Created
November 4, 2017 04:04
-
-
Save rafacouto/56f0841330b676be3d3a5d1f696632c1 to your computer and use it in GitHub Desktop.
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
// 2x SNx4HC595 using N bits | |
#include <Arduino.h> | |
#define PIN_SER 8 | |
#define PIN_LAT 9 | |
#define PIN_CLK 10 | |
#define TOTAL_BITS 12 | |
void setup() | |
{ | |
pinMode(PIN_SER, OUTPUT); | |
digitalWrite(PIN_SER, LOW); | |
pinMode(PIN_LAT, OUTPUT); | |
digitalWrite(PIN_LAT, LOW); | |
pinMode(PIN_CLK, OUTPUT); | |
digitalWrite(PIN_CLK, LOW); | |
} | |
void send(int number) | |
{ | |
digitalWrite(PIN_LAT, LOW); | |
for (int b = TOTAL_BITS - 1; b >= 0; b--) | |
{ | |
digitalWrite(PIN_CLK, LOW); | |
digitalWrite(PIN_SER, number & (1 << b) ? HIGH : LOW); | |
digitalWrite(PIN_CLK, HIGH); | |
} | |
digitalWrite(PIN_LAT, HIGH); | |
} | |
void loop() | |
{ | |
static int times = 0; | |
send(times % (1 << TOTAL_BITS)); | |
times++; | |
delay(20); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment