Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // NeoPixel Ring simple sketch (c) 2013 Shae Erisson
- // released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
- #include <Adafruit_NeoPixel.h>
- #include <avr/power.h>
- // Which pin on the Arduino is connected to the NeoPixels?
- // On a Trinket or Gemma we suggest changing this to 1
- #define PIN 4
- // How many NeoPixels are attached to the Arduino?
- #define NUMPIXELS 2
- // thermistor voltage divider input pin
- #define TEMP_IN_PIN A3
- // exponent for sensitivity purposes
- #define EXPONENT 2
- // define the sensitivity of the temperature meastuement
- // smaller numbers are more sensitive, change from 16 to 256 in binary progression
- #define TEMP_SENSITIVITY 80
- // define the offset of the Temperature
- // typical values are around 512, give or take 200 or so but 512 is the central number
- #define TEMP_OFFSET 700
- // When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
- // Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
- // example for more information on possible values.
- Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
- int delayval = 10; // delay for half a second
- int count = 0; // frame counter
- void setup()
- {
- pinMode(TEMP_IN_PIN, INPUT); // temperature input (reads thermistor voltage divider)
- pixels.begin(); // This initializes the NeoPixel library.
- }
- void loop()
- {
- // read in the temperature
- int temperatureInput = analogRead(TEMP_IN_PIN);
- // maptemperature to a sigmoid function
- float tempColorCold = 64.0 / (1.0 + exp( (TEMP_OFFSET - temperatureInput) / TEMP_SENSITIVITY ) );
- float tempColorHot = 64.0 - tempColorCold;
- // use signed modulus to create a sine wave for both tcolorA and colorB pixels
- int modulus = 127.0*(1.0 + sin(2.0*PI * count/256.0) );
- // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
- // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
- pixels.setPixelColor(0, pixels.Color(0*modulus, 0, 0)); // Moderately bright green color.
- pixels.setPixelColor(1, pixels.Color(0, tempColorHot, tempColorCold)); // Moderately bright green color.
- pixels.show(); // This sends the updated pixel color to the hardware.
- ++count; // increment frame counter
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement