Skip to content

Instantly share code, notes, and snippets.

@StuffAndyMakes
Created July 13, 2015 14:44
Show Gist options
  • Save StuffAndyMakes/b9cd1ee96a2d742eca6c to your computer and use it in GitHub Desktop.
Save StuffAndyMakes/b9cd1ee96a2d742eca6c to your computer and use it in GitHub Desktop.
Example usage for StuffAndyMakes.com Simple LED Controller shift register breakout board
#include "Arduino.h"
#define data 8
#define clk 9
#define oe 7
#define rst 6
void pulseClock() {
digitalWrite(clk, HIGH);
digitalWrite(clk, LOW);
}
void setLEDs(uint8_t leds) {
// reset chip
digitalWrite(rst, LOW);
digitalWrite(rst, HIGH);
// if set to 0, just bombo out, since all LEDs are off at this point
if (leds == 0) return;
// turn off display (active low)
digitalWrite(oe, HIGH);
// shift in bits
for (uint8_t bit = 0; bit < 8; bit++) {
digitalWrite(data, (leds & (1 << bit)) == (1 << bit) ? HIGH : LOW);
pulseClock();
}
pulseClock();
// turn on display (active low)
digitalWrite(oe, LOW);
}
void setup() {
pinMode(data, OUTPUT);
pinMode(clk, OUTPUT);
pinMode(oe, OUTPUT);
pinMode(rst, OUTPUT);
}
void loop() {
uint8_t a = 0;
while (a != 255) {
a = (a << 1) + 1;
setLEDs(a);
delay(100);
}
while (a != 0) {
a = (a << 1);
setLEDs(a);
delay(100);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment