//Shift Register 74HC165
//シフトレジスタ74HC165の使い方
//Copyright (C) Oz@SIT all rights reserved.
//Originally brought from https://dronebotworkshop.com/shift-registers/#Arduino_74HC165_Sketch
//rev 0.1 2022/12/31
/*
* 74HC165
* SH/LD 7
* CLK 6
* QH 8
*/
int const SL = 4; //7-4
int const CLK = 6; //6-6
int const SER = 9; //8-9
/*
74HC165 Shift Register Demonstration 1
74hc165-demo.ino
Read from 8 dipswitches and display values on serial monitor
DroneBot Workshop 2020
https://dronebotworkshop.com
*/
// Define Connections to 74HC165
// PL pin 1
int load = 4; //load pinを4ピンに設定
// CE pin 15
int clockInhibit = 2; //clockInhibit pinを2ピンに設定
// Q7 pin 9
int dataIn = 9; //data pinを9ピンに設定
// CP pin 2
int clockIn = 6; //clock pinを6ピンに設定
void setup(){
// Setup Serial Monitor
Serial.begin(9600);
// Setup 74HC165 connections
//デジタルピンの入出力の設定
pinMode(load, OUTPUT);
pinMode(clockInhibit, OUTPUT);
pinMode(clockIn, OUTPUT);
pinMode(dataIn, INPUT);
//-----------------------------------------------------------------------
}
void loop()
{
// Write pulse to load pin
//loadピンにLOW→HIGHのパルスを入れてデータをロードする。
digitalWrite(load, LOW);
delayMicroseconds(2);
digitalWrite(load, HIGH);
delayMicroseconds(2);
// Get data from 74HC165
//データを1ビットずつ読み込む。そのためclockIn
digitalWrite(clockIn, HIGH);
digitalWrite(clockInhibit, LOW);
byte incoming = shiftIn(dataIn, clockIn, LSBFIRST);
digitalWrite(clockInhibit, HIGH);
// Print to serial monitor
Serial.print("Pin States: ");
Serial.println(incoming, BIN);
delay(200);
}