#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN D0
// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 30
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
// These constants won't change. They're used to give names to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(WIO_LIGHT, INPUT);
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
// Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
strip.setBrightness(255); // Set BRIGHTNESS to about 1/5 (max = 255)
}
void loop() {
// read the analog in value:
sensorValue = analogRead(WIO_LIGHT);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 30);
LightColor(strip.Color(255, 0, 0), outputValue);
// change the analog out value:
analogWrite(analogOutPin, outputValue);
// print the results to the Serial Monitor:
Serial.print("sensor = ");
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
// wait 2 milliseconds before the next loop for the analog-to-digital
// converter to settle after the last reading:
delay(2);
}
void LightColor(uint32_t color1, int pin) {
for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
strip.setPixelColor(pin, color1);
strip.setPixelColor(pin+1, strip.Color(0, 0, 0));
/* strip.setPixelColor(pin + 1, color1);
strip.setPixelColor(pin + 2, color1); // Set pixel's color (in RAM)
strip.setPixelColor(pin + 3, strip.Color(0, 0, 0));
strip.setPixelColor(pin - 1, strip.Color(0, 0, 0));
*/ strip.show(); // Update strip to match
delay(1); // Pause for a moment
}
}
void doubleColor(uint32_t color1, uint32_t color2, int wait) {
for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
strip.setPixelColor(i, color1);
strip.setPixelColor(i + 1, color1);
strip.setPixelColor(i + 2, color1); // Set pixel's color (in RAM)
strip.setPixelColor(i - 1, color2);
strip.show(); // Update strip to match
delay(wait); // Pause for a moment
}
}