Skip to content

Instantly share code, notes, and snippets.

@rafacouto
Created November 4, 2017 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafacouto/56f0841330b676be3d3a5d1f696632c1 to your computer and use it in GitHub Desktop.
Save rafacouto/56f0841330b676be3d3a5d1f696632c1 to your computer and use it in GitHub Desktop.
// 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