Guest User

Chameleon Scarf Code

a guest
Nov 18th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2. #include <Adafruit_TCS34725.h>
  3. #ifdef __AVR__
  4. #include <avr/power.h>
  5. #endif
  6. // Which pin on the Arduino is connected to the NeoPixels?
  7. // On a Trinket or Gemma we suggest changing this to 1
  8. #define PIN 1
  9. // How many NeoPixels are attached to the Arduino?
  10. #define NUMPIXELS 1
  11. #define RED 0
  12. #define GREEN 1
  13. #define BLUE 2
  14. void setup() {
  15. #if defined (__AVR_ATtiny85__)
  16. if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  17. #endif
  18. Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
  19. Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
  20. byte *rgb = (byte *)malloc(sizeof(byte) * 3);
  21. uint16_t *redgreenblue = (uint16_t *)malloc(sizeof(uint16_t) * 4);
  22. // End of trinket special code
  23. delay(3000);
  24. pixels.begin(); // This initializes the NeoPixel library.
  25. tcs.begin();
  26. tcs.setInterrupt(false); // turn on LED
  27. delay(800); // takes 50ms to read
  28. tcs.getRawData(redgreenblue, redgreenblue + 1, redgreenblue + 2, redgreenblue + 3);
  29. //delay(30);
  30. tcs.setInterrupt(true); // turn off LED
  31.  
  32. double sum;
  33.  
  34. sum = redgreenblue[BLUE + 1];
  35. rgb[RED] = redgreenblue[RED] / sum * 256;
  36. rgb[GREEN] = redgreenblue[GREEN] / sum * 256;
  37. rgb[BLUE] = redgreenblue[BLUE] / sum * 256;
  38. int i;
  39. for (int i = 0; i < 256; i++) {
  40. float x = i;
  41. x /= 255;
  42. x = x * x;//pow(x, 2.5);
  43. x *= 255;
  44. if (rgb[RED] == i) {
  45. rgb[RED] = x;
  46. }
  47. if (rgb[GREEN] == i) {
  48. rgb[GREEN] = x;
  49. }
  50. if (rgb[BLUE] == i) {
  51. rgb[BLUE] = x;
  52. }
  53. }
  54. for (int i = 0; i < NUMPIXELS; i++) {
  55. // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
  56. pixels.setPixelColor(i, pixels.Color((byte)rgb[RED], (byte)rgb[GREEN], (byte)rgb[BLUE])); // Moderately bright green color.
  57. pixels.show(); // This sends the updated pixel color to the hardware.
  58. delay(500); // Delay for a period of time (in milliseconds).
  59. }
  60. }
  61. void loop() {}
Add Comment
Please, Sign In to add comment