Skip to content

Instantly share code, notes, and snippets.

@halferty
Created May 4, 2015 22:01
Show Gist options
  • Select an option

  • Save halferty/6ed127f77920c2d54671 to your computer and use it in GitHub Desktop.

Select an option

Save halferty/6ed127f77920c2d54671 to your computer and use it in GitHub Desktop.
Radioshack RGB LED strip Ripple color change test with IR remote control
#include <avr/pgmspace.h>
#include <IRremote.h>
#include <IRremoteInt.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
#define B_1 0x92DF9279
#define B_2 0x87CDD0EF
#define B_3 0x37788763
int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long pattern[10];
unsigned long color1 = 0xff0000, color2 = 0x440000;
int timer = 0, index = 0;
void setup()
{
STRIP_PINOUT;
reset_strip();
Serial.begin(9600);
Serial.println("Ready to decode IR!");
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
int i;
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
switch (results.value) {
case B_1:
Serial.println("1!");
color1 = 0xff0000;
color2 = 0x440000;
break;
case B_2:
Serial.println("2!");
color1 = 0x0000ff;
color2 = 0x000044;
break;
case B_3:
Serial.println("3!");
color1 = 0x00ff00;
color2 = 0x004400;
break;
default:
break;
}
irrecv.resume(); // Receive the next value
}
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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment