/* Light Painters Palette Written by JD Ritchy December 1, 2013 Thanks to the writers of the IR remote library and all the LED fading writers out there. You made this possible!! */ #include int Switch1Pin = 8; int Switch2Pin = 4; int redPin = 10; int grnPin = 5; int bluPin = 6; int IR_Recv_Pin = 9; int redPotPin = A3; int greenPotPin = A2; int bluePotPin = A1; IRrecv irrecv(IR_Recv_Pin); decode_results results; unsigned int rawCodes[RAWBUF]; // The durations if raw int black[3] = { 0, 0, 0 }; int white[3] = { 100, 100, 100}; int red[3] = { 100, 0, 0}; int green[3] = { 0, 100, 0}; int blue[3] = { 0, 0, 100}; int color1[3] = { 100, 10, 00}; int color2[3] = { 100, 30, 00}; int color3[3] = { 100, 50, 00}; int color4[3] = { 100, 100, 0}; int color5[3] = { 0, 100, 10}; int color6[3] = { 0, 100, 30}; int color7[3] = { 0, 100, 50}; int color8[3] = { 00, 100, 100}; int color9[3] = { 10, 0, 100}; int color10[3] = { 30, 0, 100}; int color11[3] = { 50, 0, 100}; int color12[3] = { 100, 0, 100}; int color13[3] = { 00, 00, 00}; int redVal = black[0]; int grnVal = black[1]; int bluVal = black[2]; int prevR = redVal; int prevG = grnVal; int prevB = bluVal; int wait; int Switch1; int Switch2; void setup() { Serial.begin(9600); irrecv.enableIRIn(); // Start the receiver pinMode(redPin, OUTPUT); pinMode(grnPin, OUTPUT); pinMode(bluPin, OUTPUT); } void loop() { if (digitalRead(Switch1Pin) == HIGH && digitalRead(Switch2Pin)==HIGH) { int redValue = analogRead(redPotPin); delay(5); int greenValue = analogRead(greenPotPin); delay(5); int blueValue = analogRead(bluePotPin); delay(5); int redVal = map(redValue, 0, 1023, 0, 255); int greenVal = map(greenValue, 0, 1023, 0, 225); int blueVal = map(blueValue, 0, 1023, 0, 255); analogWrite(redPin, redVal); analogWrite(grnPin, greenVal); analogWrite(bluPin, blueVal); Serial.print("Red= "); Serial.print(redVal); Serial.print("Green= "); Serial.print(greenVal); Serial.print("Blue= "); Serial.print(blueVal); } //======================================================================= if (digitalRead(Switch1Pin)==HIGH && digitalRead(Switch2Pin)==LOW) { int strobeSpeed = analogRead(redPotPin); int strobePause = map(strobeSpeed, 0, 1023, 1, 3072); wait = strobePause; if(strobeSpeed >2){ crossFade(red); crossFade(black); } int strobe2Speed = analogRead(greenPotPin); int strobe2Pause = map(strobe2Speed, 0, 1023, 1, 3072); wait = strobe2Pause; if(strobe2Speed >2){ crossFade(green); crossFade(black); } int strobe3Speed = analogRead(bluePotPin); int strobe3Pause = map(strobe3Speed, 0, 1023, 1, 3072); wait = strobe3Pause; if(strobe3Speed >2){ crossFade(blue); crossFade(black); } } //======================================================================= if (digitalRead(Switch1Pin)==LOW && digitalRead(Switch2Pin)==HIGH) { int strobeSpeed = analogRead(redPotPin); int strobePause = map(strobeSpeed, 0, 1023, 1, 3072); wait = strobePause; if(strobeSpeed >2) crossFade(red); int strobe2Speed = analogRead(greenPotPin); int strobe2Pause = map(strobe2Speed, 0, 1023, 1, 3072); wait = strobe2Pause; if(strobe2Speed >2) crossFade(green); int strobe3Speed = analogRead(bluePotPin); int strobe3Pause = map(strobe3Speed, 0, 1023, 1, 3072); wait = strobe3Pause; if(strobe3Speed >2) crossFade(blue); } //======================================================================= if (digitalRead(Switch1Pin)==LOW && digitalRead(Switch2Pin)==LOW) { wait = 1; if (irrecv.decode(&results)) { Serial.println(results.value); if (results.value==3898168033){crossFade(red); } else if (results.value==16195807){ crossFade(red); } else if (results.value==16228447){ crossFade(green); } else if (results.value==2026743005){ crossFade(green); } else if (results.value==16212127){ crossFade(blue); } else if (results.value==632192736){ crossFade(blue); } else if (results.value==2724668229){ crossFade(blue); } else if (results.value==16191727){ crossFade(color1); } else if (results.value==16199887){ crossFade(color2); } else if (results.value==16189687){ crossFade(color3); } else if (results.value==16197847){ crossFade(color4); } else if (results.value==16224367){ crossFade(color5); } else if (results.value==16232527){ crossFade(color6); } else if (results.value==16222327){ crossFade(color7); } else if (results.value==16230487){ crossFade(color8); } else if (results.value==16208047){ crossFade(color9); } else if (results.value==16216207){ crossFade(color10); } else if (results.value==16206007){ crossFade(color11); } else if (results.value==16214167){ crossFade(color12); } else if (results.value==16203967){ crossFade(color13); } else if (results.value==16244767){ crossFade(white); } else if (results.value==581859882 || results.value==581859881){ int redValue = analogRead(redPotPin); int greenValue = analogRead(greenPotPin); int blueValue = analogRead(bluePotPin); int redVal = map(redValue, 0, 1023, 0, 255); int greenVal = map(greenValue, 0, 1023, 0, 225); int blueVal = map(blueValue, 0, 1023, 0, 255); delay(125); analogWrite(redPin, redVal); analogWrite(grnPin, greenVal); analogWrite(bluPin, blueVal); delay(200); analogWrite(redPin, 0); analogWrite(grnPin, 0); analogWrite(bluPin, 0); } else if (results.value==16240687){ //Flash analogWrite(redPin, 255); analogWrite(grnPin, 255); analogWrite(bluPin, 255); delay(150); analogWrite(redPin, 0); analogWrite(grnPin, 0); analogWrite(bluPin, 0); } else if (results.value==16248847){ //Strobe do{ irrecv.resume(); delay(random(25, 100)); analogWrite(redPin, 255); analogWrite(grnPin, 255); analogWrite(bluPin, 255); delay(random(50, 150)); analogWrite(redPin, 0); analogWrite(grnPin, 0); analogWrite(bluPin, 0); irrecv.decode(&results); delay(10); } while (results.value!=16203967); } else if (results.value==16238647){ //Fade do{ irrecv.resume(); // Receive the next value wait = 5; crossFade(red); crossFade(green); crossFade(blue); irrecv.decode(&results); } while (results.value!=16203967); } else if (results.value==16246807){ //Smooth wait = 10000; do{ irrecv.resume(); // Receive the next value wait = 1000; crossFade(red); crossFade(green); crossFade(blue); irrecv.decode(&results); } while (results.value!=16203967); } else if (results.value==16220287){ //Dimmer redVal= redVal/2; grnVal = grnVal/2; bluVal = bluVal/2; constrain(redVal, 2, 255); constrain(grnVal, 2, 255); constrain(bluVal, 2, 255); analogWrite(redPin, redVal); // Write current values to LED pins analogWrite(grnPin, grnVal); analogWrite(bluPin, bluVal); } else if (results.value==16187647){ //Brighter redVal= redVal*2; grnVal = grnVal*2; bluVal = bluVal*2; constrain(redVal, 2, 255); constrain(grnVal, 2, 255); constrain(bluVal, 2, 255); analogWrite(redPin, redVal); // Write current values to LED pins analogWrite(grnPin, grnVal); analogWrite(bluPin, bluVal); } irrecv.resume(); // Receive the next value } } } int calculateStep(int prevValue, int endValue) { int step = endValue - prevValue; // What's the overall gap? if (step) { // If its non-zero, step = 1020/step; // divide by 1020 } return step; } int calculateVal(int step, int val, int i) { if ((step) && i % step == 0) { // If step is non-zero and its time to change a value, if (step > 0) { // increment the value if step is positive... val += 1; } else if (step < 0) { // ...or decrement it if step is negative val -= 1; } } // Defensive driving: make sure val stays in the range 0-255 if (val > 255) { val = 255; } else if (val < 0) { val = 0; } return val; } void crossFade(int color[3]) { // Convert to 0-255 int R = (color[0] * 255) / 100; int G = (color[1] * 255) / 100; int B = (color[2] * 255) / 100; int stepR = calculateStep(prevR, R); int stepG = calculateStep(prevG, G); int stepB = calculateStep(prevB, B); for (int i = 0; i <= 1020; i++) { redVal = calculateVal(stepR, redVal, i); grnVal = calculateVal(stepG, grnVal, i); bluVal = calculateVal(stepB, bluVal, i); analogWrite(redPin, redVal); // Write current values to LED pins delayMicroseconds(wait); // Pause for 'wait' milliseconds before resuming the loop analogWrite(grnPin, grnVal); delayMicroseconds(wait); // Pause for 'wait' milliseconds before resuming the loop analogWrite(bluPin, bluVal); delayMicroseconds(wait); // Pause for 'wait' milliseconds before resuming the loop } // Update current values for next loop prevR = redVal; prevG = grnVal; prevB = bluVal; delayMicroseconds(wait); // Pause for optional 'wait' milliseconds before resuming the loop }