Portfolio. BHSAD Arduino Prototyping | L4, Harduino: Drawing light | Page 28

full Code for infinity mirror Thermometer #include #include #include lcd.setCursor(0, 1); lcd.print(t); lcd.print(“ C”); showStrip(); delay(SpeedDelay); } } #define PIN 3 #define NUM_LEDS 18 //number of pixels in strip Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800); LiquidCrystal lcd(13, 12, 11, 10, 9, 8); DHT dht(DHTPIN, DHTTYPE); //Setup the NeoPixel Strip int lastTimeCkeched; float h; float t; int cylesPassed = 0; void setup() { lcd.begin(16, 2); dht.begin(); strip.begin(); strip.show(); // Initialize all pixels to ‘off’ Serial.begin(9600); } void loop() { cylesPassed = cylesPassed + 1; Serial.println(cylesPassed); if (cylesPassed >= 150) { h = dht.readHumidity(); t = dht.readTemperature(); Serial.print(“ckecked at “); Serial.println(millis()); if (isnan(t) || isnan(h)) { lcd.print(“NO CONNECTION”); return; } else { lcd.setCursor(0, 0); lcd.print(h); lcd.print(“ % “); delay(ReturnDelay); cylesPassed = 0; } if (t >= 35) { ColorPlay3(); } else if (t >= 30) { ColorPlay1(); cylesPassed = cylesPassed+1000; } else if (t >= 20) { ColorPlay2(); cylesPassed = cylesPassed+1000; } } ///////WIPE ColorPlay1/////////////////////////// void ColorPlay1() { colorWipe(0xff,0x0f,0x5f, 50); colorWipe(0x00,0x00,0x00, 50); } void colorWipe(byte red, byte green, byte blue, int SpeedDelay) { for(uint16_t i=0; i 0; i--) { setAll(0,0,0); setPixel(i, red/10, green/10, blue/10); for(int j = 1; j <= EyeSize; j++) { setPixel(i+j, red, green, blue); } setPixel(i+EyeSize+1, red/10, green/10, blue/10); showStrip(); delay(SpeedDelay); } delay(ReturnDelay); } /////////FIRE ColorPlay3///////////////////////////////////// void ColorPlay3() { Fire(50,120,20); } void Fire(int Cooling, int Sparking, int SpeedDelay) { static byte heat[NUM_LEDS]; int cooldown; // Step 1. Cool down every cell a little for( int i = 0; i < NUM_LEDS; i++) { cooldown = random(0, ((Cooling * 10) / NUM_LEDS) + 2); if(cooldown>heat[i]) { heat[i]=0; } else { heat[i]=heat[i]-cooldown; } } // Step 2. Heat from each cell drifts ‘up’ and diffuses a little for( int k= NUM_LEDS - 1; k >= 2; k--) { heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3; } // Step 3. Randomly ignite new ‘sparks’ near the bottom if( random(255) < Sparking ) { int y = random(7); heat[y] = heat[y] + random(160,255); //heat[y] = random(160,255); } showStrip(); delay(SpeedDelay); } void setPixelHeatColor (int Pixel, byte temperature) { // Scale ‘heat’ down from 0-255 to 0-191 byte t192 = round((temperature/255.0)*191); // calculate ramp up from byte heatramp = t192 & 0x3F; // 0..63 heatramp <<= 2; // scale up to 0..252 // figure out which third of the spectrum we’re in: if( t192 > 0x80) { // hottest setPixel(Pixel, 255, 255, heatramp); } else if( t192 > 0x40 ) { // middle setPixel(Pixel, 255, heatramp, 0); } else { // coolest setPixel(Pixel, heatramp, 0, 0); } } ////////////////////////////////////////////////////////// void showStrip() { #ifdef ADAFRUIT_NEOPIXEL_H // NeoPixel strip.show(); #endif } void setPixel(int Pixel, byte red, byte green, byte blue) { #ifdef ADAFRUIT_NEOPIXEL_H // NeoPixel strip.setPixelColor(Pixel, strip.Color(red, green, blue)); #endif } void setAll(byte red, byte green, byte blue) { for(int i = 0; i < NUM_LEDS; i++ ) { setPixel(i, red, green, blue); } showStrip(); } #define DHTPIN A0 #define DHTTYPE DHT11 // Step 4. Convert heat to LED colors for( int j = 0; j < NUM_LEDS; j++) { setPixelHeatColor(j, heat[j] ); }