Final-ish Code for Workshop

We have the final(ish) code ready for the prototypes that people will be able to make from our kits.

// Accessible Pixel version 1
// APvl.ino
// designed by AccessiblePixel.com
//Include Libraries
#include <Adafruit_NeoPixel.h>
#include <Keypad.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
// Initialise Variables
#define PIN 9 // PIN for LED Strip
volatile int frame=0;
volatile int backcolorframe=0;
volatile int r = 0;
volatile int g = 0;
volatile int b = 0;
volatile int brightred = 0;
volatile int brightgreen = 0;
volatile int brightblue = 0;
volatile int brightcolor = 0;
volatile int up = 0;
volatile int rainbowi = 0;
volatile int rainboww = 0;
volatile int circleanimation = 0;
// Initialise Pixels
Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, PIN, NEO_GRB + NEO_KHZ800);
// Setup Keypad
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 8, 7, 6, 5 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 4, 3, 2 }; 
// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
// Main Setup Loop (Run Once At Start Up)
void setup() {
// Initialize Pixels
strip.begin();    
strip.setBrightness(135);
strip.setPixelColor(0,50,50,50);
strip.setPixelColor(1,0,0,0);
strip.setPixelColor(2,50,50,50);
strip.setPixelColor(3,0,0,0);
strip.setPixelColor(4,50,50,50);
strip.setPixelColor(5,0,0,0);
strip.setPixelColor(6,50,50,50);
strip.setPixelColor(7,0,0,0);
strip.setPixelColor(8,50,50,50);
strip.setPixelColor(9,0,0,0);
strip.setPixelColor(10,50,50,50);
strip.setPixelColor(11,0,0,0);
strip.setPixelColor(12,50,50,50);
strip.setPixelColor(13,0,0,0);
strip.setPixelColor(14,50,50,50);
strip.setPixelColor(15,0,0,0);
strip.show(); 
// Setup Interrupt at 32hz
// Stop Interrupts
cli();
// Clear Timer Register
TCCR1A = 0;// Set entire TCCR1A register to 0
TCCR1B = 0;// Same for TCCR1B
TCNT1  = 0;// Initialize counter value to 0
// set compare match register for 32hz increments
OCR1A = 488;// = (16*10^6) / (32*1024) - 1 (must be <65536)
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS10 and CS12 bits for 1024 prescaler
TCCR1B |= (1 << CS12) | (1 << CS10);  
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
// Allow Interrupts
sei();
}//end setup loop
// Function Declarations
//Initialize Reset Function
void(* resetFunc) (void) = 0; //declare reset function @ address 0 
uint32_t wheelz(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
// Run Animation Frames
ISR(TIMER1_COMPA_vect){
if(frame==1){ 
strip.setPixelColor(0,135,0,0);
strip.show(); 
frame++;
}
else if(frame==2) {  
strip.setPixelColor(1,135,0,0);
strip.show(); 
frame++;
}
else if(frame==3) {  
strip.setPixelColor(2,135,0,0);
strip.show(); 
frame++;
}
else if(frame==4) {  
strip.setPixelColor(3,135,0,0);
strip.show(); 
frame++;
}
else if(frame==5) {  
strip.setPixelColor(4,135,0,0);
strip.show(); 
frame++;
}
else if(frame==6) {  
strip.setPixelColor(5,135,0,0);
delay(50);
strip.show(); 
frame++;
}
else if(frame==7) {  
strip.setPixelColor(6,135,0,0);
strip.show(); 
frame++;
}
else if(frame==8) {  
strip.setPixelColor(7,135,0,0);
strip.show(); 
frame++;
}
else if(frame==9) {  
strip.setPixelColor(8,135,0,0);
strip.show(); 
frame++;
}
else if(frame==10) {  
strip.setPixelColor(9,135,0,0);
strip.show(); 
frame++;
}
else if(frame==11) {  
strip.setPixelColor(10,135,0,0);
strip.show(); 
frame++;
}
else if(frame==12) {  
strip.setPixelColor(11,135,0,0);
strip.show(); 
frame++;
}
else if(frame==13) {  
strip.setPixelColor(12,135,0,0);
strip.show(); 
frame++;
}
else if(frame==14) {  
strip.setPixelColor(13,135,0,0);
strip.show(); 
frame++;
}
else if(frame==15) {  
strip.setPixelColor(14,135,0,0);
strip.show(); 
frame++;
}
else if(frame==16) {  
strip.setPixelColor(15,135,0,0);
strip.show(); 
frame = 38;
}
// RESET ANIMATION
else if(frame==17){ 
strip.setPixelColor(15,0,0,0);
strip.show(); 
frame++;
}
else if(frame==18) {  
strip.setPixelColor(14,0,0,0);
strip.show(); 
frame++;
}
else if(frame==19) {  
strip.setPixelColor(13,0,0,0);
strip.show(); 
frame++;
}
else if(frame==20) {  
strip.setPixelColor(12,0,0,0);
strip.show(); 
frame++;
}
else if(frame==21) {  
strip.setPixelColor(11,0,0,0);
strip.show(); 
frame++;
}
else if(frame==22) {  
strip.setPixelColor(10,0,0,0);
strip.show(); 
frame++;
}
else if(frame==23) {  
strip.setPixelColor(9,0,0,0);
strip.show(); 
frame++;
}
else if(frame==24) {  
strip.setPixelColor(8,0,0,0);
delay(50);
strip.show(); 
frame++;
}
else if(frame==25) {  
strip.setPixelColor(7,0,0,0);
strip.show(); 
frame++;
}
else if(frame==26) {  
strip.setPixelColor(6,0,0,0);
strip.show(); 
frame++;
}
else if(frame==27) {  
strip.setPixelColor(5,0,0,0);
strip.show(); 
frame++;
}
else if(frame==28) {  
strip.setPixelColor(4,0,0,0);
strip.show(); 
frame++;
}
else if(frame==29) {  
strip.setPixelColor(3,0,0,0);
strip.show(); 
frame++;
}
else if(frame==30) {  
strip.setPixelColor(2,0,0,0);
strip.show(); 
frame++;
}
else if(frame==31) {  
strip.setPixelColor(1,0,0,0);
strip.show(); 
frame++;
}
else if(frame==32) {  
strip.setPixelColor(0,0,0,0);
strip.show(); 
} else if(frame==33) {
strip.setPixelColor(random(0,15),random(0,135),random(0,135),random(0,135));
strip.setPixelColor(random(0,15),0,0,0,0);
strip.show();
}
else if(frame==34){strip.setPixelColor(0,0,0,0);
strip.setPixelColor(1,0,0,0);
strip.setPixelColor(2,0,0,0);
strip.setPixelColor(3,0,0,0);
strip.setPixelColor(4,0,0,0);
strip.setPixelColor(5,0,0,0);
strip.setPixelColor(6,0,0,0);
strip.setPixelColor(7,0,0,0);
strip.setPixelColor(8,0,0,0);
strip.setPixelColor(9,0,0,0);
strip.setPixelColor(10,0,0,0);
strip.setPixelColor(11,0,0,0);
strip.setPixelColor(12,0,0,0);
strip.setPixelColor(13,0,0,0);
strip.setPixelColor(14,0,0,0);
strip.setPixelColor(15,0,0,0);
strip.show();
}
else if(frame==35){
strip.setPixelColor(0,brightred,brightgreen,brightblue);
strip.setPixelColor(1,brightred,brightgreen,brightblue);
strip.setPixelColor(2,brightred,brightgreen,brightblue);
strip.setPixelColor(3,brightred,brightgreen,brightblue);
strip.setPixelColor(4,brightred,brightgreen,brightblue);
strip.setPixelColor(5,brightred,brightgreen,brightblue);
strip.setPixelColor(6,brightred,brightgreen,brightblue);
strip.setPixelColor(7,brightred,brightgreen,brightblue);
strip.setPixelColor(8,brightred,brightgreen,brightblue);
strip.setPixelColor(9,brightred,brightgreen,brightblue);
strip.setPixelColor(10,brightred,brightgreen,brightblue);
strip.setPixelColor(11,brightred,brightgreen,brightblue);
strip.setPixelColor(12,brightred,brightgreen,brightblue);
strip.setPixelColor(13,brightred,brightgreen,brightblue);
strip.setPixelColor(14,brightred,brightgreen,brightblue);
strip.setPixelColor(15,brightred,brightgreen,brightblue);
strip.show();
if (brightcolor==0) {
if (up == 0) {
if (brightred < 135) {
brightred++; 
}
else if (brightred == 135) {
brightred=135; 
up = 1;
} 
}
else if(up == 1) {
if(brightred > 0) {
brightred--;
} 
else if (brightred == 0) {
up = 0;brightcolor++;
} 
}
} 
else if (brightcolor==1) {
if (up == 0) {
if (brightgreen < 135) {
brightgreen++; 
}
else if (brightgreen == 135) {
brightgreen=135; 
up = 1;
} 
}
else if(up == 1) {
if(brightgreen > 0) {
brightgreen--;
} 
else if (brightgreen == 0) {
up = 0;brightcolor++;
} 
}
} 
else if (brightcolor==2) {
if (up == 0) {
if (brightblue < 135) {
brightblue++; 
}
else if (brightblue == 135) {
brightblue=135; 
up = 1;
} 
}
else if(up == 1) {
if(brightblue > 0) {
brightblue--;
} 
else if (brightblue == 0) {
up = 0;brightcolor=0;
} 
}
}            
}
else if(frame==36){
strip.setPixelColor(rainbowi, wheelz((rainbowi+rainboww) & 255));
strip.show();
if (rainbowi < 15 )
{ rainbowi++; } else if (rainbowi == 15) { rainbowi = 0; }
if (rainboww < 255 )
{rainboww++; } if (rainboww == 255) {rainboww =0; }
}
else if(frame==37){frame=0;}
if(frame==38){ 
strip.setPixelColor(0,0,0,135);
strip.show(); 
frame++;
}
else if(frame==39) {  
strip.setPixelColor(1,0,0,135);
strip.show(); 
frame++;
}
else if(frame==40) {  
strip.setPixelColor(2,0,0,135);
strip.show(); 
frame++;
}
else if(frame==41) {  
strip.setPixelColor(3,0,0,135);
strip.show(); 
frame++;
}
else if(frame==42) {  
strip.setPixelColor(4,0,0,135);
strip.show(); 
frame++;
}
else if(frame==43) {  
strip.setPixelColor(5,0,0,135);
strip.show(); 
frame++;
}
else if(frame==44) {  
strip.setPixelColor(6,0,0,135);
strip.show(); 
frame++;
}
else if(frame==45) {  
strip.setPixelColor(7,0,0,135);
strip.show(); 
frame++;
}
else if(frame==46) {  
strip.setPixelColor(8,0,0,135);
strip.show(); 
frame++;
}
else if(frame==47) {  
strip.setPixelColor(9,0,0,135);
strip.show(); 
frame++;
}
else if(frame==48) {  
strip.setPixelColor(10,0,0,135);
strip.show(); 
frame++;
}
else if(frame==49) {  
strip.setPixelColor(11,0,0,135);
strip.show(); 
frame++;
}
else if(frame==50) {  
strip.setPixelColor(12,0,0,135);
strip.show(); 
frame++;
}
else if(frame==51) {  
strip.setPixelColor(13,0,0,135);
strip.show(); 
frame++;
}
else if(frame==52) {  
strip.setPixelColor(14,0,0,135);
strip.show(); 
frame++;
}
else if(frame==53) {  
strip.setPixelColor(15,0,0,135);
strip.show(); 
frame++;
}
if(frame==54){ 
strip.setPixelColor(0,0,135,0);
strip.show(); 
frame++;
}
else if(frame==55) {  
strip.setPixelColor(1,0,135,0);
strip.show(); 
frame++;
}
else if(frame==56) {  
strip.setPixelColor(2,0,135,0);
strip.show(); 
frame++;
}
else if(frame==57) {  
strip.setPixelColor(3,0,135,0);
strip.show(); 
frame++;
}
else if(frame==58) {  
strip.setPixelColor(4,0,135,0);
strip.show(); 
frame++;
}
else if(frame==59) {  
strip.setPixelColor(5,0,135,0);
delay(50);
strip.show(); 
frame++;
}
else if(frame==60) {  
strip.setPixelColor(6,0,135,0);
strip.show(); 
frame++;
}
else if(frame==61) {  
strip.setPixelColor(7,0,135,0);
strip.show(); 
frame++;
}
else if(frame==62) {  
strip.setPixelColor(8,0,135,0);
strip.show(); 
frame++;
}
else if(frame==63) {  
strip.setPixelColor(9,0,135,0);
strip.show(); 
frame++;
}
else if(frame==64) {  
strip.setPixelColor(10,0,135,0);
strip.show(); 
frame++;
}
else if(frame==65) {  
strip.setPixelColor(11,0,135,0);
strip.show(); 
frame++;
}
else if(frame==66) {  
strip.setPixelColor(12,0,135,0);
strip.show(); 
frame++;
}
else if(frame==67) {  
strip.setPixelColor(13,0,135,0);
strip.show(); 
frame++;
}
else if(frame==68) {  
strip.setPixelColor(14,0,135,0);
strip.show(); 
frame++;
}
else if(frame==69) {  
strip.setPixelColor(15,0,135,0);
strip.show(); 
frame = 1;
} else if(frame==70) {  
strip.setPixelColor(0,50,50,50);
strip.setPixelColor(1,0,0,0);
strip.setPixelColor(2,50,50,50);
strip.setPixelColor(3,0,0,0);
strip.setPixelColor(4,50,50,50);
strip.setPixelColor(5,0,0,0);
strip.setPixelColor(6,50,50,50);
strip.setPixelColor(7,0,0,0);
strip.setPixelColor(8,50,50,50);
strip.setPixelColor(9,0,0,0);
strip.setPixelColor(10,50,50,50);
strip.setPixelColor(11,0,0,0);
strip.setPixelColor(12,50,50,50);
strip.setPixelColor(13,0,0,0);
strip.setPixelColor(14,50,50,50);
strip.setPixelColor(15,0,0,0);
strip.show();
}
else if(frame==71) {  
strip.setPixelColor(0,135,0,0);
strip.setPixelColor(1,135,0,0);
strip.setPixelColor(2,135,0,0);
strip.setPixelColor(3,135,0,0);
strip.setPixelColor(4,135,0,0);
strip.setPixelColor(5,135,0,0);
strip.setPixelColor(6,135,0,0);
strip.setPixelColor(7,135,0,0);
strip.setPixelColor(8,135,0,0);
strip.setPixelColor(9,135,0,0);
strip.setPixelColor(10,135,0,0);
strip.setPixelColor(11,135,0,0);
strip.setPixelColor(12,135,0,0);
strip.setPixelColor(13,135,0,0);
strip.setPixelColor(14,135,0,0);
strip.setPixelColor(15,135,0,0);
strip.show();
}
else if(frame==72) {  
strip.setPixelColor(0,0,135,0);
strip.setPixelColor(1,0,135,0);
strip.setPixelColor(2,0,135,0);
strip.setPixelColor(3,0,135,0);
strip.setPixelColor(4,0,135,0);
strip.setPixelColor(5,0,135,0);
strip.setPixelColor(6,0,135,0);
strip.setPixelColor(7,0,135,0);
strip.setPixelColor(8,0,135,0);
strip.setPixelColor(9,0,135,0);
strip.setPixelColor(10,0,135,0);
strip.setPixelColor(11,0,135,0);
strip.setPixelColor(12,0,135,0);
strip.setPixelColor(13,0,135,0);
strip.setPixelColor(14,0,135,0);
strip.setPixelColor(15,0,135,0);
strip.show();
}
else if(frame==73) {  
strip.setPixelColor(0,0,0,135);
strip.setPixelColor(1,0,0,135);
strip.setPixelColor(2,0,0,135);
strip.setPixelColor(3,0,0,135);
strip.setPixelColor(4,0,0,135);
strip.setPixelColor(5,0,0,135);
strip.setPixelColor(6,0,0,135);
strip.setPixelColor(7,0,0,135);
strip.setPixelColor(8,0,0,135);
strip.setPixelColor(9,0,0,135);
strip.setPixelColor(10,0,0,135);
strip.setPixelColor(11,0,0,135);
strip.setPixelColor(12,0,0,135);
strip.setPixelColor(13,0,0,135);
strip.setPixelColor(14,0,0,135);
strip.setPixelColor(15,0,0,135);
strip.show();
}
else if(frame==74) {  
strip.setPixelColor(0,0,68,68);
strip.setPixelColor(1,0,68,68);
strip.setPixelColor(2,0,68,68);
strip.setPixelColor(3,0,68,68);
strip.setPixelColor(4,0,68,68);
strip.setPixelColor(5,0,68,68);
strip.setPixelColor(6,0,68,68);
strip.setPixelColor(7,0,68,68);
strip.setPixelColor(8,0,68,68);
strip.setPixelColor(9,0,68,68);
strip.setPixelColor(10,0,68,68);
strip.setPixelColor(11,0,68,68);
strip.setPixelColor(12,0,68,68);
strip.setPixelColor(13,0,68,68);
strip.setPixelColor(14,0,68,68);
strip.setPixelColor(15,0,68,68);
strip.show();
}
else if(frame==75) {  
strip.setPixelColor(0,68,0,68);
strip.setPixelColor(1,68,0,68);
strip.setPixelColor(2,68,0,68);
strip.setPixelColor(3,68,0,68);
strip.setPixelColor(4,68,0,68);
strip.setPixelColor(5,68,0,68);
strip.setPixelColor(6,68,0,68);
strip.setPixelColor(7,68,0,68);
strip.setPixelColor(8,68,0,68);
strip.setPixelColor(9,68,0,68);
strip.setPixelColor(10,68,0,68);
strip.setPixelColor(11,68,0,68);
strip.setPixelColor(12,68,0,68);
strip.setPixelColor(13,68,0,68);
strip.setPixelColor(14,68,0,68);
strip.setPixelColor(15,68,0,68);
strip.show();
}
else if(frame==76) {  
strip.setPixelColor(0,68,68,0);
strip.setPixelColor(1,68,68,0);
strip.setPixelColor(2,68,68,0);
strip.setPixelColor(3,68,68,0);
strip.setPixelColor(4,68,68,0);
strip.setPixelColor(5,68,68,0);
strip.setPixelColor(6,68,68,0);
strip.setPixelColor(7,68,68,0);
strip.setPixelColor(8,68,68,0);
strip.setPixelColor(9,68,68,0);
strip.setPixelColor(10,68,68,0);
strip.setPixelColor(11,68,68,0);
strip.setPixelColor(12,68,68,0);
strip.setPixelColor(13,68,68,0);
strip.setPixelColor(14,68,68,0);
strip.setPixelColor(15,68,68,0);
strip.show();
}
else if(frame==77) {  
strip.setPixelColor(0,50,50,50);
strip.setPixelColor(1,50,50,50);
strip.setPixelColor(2,50,50,50);
strip.setPixelColor(3,50,50,50);
strip.setPixelColor(4,50,50,50);
strip.setPixelColor(5,50,50,50);
strip.setPixelColor(6,50,50,50);
strip.setPixelColor(7,50,50,50);
strip.setPixelColor(8,50,50,50);
strip.setPixelColor(9,50,50,50);
strip.setPixelColor(10,50,50,50);
strip.setPixelColor(11,50,50,50);
strip.setPixelColor(12,50,50,50);
strip.setPixelColor(13,50,50,50);
strip.setPixelColor(14,50,50,50);
strip.setPixelColor(15,50,50,50);
strip.show();
}
}
void loop(){
char key = kpd.getKey();
if(key)  // Check for a valid key.
{
switch (key)
{
case '1':
frame = 1;
break;
case '#':
frame = 33;
break;
case '2':
frame = 35;
up = 0;
break;
case '3':
frame = 36;
break;
case '4':
frame = 71;
break;
case '5':
frame = 72;
break;
case '6':
frame = 73;
break;
case '7':
frame = 74;
break;
case '8':
frame = 75;
break;
case '9':
frame = 76;
break;
case '*':
frame = 77;
break;
case '0':
resetFunc();
break;
default:
break;
}
}
}

No Comments

Post a Comment

Skip to content