Code for first Object Project
// Adafruit NeoPixel - Version: Latest | |
#include <Adafruit_NeoPixel.h> | |
#ifdef __AVR__ | |
#include <avr/power.h> | |
#endif | |
//set out signal pin | |
#define PIN 9 | |
//Set up pixel strip | |
Adafruit_NeoPixel strip = Adafruit_NeoPixel(6, PIN, NEO_GRB + NEO_KHZ800); | |
//Create initial RGB Target Values | |
int targetR = random(1,255); | |
int targetG = random(1,255); | |
int targetB = random(1,255); | |
void setup() { | |
//start the strip | |
strip.begin(); | |
//initialize all pixels to 'off' | |
strip.show(); | |
//initialize serial comm -- for debug | |
Serial.begin(9600); | |
//Set Pinmodes | |
pinMode(3, OUTPUT); | |
pinMode(5, OUTPUT); | |
pinMode(6, OUTPUT); | |
} | |
int randRGB(){ | |
return random(1,255); | |
}; | |
void loop() { | |
//Read the position of the input | |
int redIn = analogRead(0)/4; | |
int greenIn = analogRead(1)/4; | |
int blueIn = analogRead(2)/4; | |
//Get the differences between target and actual RGB values | |
int redDif = redIn - targetR; | |
int greenDif = greenIn - targetG; | |
int blueDif = blueIn - targetB; | |
//Figure out if the input is close enough to the target. | |
if (abs(redDif) <= 40 && abs(greenDif) <= 40 && abs(blueDif) <= 40){ | |
targetR = randRGB(); | |
targetG = randRGB(); | |
targetB = randRGB(); | |
} | |
else{ | |
// Serial.println("R: "+String(redValue) + " G: "+ String(greenValue) + " B: "+String(blueValue)); | |
for(uint16_t i=0; i<strip.numPixels(); i++){ | |
strip.setPixelColor(i,targetR,targetG,targetB); | |
strip.show(); | |
} | |
//Update Input LED from sliders. | |
analogWrite(3,greenIn); | |
analogWrite(5,blueIn); | |
analogWrite(6,redIn); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment