/ DIY_Thermal_Light_Painting / DIY_Thermal_Light_Painting.ino
DIY_Thermal_Light_Painting.ino
1 // SPDX-FileCopyrightText: 2018 Limor Fried for Adafruit Industries 2 // 3 // SPDX-License-Identifier: MIT 4 5 /*************************************************** 6 This is a library for the MLX90614 temperature sensor SPECIFICALLY 7 FOR USE WITH TINYWIREM ON TRINKET/GEMMA 8 9 Requires the latest TinyWireM with repeated-start support 10 https://github.com/adafruit/TinyWireM 11 12 NOT FOR REGULAR ARDUINOS! Use the regular Adafruit_MLX90614 for that 13 14 Designed specifically to work with the MLX90614 sensors in the 15 adafruit shop 16 ----> https://www.adafruit.com/products/1748 17 ----> https://www.adafruit.com/products/1749 18 19 These sensors use I2C to communicate, 2 pins are required to 20 interface 21 Adafruit invests time and resources providing this open source code, 22 please support Adafruit and open-source hardware by purchasing 23 products from Adafruit! 24 25 Written by Limor Fried/Ladyada for Adafruit in any redistribution 26 ****************************************************/ 27 28 #include <Adafruit_MLX90614.h> 29 #include <Adafruit_NeoPixel.h> 30 31 // change these to adjust the range of temperatures you want to measure 32 // (these are in Farenheit) 33 #define COLDTEMP 60 34 #define HOTTEMP 80 35 36 37 #define PIN 1 38 Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800); 39 40 Adafruit_MLX90614 mlx = Adafruit_MLX90614(); 41 42 void setup() { 43 mlx.begin(); 44 strip.begin(); 45 strip.show(); // Initialize all pixels to 'off' 46 } 47 48 void loop() { 49 uint8_t red, blue; 50 float temp = mlx.readObjectTempF(); 51 52 if (temp < COLDTEMP) temp = COLDTEMP; 53 if (temp > HOTTEMP) temp = HOTTEMP; 54 55 // map temperature to red/blue color 56 // hotter temp -> more red 57 red = map(temp, COLDTEMP, HOTTEMP, 0, 255); 58 // hotter temp -> less blue 59 blue = map(temp, COLDTEMP, HOTTEMP, 255, 0); 60 61 colorWipe(strip.Color(red, 0, blue), 0); 62 63 delay(50); // can adjust this for faster/slower updates 64 } 65 66 // Fill the dots one after the other with a color 67 void colorWipe(uint32_t c, uint8_t wait) { 68 for(uint16_t i=0; i<strip.numPixels(); i++) { 69 strip.setPixelColor(i, c); 70 strip.show(); 71 delay(wait); 72 } 73 }