NOMCU 24bit I/O Expander
使用3個74HC165 與3個 74HC595
//NodeMCU
//static const uint8_t D0 = 16;
//static const uint8_t D1 = 5;
//static const uint8_t D2 = 4;
//static const uint8_t D3 = 0;
//static const uint8_t D4 = 2;
//static const uint8_t D5 = 14;
//static const uint8_t D6 = 12;
//static const uint8_t D7 = 13;
//static const uint8_t D8 = 15;
//static const uint8_t D9 = 3;
//static const uint8_t D10 = 1;
#define SO 12 // SO-Serial output (Pin 9) of 74165 is connected to Nodemcu D6 = 12.
#define SH_LD 15 // SH/LD (Pin 1) of 74165 is connected to Nodemcu D8 = 15.
#define CLK 14 // CLK (Pin 2) of 74165 is connected to Nodemcu D5 = 14.
#include <ShiftRegister74HC595.h>
// create shift register object (number of shift registers, data pin, clock pin, latch pin)
ShiftRegister74HC595 sr (3, 16, 4, 5);
// variables will change:
int i = 0; // variable for reading 8-bit data
long int PinState = 0; //read the state of the SO pin
int Parallel_data = 0;//To store parallel data
int Parallel_data1 = 0;//To store parallel data
int read_shift_data()
{
Parallel_data = 0;
digitalWrite(CLK, LOW);
/*Parallel data that will be entered through D0 - D7 Pins of 74165 **/
digitalWrite(SH_LD, LOW);
delay(5);
/******************* INHIBIT SECTION START HERE *****************/
digitalWrite(SH_LD, HIGH);
/******************* INHIBIT SECTION ENDS HERE ******************/
/************** SERIAL SHIFT SECTION START HERE **********/
//Read 8-bit data from 74HC165
// Serial.print("Parallel Data1:");
for(i=0;i<=23;i++)
{
PinState = digitalRead(SO);// read the state of the SO:
digitalWrite(CLK, LOW);
delay(1);
digitalWrite(CLK, HIGH);
delay(1);
//Serial.print(PinState);
Parallel_data = (Parallel_data<<1)|PinState; //Store the value in Parallel_data
}
return Parallel_data;
}
void setup()
{
// initialize serial communication at 9600 bits per second:
Serial.begin(115200);
// initialize the SH_LD & CLK pin as an output:
pinMode(SH_LD, OUTPUT);
pinMode(CLK, OUTPUT);
// initialize the SO-Serial output pin as an input:
pinMode(SO, INPUT);
}
void loop()
{
Parallel_data1=read_shift_data();
String thisString1 = String(Parallel_data1, HEX);
Serial.print("--switchBank1:");
Serial.println (thisString1);
// set all pins at once
byte d1= (MSBFIRST, (Parallel_data1 / 65536));
byte d2= (MSBFIRST, (Parallel_data1 / 256));
byte d3= (MSBFIRST, (Parallel_data1 ));
String thisString4 = String(d1, HEX);
String thisString5 = String(d2, HEX);
String thisString6 = String(d3, HEX);
Serial.print("--switchBank1:");
Serial.print (thisString4);
Serial.print("---");
Serial.print (thisString5);
Serial.print("---");
Serial.print (thisString6);
Serial.println ();
uint8_t pinValues[] = { d1, d2 , d3 };
sr.setAll(pinValues);
Serial.println();
delay(10000);
}
}
訂閱:
張貼留言 (Atom)
Messaging API作為替代方案
LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...
-
python pip 不是内部或外部命令 -- 解決方法 要安裝 Pyqt5 1. 首先,開啟命令提示字元。 2. 輸入 pip3 install pyqt5 好像不能執行 ! ! 錯誤顯示 : ‘ pip3 ’ 不是內部或外部命令、可執行的程式或批...
-
課程講義 下載 11/20 1) PPT 下載 + 程式下載 http://www.mediafire.com/file/cru4py7e8pptfda/106%E5%8B%A4%E7%9B%8A2-1.rar 11/27 2) PPT 下載...
-
• 認 識 PreFix、InFix、PostFix PreFix(前序式):* + 1 2 + 3 4 InFix(中序式): (1+2)*(3+4) PostFix(後序式):1 2 + 3 4 + * 後 序式的運算 例如: 運算時由 後序式的...
沒有留言:
張貼留言