Created
May 12, 2013 22:05
-
-
Save kmcallister/5565083 to your computer and use it in GitHub Desktop.
LPD6803 driver for AVR
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
| typedef unsigned char byte; | |
| #define STRIP_DDR DDRD | |
| #define STRIP_PORT PORTD | |
| #define STRIP_DAT (1 << 2) | |
| #define STRIP_CLK (1 << 3) | |
| // Set up the interface at boot. | |
| inline void setup_strip() { | |
| STRIP_DDR |= (STRIP_DAT | STRIP_CLK); | |
| } | |
| // Write a single bit to the LED strip. | |
| inline void write_bit(byte x) { | |
| if (x) | |
| STRIP_PORT |= STRIP_DAT; | |
| else | |
| STRIP_PORT &= ~STRIP_DAT; | |
| STRIP_PORT |= STRIP_CLK; | |
| STRIP_PORT &= ~STRIP_CLK; | |
| } | |
| // Write five bits to the LED strip. | |
| inline void write5(byte x) { | |
| write_bit(x & 0x10); | |
| write_bit(x & 0x08); | |
| write_bit(x & 0x04); | |
| write_bit(x & 0x02); | |
| write_bit(x & 0x01); | |
| } | |
| // Start a new frame. | |
| inline void frame_start() { | |
| for (byte i=0; i<32; i++) { | |
| write_bit(0); | |
| } | |
| } | |
| // Set a RGB color. | |
| inline void rgb(byte r, byte g, byte b) { | |
| write_bit(1); | |
| write5(g); | |
| write5(r); | |
| write5(b); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment