/*
74HC595 Shift Register Demonstration 1
74hc595-demo.ino
Count in Binary and display on 8 LEDs
Modified from "Hello World" example by Carlyn Maw,Tom Igoe and David A. Mellis
DroneBot Workshop 2020
https://dronebotworkshop.com
*/
// Define Connections to 74HC595
// ST_CP pin 12
const int latchPin = 5; //esp d5 pini
// SH_CP pin 11
const int clockPin = 18;//esp d18 pini
// DS pin 14
const int dataPin = 19;//esp d19 pini
// Patterns for characters 0,1,2,3,4,5,6,7,8,9,A,b,C,d,E,F
int datArray[16] = {B11111100, B01100000, B11011010, B11110010, B01100110, B10110110, B10111110, B11100000, B11111110, B11110110, B11101110, B00111110, B10011100, B01111010, B10011110, B10001110};
void data_shift(unsigned char data);
void setup ()
{
Serial.begin(115200);
// Setup pins as Outputs
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop()
{
// Count from 0 to 15
for (int num = 0; num < 16; num++)
{
// ST_CP LOW to keep LEDs from changing while reading serial data
digitalWrite(latchPin, LOW);
// Shift out the bits
//shiftOut(dataPin, clockPin, MSBFIRST, datArray[num]);
data_shift(datArray[num]);
// ST_CP HIGH change LEDs
digitalWrite(latchPin, HIGH);
delay(1000);
}
}
void data_shift(unsigned char data)
{
unsigned char d=0;
Serial.println(data, HEX);
for(uint8_t i=0; i<8; i++)
{
digitalWrite(clockPin, LOW);
d = data & 0x80;
Serial.println(d, HEX);
data=data<<1;
if(d) digitalWrite(dataPin, HIGH);
else digitalWrite(dataPin, LOW);
digitalWrite(clockPin, HIGH);
}
}