Last active
May 13, 2023 19:42
-
-
Save 42Bots/dd3c8d801fa0bb3124e2ec791d375954 to your computer and use it in GitHub Desktop.
ESP8266 Shift Register (74HC595) using the Arduino IDE and SPI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Example of using ES8266 with a 74HC595 shift register | |
** for more details, see http://42bots.com | |
-------------------------------------------------------- | |
** Connections: | |
** ESP8266 GPIO13 to 74HC595 pin 14 | |
** ESP8266 GPIO15 to 74HC595 pin 12 | |
** ESP8266 GPIO14 to 74HC595 pin 11 | |
** 74HC595 Vcc is connected to 3.3V | |
** 8 LEDs connected to the 8 outputs of the 74HC595 | |
** via approariate velue resistor (I use 1k Ohm) | |
*/ | |
#include <SPI.h> | |
int latchPin = 15; // pin D8 on NodeMCU boards | |
//int clockPin = 14; // pin D5 on NodeMCU boards | |
//int dataPin = 13; // pin D7 on NodeMCU | |
long randNumber; | |
void setup() | |
{ | |
//set pins to output so you can control the shift register | |
pinMode(latchPin, OUTPUT); | |
//pinMode(clockPin, OUTPUT); | |
//pinMode(dataPin, OUTPUT); | |
SPI.begin(); | |
randomSeed(analogRead(A0)); | |
} | |
void loop() | |
{ | |
randNumber = random(1, 255); | |
// take the latchPin low so | |
// the LEDs don't change while you're sending in bits: | |
digitalWrite(latchPin, LOW); | |
// shift out the bits: | |
SPI.transfer(randNumber); | |
//take the latch pin high so the LEDs will light up: | |
digitalWrite(latchPin, HIGH); | |
// pause before next value: | |
delay(500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment