Advertisement
Guest User

Spidey Sensor - Touch and Temperature

a guest
Apr 27th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 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. int delayval = 10; // delay for half a second
  33.  
  34. int count = 0; // frame counter
  35.  
  36.  
  37. void setup()
  38. {
  39. pinMode(TEMP_IN_PIN, INPUT); // temperature input (reads thermistor voltage divider)
  40.  
  41. pixels.begin(); // This initializes the NeoPixel library.
  42. }
  43.  
  44.  
  45.  
  46. void loop()
  47. {
  48. // read in the temperature
  49. int temperatureInput = analogRead(TEMP_IN_PIN);
  50.  
  51. // maptemperature to a sigmoid function
  52. float tempColorCold = 64.0 / (1.0 + exp( (TEMP_OFFSET - temperatureInput) / TEMP_SENSITIVITY ) );
  53. float tempColorHot = 64.0 - tempColorCold;
  54.  
  55.  
  56. // use signed modulus to create a sine wave for both tcolorA and colorB pixels
  57. int modulus = 127.0*(1.0 + sin(2.0*PI * count/256.0) );
  58.  
  59. // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
  60. // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
  61. pixels.setPixelColor(0, pixels.Color(0*modulus, 0, 0)); // Moderately bright green color.
  62. pixels.setPixelColor(1, pixels.Color(0, tempColorHot, tempColorCold)); // Moderately bright green color.
  63. pixels.show(); // This sends the updated pixel color to the hardware.
  64.  
  65. ++count; // increment frame counter
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement