-
-
Save monkbroc/6805c656e5897450da4275c3bc0dfd72 to your computer and use it in GitHub Desktop.
Revisions
-
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,72 @@ /* Pixel wave * Copyright 2016 Julien Vanier, MIT license * * Connect 3 photoresistors to analog inputs and drive a Dotstar/Neopixel strip from the 3 analog signals! */ #include "application.h" #include "dotstar/dotstar.h" SYSTEM_THREAD(ENABLED); // IMPORTANT: Connect Dotstar strand to hardware SPI (Data => A5 and Clock => A3) #define PIXEL_COUNT 72 #define BRIGHTNESS 255 #define SPEED 10 #define PIN_RED A0 #define PIN_GREEN A1 #define PIN_BLUE A6 #define VOLTAGE_MAX_NOMINAL (3.3 * 256 / 4096) #define VOLTAGE_MAX_RED 0.190 #define VOLTAGE_MAX_GREEN 0.220 #define VOLTAGE_MAX_BLUE 0.130 Adafruit_DotStar strip = Adafruit_DotStar(PIXEL_COUNT, DOTSTAR_BGR); uint32_t colors[PIXEL_COUNT] = { 0 }; uint16_t pos = 0; void setup() { strip.begin(); strip.setBrightness(BRIGHTNESS); strip.show(); pinMode(PIN_RED, INPUT); pinMode(PIN_GREEN, INPUT); pinMode(PIN_BLUE, INPUT); } void loop() { updateColor(); showStrip(); delay(SPEED); } void updateColor() { colors[pos] = strip.Color( pinColor(PIN_RED, VOLTAGE_MAX_RED), pinColor(PIN_GREEN, VOLTAGE_MAX_GREEN), pinColor(PIN_BLUE, VOLTAGE_MAX_BLUE) ); } uint8_t pinColor(pin_t pin, float voltageMax) { int value = (int)(analogRead(pin) * VOLTAGE_MAX_NOMINAL / voltageMax); if (value > 255) { value = 255; } return 255 - value; } void showStrip() { for (uint16_t i = 0; i < PIXEL_COUNT; i++) { uint16_t n = (i + pos) % PIXEL_COUNT; strip.setPixelColor(PIXEL_COUNT - i, colors[n]); } strip.show(); pos = (pos + 1) % PIXEL_COUNT; }