Last active
December 13, 2015 03:38
-
-
Save halferty/fa2dfb6e0358eeb95bfa to your computer and use it in GitHub Desktop.
ledripple_no_ir.ino
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 <avr/pgmspace.h> | |
#define DATA_1 (PORTC |= 0X01) | |
#define DATA_0 (PORTC &= 0XFE) | |
#define STRIP_PINOUT (DDRC=0xFF) | |
#define NOP __asm__("nop\n\t"); | |
#define NOP28 NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP | |
#define NOP9 NOP NOP NOP NOP NOP NOP NOP NOP NOP | |
#define NOP3 NOP NOP NOP | |
unsigned long pattern[10]; | |
unsigned long color1 = 0xff0000, color2 = 0x0000ff; | |
int timer = 0, index = 0; | |
void setup() | |
{ | |
STRIP_PINOUT; | |
reset_strip(); | |
Serial.begin(9600); | |
Serial.println("Hello, LED strip!"); | |
} | |
void loop() { | |
int i; | |
for (i = 0; i < 10; i++) { | |
pattern[i] = (i == index)? color1 : color2; | |
} | |
send_pattern(pattern); | |
delay(100); | |
index++; | |
if (index >= 10) { | |
index = 0; | |
} | |
} | |
void reset_strip() | |
{ | |
DATA_0; | |
delayMicroseconds(20); | |
} | |
void send_pattern(unsigned long * data) { | |
int i; | |
unsigned long j; | |
noInterrupts(); | |
for (i = 0; i < 10; i++) | |
{ | |
for (j = 0x800000; j > 0x00000000; j >>= 1) | |
{ | |
if (data[i] & j) | |
{ | |
DATA_1; | |
NOP28 | |
DATA_0; | |
} | |
else | |
{ | |
DATA_1; | |
NOP9 | |
DATA_0; | |
NOP3 | |
} | |
} | |
} | |
interrupts(); | |
} |
Author
halferty
commented
Dec 13, 2015
Obviously, only use 12V if your LED strip datasheet tells you to...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment