#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
//#include <stdio.h>
//#include "pico/stdlib.h"
//#include "hardware/gpio.h"
//#include "hardware/pwm.h"
#define QH 16 // データの入力ピン(74HC165-QH). GP16
#define CK 28 // クロック出力ピン(74HC165-CK/CP). GP28
#define SL 27 // レジスタロードピン(74HC165-SL/PL) GP27
//参考 http://zattouka.net/GarageHouse/micon/circuit/HC165.htm$0
const int dataPin = 0; /* Q7 */
const int clockPin = 2; /* CP */
const int latchPin = 1; /* PL */
const int numBits = 8; /* Set to 8 * number of shift registers */
const int ledpin = 17;
int Outdatapin = 13;
int Outclockpin = 15;
int Outlatchpin = 14;
int state;
byte ShiftData ;
const int pulseWidth = 10; // pulse width in microseconds
byte data = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello,again ");
pinMode(dataPin, INPUT);
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(Outdatapin, OUTPUT);
pinMode(Outclockpin, OUTPUT);
pinMode(Outlatchpin, OUTPUT);
pinMode(ledpin, OUTPUT);
lcd.begin(16, 2);
lcd.print("Hello1");
lcd.setCursor(2, 1);
lcd.print(dataPin);
lcd.print(clockPin);
}
void loop() {
delay(10);
// put your main code here, to run repeatedly:
//byte dt ;
// Step 1: Sample
digitalWrite(latchPin, LOW);
digitalWrite(latchPin, HIGH);
// Step 2: Shift
Serial.print("Bits: ");
for (int i = 0; i < numBits; i++) {
int bit = digitalRead(dataPin);
if (bit == HIGH) {
Serial1.print("1");
} else {
Serial1.print("0");
}
digitalWrite(clockPin, HIGH); // Shift out the next bit
delayMicroseconds( pulseWidth);
digitalWrite(clockPin, LOW);
}
//lcd.print(state);
oneAfterAnother(); // All on, all off
Serial.println();
// delay(1000);
state =state+1;
if(state>=50 && state<51){
digitalWrite(ledpin, HIGH);
lcd.setCursor(2, 1);
lcd.print("1");
}else if( state>=100){
lcd.setCursor(2, 1);
lcd.print("> Pi Pico! <");
digitalWrite(ledpin,LOW);
state = 0;
}
}
void shiftWrite(int desiredPin, boolean desiredState){
// This function lets you make the shift register outputs
// HIGH or LOW in exactly the same way that you use digitalWrite().
bitWrite(data,desiredPin,desiredState); //Change desired bit to 0 or 1 in "data"
// Now we'll actually send that data to the shift register.
// The shiftOut() function does all the hard work of
// manipulating the data and clock pins to move the data
// into the shift register:
shiftOut(Outdatapin, Outclockpin, MSBFIRST, data); //Send "data" to the shift register
//Toggle the latchPin to make "data" appear at the outputs
digitalWrite(Outlatchpin, HIGH);
digitalWrite(Outlatchpin, LOW);
}
void oneAfterAnother()
{
// This function will turn on all the LEDs, one-by-one,
// and then turn them off all off, one-by-one.
int index;
int delayTime = 100; // Time (milliseconds) to pause between LEDs
// Make this smaller for faster switching
// Turn all the LEDs on
for(index = 0; index <= 7; index++)
{
shiftWrite(index, HIGH);
delay(delayTime);
}
// Turn all the LEDs off
for(index = 7; index >= 0; index--)
{
shiftWrite(index, LOW);
delay(delayTime);
}
}