Created
July 13, 2015 13:11
-
-
Save StuffAndyMakes/bb62aef4b9551101222d to your computer and use it in GitHub Desktop.
Example usage for StuffAndyMakes.com Simple LED Controller shift register breakout board
This file contains hidden or 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
#include "mbed.h" | |
DigitalOut data(PTB9); | |
DigitalOut clk(PTB8); | |
DigitalOut oe(PTB10); | |
DigitalOut rst(PTB11); | |
Serial out(PTA2, PTA1); | |
void pulseClock() { | |
clk = 1; | |
clk = 0; | |
} | |
void setLEDs(uint8_t leds) { | |
// reset chip | |
rst = 0; | |
rst = 1; | |
// if set to 0, just bombo out, since all LEDs are off at this point | |
if (leds == 0) return; | |
// turn off display (active low) | |
oe = 1; | |
// shift in bits | |
for (uint8_t bit = 0; bit < 8; bit++) { | |
data = (leds & (1 << bit)) == (1 << bit) ? 1 : 0; | |
pulseClock(); | |
} | |
pulseClock(); | |
// turn on display (active low) | |
oe = 0; | |
} | |
void setup() { | |
out.printf("Hi!\r\n"); | |
} | |
void loop() { | |
uint8_t a = 0; | |
while (a != 255) { | |
a = (a << 1) + 1; | |
setLEDs(a); | |
wait_ms(100); | |
} | |
while (a != 0) { | |
a = (a << 1); | |
setLEDs(a); | |
wait_ms(100); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment