Searching for the Right Channel
This project was created using the LOL Shield by Jimmie Rodgers and the IR library by Ken Shirriff. The LOL library and the IR library do not work together because the ISR code in both is using the same timer. I tried combining both libraries and make one of the ISR a separate function and injected into the other, however; it failed, so I had to alter the example code of the LOL Shield without the library and the help of my friend Shawn Lauriat. The idea the came to fruition, using the mac remote I was able to move a dot around the screen. Then if you found the right dot an animation would appear that I coded in with the help of Jimmie Rodgers’s excel sheet. Then the play button would flash all the LEDs at once and the menu button would reset your dot position. Its aesthetic is like a cute TV or a Bomb!
aisencc 5:54 am on December 6, 2011 Permalink |
// Searching for the Right Channel
// By Aisen Caro Chacin
// With the help of Shawn Lauriat, the LOL shield and IR library developers
#include //This is in the Arduino library
#include // IR remote control library
const int irReceivePin = 14; // pin connected to IR detector output
IRrecv irrecv(irReceivePin); // create the IR library
decode_results results; // IR data goes here
int blinkdelay = 75; //This basically controls brightness. Lower is dimmer
int runspeed = 20; //smaller = faster
int pin13 =13;
int pin12 =12;
int pin11 =11;
int pin10 =10;
int pin09 =9;
int pin08 =8;
int pin07 =7;
int pin06 =6;
int pin05 =5;
int pin04 =4;
int pin03 =3;
int pin02 =2;
int x=1;
int y=0;
const int pins[] = {
pin13,pin12,pin11,pin10,pin09,pin08,pin07,pin06,pin05,pin04,pin03,pin02};
const int ledMap[126][2] ={
{pin13, pin05},{pin13, pin06},{pin13, pin07},{pin13, pin08},{pin13, pin09},{pin13, pin10},{pin13, pin11},{pin13, pin12},{pin13, pin04},{pin04, pin13},{pin13, pin03},{pin03, pin13},{pin13, pin02},{pin02, pin13},
{pin12, pin05},{pin12, pin06},{pin12, pin07},{pin12, pin08},{pin12, pin09},{pin12, pin10},{pin12, pin11},{pin12, pin13},{pin12, pin04},{pin04, pin12},{pin12, pin03},{pin03, pin12},{pin12, pin02},{pin02, pin12},
{pin11, pin05},{pin11, pin06},{pin11, pin07},{pin11, pin08},{pin11, pin09},{pin11, pin10},{pin11, pin12},{pin11, pin13},{pin11, pin04},{pin04, pin11},{pin11, pin03},{pin03, pin11},{pin11, pin02},{pin02, pin11},
{pin10, pin05},{pin10, pin06},{pin10, pin07},{pin10, pin08},{pin10, pin09},{pin10, pin11},{pin10, pin12},{pin10, pin13},{pin10, pin04},{pin04, pin10},{pin10, pin03},{pin03, pin10},{pin10, pin02},{pin02, pin10},
{pin09, pin05},{pin09, pin06},{pin09, pin07},{pin09, pin08},{pin09, pin10},{pin09, pin11},{pin09, pin12},{pin09, pin13},{pin09, pin04},{pin04, pin09},{pin09, pin03},{pin03, pin09},{pin09, pin02},{pin02, pin09},
{pin08, pin05},{pin08, pin06},{pin08, pin07},{pin08, pin09},{pin08, pin10},{pin08, pin11},{pin08, pin12},{pin08, pin13},{pin08, pin04},{pin04, pin08},{pin08, pin03},{pin03, pin08},{pin08, pin02},{pin02, pin08},
{pin07, pin05},{pin07, pin06},{pin07, pin08},{pin07, pin09},{pin07, pin10},{pin07, pin11},{pin07, pin12},{pin07, pin13},{pin07, pin04},{pin04, pin07},{pin07, pin03},{pin03, pin07},{pin07, pin02},{pin02, pin07},
{pin06, pin05},{pin06, pin07},{pin06, pin08},{pin06, pin09},{pin06, pin10},{pin06, pin11},{pin06, pin12},{pin06, pin13},{pin06, pin04},{pin04, pin06},{pin06, pin03},{pin03, pin06},{pin06, pin02},{pin02, pin06},
{pin05, pin06},{pin05, pin07},{pin05, pin08},{pin05, pin09},{pin05, pin10},{pin05, pin11},{pin05, pin12},{pin05, pin13},{pin05, pin04},{pin04, pin05},{pin05, pin03},{pin03, pin05},{pin05, pin02},{pin02, pin05}
};
uint16_t BitMap[][9] PROGMEM = {
{0,0,0,0,2048,5120,2048,0,0},
{0,0,0,10752,2048,13824,2048,10752,0},
{0,13696,8320,2560,13696,2560,8320,13696,0},
{4352,9344,2624,4352,9344,2560,9408,12672,6912},
{4352,9344,2624,4352,8320,15232,8384,12672,6912 },
{1024,1536,1280,1152,1088,16352,4224,3840,0},
{1024,1536,17921920,1024,16320,4224,3860,16383},
{1024,1536,1792,1920,1024,16320,4224,3882,16383},
{512,768,896,960,512,8160,2112,6037,16383},
{256,384,448,480,256,4080,1056,5098,16383},
{128,192,224,240,128,2040,528,4586,16383},
{64,96,112,120,64,1020,8456,13562,16383},
{32,48,56,60,32,8702,12420,14457,16383},
{32,48,56,60,8224,12798,14468,15482,16383},
{16,24,8220,30,12304,14591,15426,15934,16383},
{8,8204,12302,8207,8200,15487,15905,16286,16383},
{4,1229,14343,8199,8196,12351,15888,16271,16383},
{2,6147,15363,12291,12290,14367,16136,16327,16383},
{1,7169,15873,14849,14337,15375,15876,16355,16383},
{0,7680,16128,14592,14336,14343,15362,16129,16383},
{16128,16256,16320,14528,12352,12291,12289,14336,16383},
{7680,16256,16320,16352,15456,14369,14336,14336,16383},
{1920,8128,16352,16352,15920,15520,15456,15872,16383},
{0,1984,4064,7952,15952,16016,15968,16128,16383},
{0,448,2016,4080,7952,16208,16160,16256,16383},
{0,0,960,2016,3984,7984,16256,16376,16383},
{0,0,0,960,1824,4000,8128,16380,16383},
{0,0,0,384,960,2016,4088,16382,16383},
{0,0,0,192,480,1008,2040,16383,16383},
{0,0,0,0,192,480,1008,2040,16383},
{0,0,0,192,0,192,480,1008,2040},
{0,0,192,0,0,192,480,1008,2040},
{0,288,0,192,0,192,480,1008,2040},
{0,816,192,0,0,192,480,1008,2040},
{0,816,1032,192,0,192,480,1008,2040},
{0,816,1032,192,0,192,480,1008,2040},
{0,528,1224,1032,0,192,480,1008,2040},
{0,560,1032,1032,528,192,480,1008,2040},
{0,560,1224,1032,528,480,480,1008,2040},
{0,560,1224,1032,528,288,480,1008,2040},
{0,560,1224,1032,528,288,192,1008,2040},
{0,560,2040,1752,528,816,480,192,0},
{0,560,1224,1032,0,528,288,192,0},
{0,560,1224,1032,4092,528,288,192,0},
{0,560,2040,1752,4092,816,0,0,0},
{0,512,1920,1728,3968,768,0,0,0},
{1792,3712,4032,7872,8064,3968,1792,0,8},
{0,1536,1984,1664,3968,768,0,8,28},
{0,1536,3968,3840,7424,1536,8,28,28},
{0,1536,3968,3840,7424,1544,28,28,28},
{0,1536,3968,3840,7448,1564,28,28,62},
{0,1536,3968,3848,7452,1564,28,62,127},
{0,1536,3976,3868,7452,1564,62,127,93},
{0,1544,3996,3868,7452,1598,127,93,8},
{0,1032,3612,3612,1052,62,127,93,8},
{4096,14336,4192,192,2018,4095,2034,192,96},
{4096,14336,4288,384,4066,8183,4066,384,192},
{10240,4096,11264,6144,15873,16251,15889,6144,3072},
{4096,14336,6144,12288,15364,16094,15364,12288,6144},
{10240,4096,14336,8192,14340,16094,14340,8192,12288},
{0,4096,8192,0,12292,15070,12292,0,8192},
{4096,14336,4096,0,8196,14046,8196,0,0},
{4096,14336,4096,0,66,11759,66,0,0},
{0,0,0,0,0,11759,0,0,0},
{18000}
};
// BitMap[9]
uint16_t grid[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0
};
void up(){
Serial.println(“moveUP();”);
if(y > 0){
y= y -1;
}
}
void down(){
Serial.println(“moveDOWN();”);
if(y < 8){
y= y +1;
}
}
void right(){
Serial.println("moveRIGHT();");
if(x 1) {
x /= 2;
}
}
void menu(){
Serial.println(“menu();”);
x=1;
y= 0;
}
void play(){
Serial.println(“play();”);
blinkall(33);
}
void setup() {
blinkall(2); // useful for testing
Serial.begin(9600);
pinMode(irReceivePin, INPUT);
irrecv.enableIRIn(); // Start the IR receiver
Serial.println(“Press a remote key”);
}
void turnon(int led) {
int pospin = ledMap[led][0];
int negpin = ledMap[led][1];
pinMode (pospin, OUTPUT);
pinMode (negpin, OUTPUT);
digitalWrite (pospin, HIGH);
digitalWrite (negpin, LOW);
}
void alloff() {
DDRD = B00000010;
DDRB = B00000000;
}
void loop() {
byte line = 0;
unsigned long data;
if (irrecv.decode(&results)) {
// here if data is received
irrecv.resume();
if(results.value == 2011255018){
up();
}else if(results.value == 2011246826){
down();
}else if(results.value == 2011259114){
right();
}else if(results.value == 2011271402){
left();
}else if(results.value == 2011283690){
menu();
}else if(results.value == 2011275498){
play();
}
}
if (x == 2048 && y == 5) {
DisplayBitMap();
y = 0;
}
for(line = 0; line < 9; line++){
if(line == y){
grid[line]= x;
}else{
grid[line]= 0;
}
}
for(int i = 0; i < runspeed; i++) {
for(line = 0; line < 9; line++) {
data= grid[line];
for (byte led=0; led<14; ++led) {
if (data & (1<<led)) {
turnon((line*14)+led);
delayMicroseconds(blinkdelay);
alloff();
}
else {
delayMicroseconds(blinkdelay);
}
}
}
}
}
void blinkall(int numblink) {
alloff();
for(int n = 0;n < numblink;n++) {
if (irrecv.decode(&results)) { // need to call the IR read
// here if data is received
irrecv.resume();
if(results.value == 2011283690){ // this makes the menu button reset if it is stuck on the play loop
return;
}
}
for(int i = 0; i < runspeed; i++) {
for(int j = 0; j < 126; j++) {
turnon(j);
delayMicroseconds(blinkdelay);
alloff();
}
}
delay(500);
}
}
void sequenceon() {
for(int i = 0; i < 126; i++) {
turnon(i);
delay(800);
alloff();
delay(800);
}
}
void DisplayBitMap()
{
boolean run=true;
byte frame = 0;
byte line = 0;
unsigned long data;
while(run == true) {
for(int i = 0; i < runspeed; i++) {
for(line = 0; line < 9; line++) {
data = pgm_read_word_near (&BitMap[frame][line]); // fetch data from program memory
if (data==18000){
run=false;
}
else for (byte led=0; led<14; ++led) {
if (data & (1<<led)) {
turnon((line*14)+led);
delayMicroseconds(blinkdelay);
alloff();
}
else {
delayMicroseconds(blinkdelay);
}
}
}
} frame++;
}
}