Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_NeoPixel.h>
- #include <Adafruit_TCS34725.h>
- #ifdef __AVR__
- #include <avr/power.h>
- #endif
- // Which pin on the Arduino is connected to the NeoPixels?
- // On a Trinket or Gemma we suggest changing this to 1
- #define PIN 1
- // How many NeoPixels are attached to the Arduino?
- #define NUMPIXELS 1
- #define RED 0
- #define GREEN 1
- #define BLUE 2
- void setup() {
- #if defined (__AVR_ATtiny85__)
- if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
- #endif
- Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
- Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
- byte *rgb = (byte *)malloc(sizeof(byte) * 3);
- uint16_t *redgreenblue = (uint16_t *)malloc(sizeof(uint16_t) * 4);
- // End of trinket special code
- delay(3000);
- pixels.begin(); // This initializes the NeoPixel library.
- tcs.begin();
- tcs.setInterrupt(false); // turn on LED
- delay(800); // takes 50ms to read
- tcs.getRawData(redgreenblue, redgreenblue + 1, redgreenblue + 2, redgreenblue + 3);
- //delay(30);
- tcs.setInterrupt(true); // turn off LED
- double sum;
- sum = redgreenblue[BLUE + 1];
- rgb[RED] = redgreenblue[RED] / sum * 256;
- rgb[GREEN] = redgreenblue[GREEN] / sum * 256;
- rgb[BLUE] = redgreenblue[BLUE] / sum * 256;
- int i;
- for (int i = 0; i < 256; i++) {
- float x = i;
- x /= 255;
- x = x * x;//pow(x, 2.5);
- x *= 255;
- if (rgb[RED] == i) {
- rgb[RED] = x;
- }
- if (rgb[GREEN] == i) {
- rgb[GREEN] = x;
- }
- if (rgb[BLUE] == i) {
- rgb[BLUE] = x;
- }
- }
- for (int i = 0; i < NUMPIXELS; i++) {
- // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
- pixels.setPixelColor(i, pixels.Color((byte)rgb[RED], (byte)rgb[GREEN], (byte)rgb[BLUE])); // Moderately bright green color.
- pixels.show(); // This sends the updated pixel color to the hardware.
- delay(500); // Delay for a period of time (in milliseconds).
- }
- }
- void loop() {}
Add Comment
Please, Sign In to add comment