Skip to content

Instantly share code, notes, and snippets.


scealux/Project Code

Created May 20, 2019
What would you like to do?
Code for first Object Project
// Adafruit NeoPixel - Version: Latest
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
//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
//initialize all pixels to 'off';
//initialize serial comm -- for debug
//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();
// Serial.println("R: "+String(redValue) + " G: "+ String(greenValue) + " B: "+String(blueValue));
for(uint16_t i=0; i<strip.numPixels(); i++){
//Update Input LED from sliders.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.