The Code
Below is the code I loaded onto each of the ATTiny85 microcontrollers. Each stone had a slight modification to adjust for the the particular elemental color of that stone.
Elemental Stone Arduino Sketch
#include <Adafruit_NeoPixel.h> //#include <avr/power.h> //#include <avr/sleep.h> //#include <avr/io.h> // Adds useful constants //#include <util/delay.h> // Adds delay_ms and delay_us functions //#include <avr/wdt.h> const int SERVO_PIN = 0; const int SWITCH_PIN = 2; const int PIXEL_PIN = 4; //Modes const int STONE_MODE = 0; const int RAINBOW_MODE = 1; const int COLOR_WIPE = 2; const int THEATER_CHASE = 3; const int LAMP_100 = 4; const int LAMP_75 = 5; const int LAMP_50 = 6; const int LAMP_25 = 7; volatile int pixelMode = 0; volatile boolean interrupted = false; unsigned long startMillis; unsigned long currentMillis; const unsigned long MODE_SWITCH_DELAY = 1500; const byte ledPin = 13; volatile int counter = 0; //bool previousSwitch = false; Adafruit_NeoPixel pixels = Adafruit_NeoPixel(3, PIXEL_PIN, NEO_GRB + NEO_KHZ800); uint32_t blue = pixels.Color(0, 0, 255); uint32_t red = pixels.Color(255, 0, 0); uint32_t green = pixels.Color(0, 255, 0); uint32_t yellow = pixels.Color(255, 100, 0); void setup() { //Serial.begin(9600); //Serial.println("Booting..."); //ADCSRA &= ~(1<<ADEN); //setup_watchdog(8); // approximately 0.5 seconds sleep pinMode(SWITCH_PIN, INPUT_PULLUP); attachInterrupt(0, changeMode, RISING); pixelMode = STONE_MODE; pixels.begin(); pixels.show(); } void loop() { switch (pixelMode) { case STONE_MODE: //0 stone(); break; case RAINBOW_MODE: //1 rainbow(20); rainbowCycle(20); break; case COLOR_WIPE: //2 colorWipe(pixels.Color(255, 0, 0), 50); // Red colorWipe(pixels.Color(0, 255, 0), 50); // Green colorWipe(pixels.Color(0, 0, 255), 50); // Blue break; case THEATER_CHASE: //3 theaterChase(pixels.Color(127, 127, 127), 50); // White theaterChase(pixels.Color(127, 0, 0), 50); // Red theaterChase(pixels.Color(0, 0, 127), 50); // Blue break; case LAMP_100: //4 lamp(100); break; case LAMP_75: //5 lamp(75); break; case LAMP_50: //6 lamp(50); break; case LAMP_25: //7 lamp(25); break; } interrupted = false; } void changeMode() { currentMillis = millis(); //get the current "time" (actually the number of milliseconds since the program started) if (currentMillis - startMillis >= MODE_SWITCH_DELAY) { interrupted = true; pixelMode = pixelMode + 1; if (pixelMode > 7) {pixelMode = 0;} startMillis = currentMillis; } } //void sleep() { // ADCSRA &= ~_BV(ADEN); // ADC off // set_sleep_mode(SLEEP_MODE_PWR_DOWN); // replaces above statement // sleep_enable(); // Sets the Sleep Enable bit in the MCUCR Register (SE BIT) // sleep_cpu(); // sleep // sleep_disable(); // Clear SE bit // ADCSRA |= _BV(ADEN); // ADC on //} // sleep void colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i=0; i<pixels.numPixels(); i++) { pixels.setPixelColor(i, c); pixels.show(); delay(wait); } } void rainbow(uint8_t wait) { uint16_t i, j; for(j=0; j<256; j++) { for(i=0; i<pixels.numPixels(); i++) { pixels.setPixelColor(i, Wheel((i+j) & 255)); } pixels.show(); delay(wait); if (interrupted == true){break;} } } // Slightly different, this makes the rainbow equally distributed throughout void rainbowCycle(uint8_t wait) { uint16_t i, j; for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel for(i=0; i< pixels.numPixels(); i++) { pixels.setPixelColor(i, Wheel(((i * 256 / pixels.numPixels()) + j) & 255)); } pixels.show(); delay(wait); if (interrupted == true){break;} } } //Theatre-style crawling lights. void theaterChase(uint32_t c, uint8_t wait) { for (int j=0; j<10; j++) { //do 10 cycles of chasing for (int q=0; q < 3; q++) { for (uint16_t i=0; i < pixels.numPixels(); i=i+3) { pixels.setPixelColor(i+q, c); //turn every third pixel on } pixels.show(); delay(wait); for (uint16_t i=0; i < pixels.numPixels(); i=i+3) { pixels.setPixelColor(i+q, 0); //turn every third pixel off } if (interrupted == true){break;} } } } //Theatre-style crawling lights with rainbow effect void theaterChaseRainbow(uint8_t wait) { for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel for (int q=0; q < 3; q++) { for (uint16_t i=0; i < pixels.numPixels(); i=i+3) { pixels.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on } pixels.show(); delay(wait); for (uint16_t i=0; i < pixels.numPixels(); i=i+3) { pixels.setPixelColor(i+q, 0); //turn every third pixel off } if (interrupted == true){break;} } } } // Input a value 0 to 255 to get a color value. // The colours are a transition r - g - b - back to r. uint32_t Wheel(byte WheelPos) { WheelPos = 255 - WheelPos; if(WheelPos < 85) { return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3); } if(WheelPos < 170) { WheelPos -= 85; return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3); } WheelPos -= 170; return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0); } void stone() { float i, in, p0, p1, p2; pixels.setBrightness(128); for (int i = 0; i < 4; i++) { for (in = 0; in < 6.283; in = in + 0.01) { p0 = sin(in - PI) * 127.5 + 127.5; p1 = sin(in - PI / 2) * 127.5 + 127.5; p2 = sin(in) * 127.5 + 127.5; //Wind (Yellow) pixels.setPixelColor(0, .4 * p0, p0, 0); pixels.setPixelColor(1, .4 * p1, p1, 0); pixels.setPixelColor(2, .4 * p2, p2, 0); //Earth (Green) //pixels.setPixelColor(0, p0, 0, 0); //pixels.setPixelColor(1, p1, 0, 0); //pixels.setPixelColor(2, p2, 0, 0); //Water (Blue) //pixels.setPixelColor(0, 0, 0, p0); //pixels.setPixelColor(1, 0, 0, p1); //pixels.setPixelColor(2, 0, 0, p2); //Fire (Red) //pixels.setPixelColor(0, 0, p0, 0); //pixels.setPixelColor(1, 0, p1, 0); //pixels.setPixelColor(2, 0, p2, 0); pixels.show(); if (interrupted == true){break;} } } //Wind (Yellow) pixels.setPixelColor(0, 100, 255, 0); pixels.setPixelColor(1, 100, 255, 0); pixels.setPixelColor(2, 100, 255, 0); //Earth (Green) //pixels.setPixelColor(0, 255, 0, 0); //pixels.setPixelColor(1, 255, 0, 0); //pixels.setPixelColor(2, 255, 0, 0); pixels.show(); //delay(5000); //sleep(); } void lamp(int brightness) { int i; pixels.setBrightness(brightness); ColorSet(pixels.Color(255, 255, 255)); //delay(5000); //sleep(); } // Set all pixels to a color (synchronously) void ColorSet(uint32_t color) { for (int i = 0; i < pixels.numPixels(); i++) { pixels.setPixelColor(i, color); } pixels.show(); }
Styrofoam get everywhere; none the less these are some of my favorite art pieces that you have created.