Skip to content

Instantly share code, notes, and snippets.

@pinglunliao
Created November 17, 2018 01:17
Show Gist options
  • Save pinglunliao/c333d2215a602f680dffcaeee8b181f4 to your computer and use it in GitHub Desktop.
Save pinglunliao/c333d2215a602f680dffcaeee8b181f4 to your computer and use it in GitHub Desktop.
#include <Adafruit_NeoPixel.h>
#define LDR_PIN A0
#define PIN 2 // input pin Neopixel is attached to
#define NUMPIXELS 12 // number of neopixels in Ring
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 0; // timing delay
int redColor = 0;
int greenColor = 0;
int blueColor = 0;
int lightLevel = 0;
int preLightLevel = 0;
void setup() {
pixels.begin(); // Initializes the NeoPixel library.
// Serial.begin(9600);
}
void loop() {
setColor();
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(redColor, greenColor, blueColor)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
// setColor()
// picks random values to set for RGB
void setColor(){
lightLevel = map(analogRead(LDR_PIN), 0, 1023, 255, 10);
Serial.println(lightLevel);
if( preLightLevel != lightLevel ) {
redColor = random(0, 10) + lightLevel;
greenColor = random(0, 10) + lightLevel;
blueColor = random(0, 10) + lightLevel;
}
preLightLevel = lightLevel;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment