Advertisement
Guest User

Spidey Sensor - Touch and Temperature

a guest
Apr 27th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. // NeoPixel Ring simple sketch (c) 2013 Shae Erisson
  2. // released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
  3.  
  4. #include <Adafruit_NeoPixel.h>
  5. #include <avr/power.h>
  6.  
  7. // Which pin on the Arduino is connected to the NeoPixels?
  8. // On a Trinket or Gemma we suggest changing this to 1
  9. #define PIN            4
  10.  
  11. // How many NeoPixels are attached to the Arduino?
  12. #define NUMPIXELS      2
  13.  
  14. // thermistor voltage divider input pin
  15. #define TEMP_IN_PIN    A3
  16.  
  17. // exponent for sensitivity purposes
  18. #define EXPONENT       2
  19.  
  20. // define the sensitivity of the temperature meastuement
  21. // smaller numbers are more sensitive, change from 16 to 256 in binary progression
  22. #define TEMP_SENSITIVITY    80
  23.  
  24. // define the offset of the Temperature
  25. // typical values are around 512, give or take 200 or so but 512 is the central number
  26. #define TEMP_OFFSET         700
  27. // When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
  28. // Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
  29. // example for more information on possible values.
  30. Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
  31.  
  32.  
  33.  
  34. void setup()
  35. {
  36.   pinMode(TEMP_IN_PIN, INPUT);  // temperature input (reads thermistor voltage divider)
  37.  
  38.   pixels.begin(); // This initializes the NeoPixel library.
  39. }
  40.  
  41.  
  42.  
  43. void loop()
  44. {
  45.   // read in the temperature
  46.   int temperatureInput = analogRead(TEMP_IN_PIN);
  47.  
  48.   // maptemperature to a sigmoid function
  49.   float tempColorCold = 64.0 / (1.0 + exp( (TEMP_OFFSET - temperatureInput) / TEMP_SENSITIVITY ) );
  50.   float tempColorHot = 64.0 - tempColorCold;
  51.  
  52.   // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
  53.   // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
  54.   pixels.setPixelColor(0, pixels.Color(0, 0, 0)); // Moderately bright green color.
  55.   pixels.setPixelColor(1, pixels.Color(0, tempColorHot, tempColorCold)); // Moderately bright green color.
  56.   pixels.show(); // This sends the updated pixel color to the hardware.
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement