So, my new Nano testing board with screw terminal break out shield arrived. My soldering is not perfect, but I am still waiting on some flux and desoldering wick to arrive to have another go at it. I’ve certainly seen worse though 🙂
The new iteration of the code adds more animations and control with the keypad. We’ll soon start making videos and uploading them so you can get a glimpse into Team Accessible Pixel’s workshop 🙂
// interrupt_animation_3.ino
// designed by AccessiblePixel.com
//Include Libraries
#include <Adafruit_NeoPixel.h>
#include <Keypad.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
// Initialise Variables
#define PINBACK 9 // PIN for REAR light
#define PINFLOOR 10 // PIN for FLOOR light
#define PINFRONT 11 // PIN for FRONT light
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;
// Initialise Pixels
Adafruit_NeoPixel stripBack = Adafruit_NeoPixel(16, PINBACK, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripFloor = Adafruit_NeoPixel(16, PINFLOOR, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripFront = Adafruit_NeoPixel(16, PINFRONT, 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 Back Pixels
stripBack.begin();
stripBack.show();
// Initialize Floor Pixels
stripFloor.begin();
stripFloor.show();
// Initialize Front Pixels
stripFront.begin();
stripFront.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
uint32_t wheelz(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return stripBack.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return stripBack.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return stripBack.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<stripBack.numPixels(); i++) {
stripBack.setPixelColor(i, c);
stripBack.show();
delay(wait);
}
}
// Run Animation Frames
ISR(TIMER1_COMPA_vect){
if(frame==1){
stripBack.setPixelColor(0,r,g,b);
stripBack.show();
frame++;
}
else if(frame==2) {
stripBack.setPixelColor(1,r,g,b);
stripBack.show();
frame++;
}
else if(frame==3) {
stripBack.setPixelColor(2,r,g,b);
stripBack.show();
frame++;
}
else if(frame==4) {
stripBack.setPixelColor(3,r,g,b);
stripBack.show();
frame++;
}
else if(frame==5) {
stripBack.setPixelColor(4,r,g,b);
stripBack.show();
frame++;
}
else if(frame==6) {
stripBack.setPixelColor(5,r,g,b);
delay(50);
stripBack.show();
frame++;
}
else if(frame==7) {
stripBack.setPixelColor(6,r,g,b);
stripBack.show();
frame++;
}
else if(frame==8) {
stripBack.setPixelColor(7,r,g,b);
delay(50);
stripBack.show();
frame++;
}
else if(frame==9) {
stripBack.setPixelColor(8,r,g,b);
stripBack.show();
frame++;
}
else if(frame==10) {
stripBack.setPixelColor(9,r,g,b);
stripBack.show();
frame++;
}
else if(frame==11) {
stripBack.setPixelColor(10,r,g,b);
stripBack.show();
frame++;
}
else if(frame==12) {
stripBack.setPixelColor(11,r,g,b);
stripBack.show();
frame++;
}
else if(frame==13) {
stripBack.setPixelColor(12,r,g,b);
stripBack.show();
frame++;
}
else if(frame==14) {
stripBack.setPixelColor(13,r,g,b);
stripBack.show();
frame++;
}
else if(frame==15) {
stripBack.setPixelColor(14,r,g,b);
stripBack.show();
frame++;
}
else if(frame==16) {
stripBack.setPixelColor(15,r,g,b);
stripBack.show();
}
else if(frame==17){
stripBack.setPixelColor(15,0,0,0);
stripBack.show();
frame++;
}
else if(frame==18) {
stripBack.setPixelColor(14,0,0,0);
stripBack.show();
frame++;
}
else if(frame==19) {
stripBack.setPixelColor(13,0,0,0);
stripBack.show();
frame++;
}
else if(frame==20) {
stripBack.setPixelColor(12,0,0,0);
stripBack.show();
frame++;
}
else if(frame==21) {
stripBack.setPixelColor(11,0,0,0);
stripBack.show();
frame++;
}
else if(frame==22) {
stripBack.setPixelColor(10,0,0,0);
stripBack.show();
frame++;
}
else if(frame==23) {
stripBack.setPixelColor(9,0,0,0);
stripBack.show();
frame++;
}
else if(frame==24) {
stripBack.setPixelColor(8,0,0,0);
delay(50);
stripBack.show();
frame++;
}
else if(frame==25) {
stripBack.setPixelColor(7,0,0,0);
stripBack.show();
frame++;
}
else if(frame==26) {
stripBack.setPixelColor(6,0,0,0);
stripBack.show();
frame++;
}
else if(frame==27) {
stripBack.setPixelColor(5,0,0,0);
stripBack.show();
frame++;
}
else if(frame==28) {
stripBack.setPixelColor(4,0,0,0);
stripBack.show();
frame++;
}
else if(frame==29) {
stripBack.setPixelColor(3,0,0,0);
stripBack.show();
frame++;
}
else if(frame==30) {
stripBack.setPixelColor(2,0,0,0);
stripBack.show();
frame++;
}
else if(frame==31) {
stripBack.setPixelColor(1,0,0,0);
stripBack.show();
frame++;
}
else if(frame==32) {
stripBack.setPixelColor(0,0,0,0);
stripBack.show();
} else if(frame==33) {
stripBack.setPixelColor(random(0,15),random(0,25),random(0,25),random(0,25));
stripBack.setPixelColor(random(0,15),0,0,0,0);
stripBack.setPixelColor(random(0,15),0,0,0,0);
delay(30);
stripBack.show();
}
else if(frame==34){stripBack.setPixelColor(0,0,0,0);
stripBack.setPixelColor(1,0,0,0);
stripBack.setPixelColor(2,0,0,0);
stripBack.setPixelColor(3,0,0,0);
stripBack.setPixelColor(4,0,0,0);
stripBack.setPixelColor(5,0,0,0);
stripBack.setPixelColor(6,0,0,0);
stripBack.setPixelColor(7,0,0,0);
stripBack.setPixelColor(8,0,0,0);
stripBack.setPixelColor(9,0,0,0);
stripBack.setPixelColor(10,0,0,0);
stripBack.setPixelColor(11,0,0,0);
stripBack.setPixelColor(12,0,0,0);
stripBack.setPixelColor(13,0,0,0);
stripBack.setPixelColor(14,0,0,0);
stripBack.setPixelColor(15,0,0,0);
stripBack.show();
}
else if(frame==35){
stripBack.setPixelColor(0,brightred,brightgreen,brightblue);
stripBack.setPixelColor(1,brightred,brightgreen,brightblue);
stripBack.setPixelColor(2,brightred,brightgreen,brightblue);
stripBack.setPixelColor(3,brightred,brightgreen,brightblue);
stripBack.setPixelColor(4,brightred,brightgreen,brightblue);
stripBack.setPixelColor(5,brightred,brightgreen,brightblue);
stripBack.setPixelColor(6,brightred,brightgreen,brightblue);
stripBack.setPixelColor(7,brightred,brightgreen,brightblue);
stripBack.setPixelColor(8,brightred,brightgreen,brightblue);
stripBack.setPixelColor(9,brightred,brightgreen,brightblue);
stripBack.setPixelColor(10,brightred,brightgreen,brightblue);
stripBack.setPixelColor(11,brightred,brightgreen,brightblue);
stripBack.setPixelColor(12,brightred,brightgreen,brightblue);
stripBack.setPixelColor(13,brightred,brightgreen,brightblue);
stripBack.setPixelColor(14,brightred,brightgreen,brightblue);
stripBack.setPixelColor(15,brightred,brightgreen,brightblue);
stripBack.show();
if (brightcolor==0) {
if (up == 0) {
if (brightred < 60) {
brightred++;
}
else if (brightred == 60) {
brightred=60;
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 < 60) {
brightgreen++;
}
else if (brightgreen == 60) {
brightgreen=60;
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 < 60) {
brightblue++;
}
else if (brightblue == 60) {
brightblue=60;
up = 1;
}
}
else if(up == 1) {
if(brightblue > 0) {
brightblue--;
}
else if (brightblue == 0) {
up = 0;brightcolor=0;
}
}
}
}
else if(frame==36){
stripBack.setPixelColor(rainbowi, wheelz((rainbowi+rainboww) & 255));
stripFloor.setPixelColor(rainbowi, wheelz((rainbowi+rainboww) & 255));
stripFront.setPixelColor(rainbowi, wheelz((rainbowi+rainboww) & 255));
stripBack.show();
stripFloor.show();
stripFront.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;}
}
void loop()
{
char key = kpd.getKey();
if(key) // Check for a valid key.
{
switch (key)
{
case '1':
if(backcolorframe==0) {
r = 60;
g = 0;
b = 0;
backcolorframe++;
frame = 1;
}
else if(backcolorframe==1) {
r = 0;
g = 60;
b = 0;
backcolorframe++; frame = 1;
}
else if(backcolorframe==2) {
r = 0;
g = 0;
b = 60;
backcolorframe++; frame = 1;
}
else if(backcolorframe==3) {
r = 30;
g = 0;
b = 30;
backcolorframe++; frame = 1;
}
else if(backcolorframe==4) {
r = 30;
g = 30;
b = 30;
backcolorframe=0; frame = 1;
}
break;
case '2':
frame = 17;
backcolorframe=0;
break;
case '3':
frame = 33;
break;
case '4':
frame = 35;
up = 0;
break;
case '*':
frame = 36;
break;
case '0':
frame = 34;
backcolorframe=0;
brightcolor=0;
brightred = 0;
brightgreen = 0;
brightblue = 0;
r = 0;
g = 0;
b = 0;
up = 0;
rainbowi = 0;
rainboww = 0;
break;
default:
break;
}
}
}