#define RING_BLUE 9 #define RING_GREEN 10 #define RING_RED 11 #define CIRCLE_BLUE 6 #define CIRCLE_GREEN 5 #define CIRCLE_RED 3 #define MAX 255 #define DELAY_ITERATION 50 #define DELAYTIME 20 int ring_iteration = 0; int ring_cur_colors[3] = { 0, 0, 0 }; int ring_new_colors[3] = { 0, 0, 0 }; int circle_iteration = 0; int circle_cur_colors[3] = { 0, 0, 0 }; int circle_new_colors[3] = { 0, 0, 0 }; void setup() { pinMode( RING_BLUE, OUTPUT ); pinMode( RING_GREEN, OUTPUT ); pinMode( RING_RED, OUTPUT ); digitalWrite( RING_BLUE, HIGH ); digitalWrite( RING_GREEN, HIGH ); digitalWrite( RING_RED, HIGH ); pinMode( CIRCLE_BLUE, OUTPUT ); pinMode( CIRCLE_GREEN, OUTPUT ); pinMode( CIRCLE_RED, OUTPUT ); digitalWrite( CIRCLE_BLUE, HIGH ); digitalWrite( CIRCLE_GREEN, HIGH ); digitalWrite( CIRCLE_RED, HIGH ); // Pick random color to start on randomSeed(analogRead(0)); randomColor( 0 ); delay( 1000 ); randomSeed(analogRead(0)); randomColor( 1 ); } void loop() { // Color change for the ring // If the current color matches new colors pick a new color // Stay on new color for a second if ( ring_cur_colors[0] == ring_new_colors[0] && ring_cur_colors[1] == ring_new_colors[1] && ring_cur_colors[2] == ring_new_colors[2]) { if ( ring_iteration > DELAY_ITERATION ) { randomColor( 0 ); ring_iteration = 0; } else { ring_iteration += 1; } } // If color is less than or greater than new color adjust current color + or - 1 if ( ring_cur_colors[0] > ring_new_colors[0] ) { ring_cur_colors[0] -= 1; } if ( ring_cur_colors[0] < ring_new_colors[0] ) { ring_cur_colors[0] += 1; } if ( ring_cur_colors[1] > ring_new_colors[1] ) { ring_cur_colors[1] -= 1; } if ( ring_cur_colors[1] < ring_new_colors[1] ) { ring_cur_colors[1] += 1; } if ( ring_cur_colors[2] > ring_new_colors[2] ) { ring_cur_colors[2] -= 1; } if ( ring_cur_colors[2] < ring_new_colors[2] ) { ring_cur_colors[2] += 1; } analogWrite( RING_BLUE, ring_cur_colors[0] ); analogWrite( RING_GREEN, ring_cur_colors[1] ); analogWrite( RING_RED, ring_cur_colors[2] ); // Color change for the circle // If the current color matches new colors pick a new color // Stay on new color for a second if ( circle_cur_colors[0] == circle_new_colors[0] && circle_cur_colors[1] == circle_new_colors[1] && circle_cur_colors[2] == circle_new_colors[2]) { if ( circle_iteration > DELAY_ITERATION ) { randomColor( 1 ); circle_iteration = 0; } else { circle_iteration += 1; } } // If color is less than or greater than new color adjust current color + or - 1 if ( circle_cur_colors[0] > circle_new_colors[0] ) { circle_cur_colors[0] -= 1; } if ( circle_cur_colors[0] < circle_new_colors[0] ) { circle_cur_colors[0] += 1; } if ( circle_cur_colors[1] > circle_new_colors[1] ) { circle_cur_colors[1] -= 1; } if ( circle_cur_colors[1] < circle_new_colors[1] ) { circle_cur_colors[1] += 1; } if ( circle_cur_colors[2] > circle_new_colors[2] ) { circle_cur_colors[2] -= 1; } if ( circle_cur_colors[2] < circle_new_colors[2] ) { circle_cur_colors[2] += 1; } analogWrite( CIRCLE_BLUE, circle_cur_colors[0] ); analogWrite( CIRCLE_GREEN, circle_cur_colors[1] ); analogWrite( CIRCLE_RED, circle_cur_colors[2] ); delay( DELAYTIME ); } void randomColor( int light ) { // light 0 == ring // light 1 == circle if ( light == 0 ) { ring_new_colors[0] = random( MAX ); ring_new_colors[1] = random( MAX ); ring_new_colors[2] = random( MAX ); } else { circle_new_colors[0] = random( MAX ); circle_new_colors[1] = random( MAX ); circle_new_colors[2] = random( MAX ); } }