Skip to content

Instantly share code, notes, and snippets.

@minamiss
Created May 3, 2019 17:07
Show Gist options
  • Save minamiss/022ac9abb65e148907cb545064b779ec to your computer and use it in GitHub Desktop.
Save minamiss/022ac9abb65e148907cb545064b779ec to your computer and use it in GitHub Desktop.
#include <Adafruit_NeoPixel.h>
int light =1; //LIGHTS
int pho =A1; //PHOTOCELL
int but = 0; //BUTTON
int last =0; //LAST STATE OF THE BUTTON
int butCount=0;//COUNT OF THE BUTTON
int count=0;
//int r=255;
//int g=255;
//int b=255;
//SETTING UP THE NEOPIXLES
Adafruit_NeoPixel strip = Adafruit_NeoPixel(16,light, NEO_GRB + NEO_KHZ800);
void setAllColor(int red,int green, int blue){
for(int i=0;i<16;i++){
strip.setPixelColor(i,red,green,blue);
strip.show();
delay(50);
}
}
void setup() {
//DECLARE STATES OF PINS
pinMode(light,OUTPUT);
pinMode(pho,INPUT_PULLUP);
pinMode(but,INPUT_PULLUP);
//BEGIN SERIAL COMMUNICATION FOR TESTING
//Serial.begin(9600);
//MORE NEOPIXEL SETTING UP
strip.begin();
}
void loop() {
//READ IN THE STATES OF THE BUTTON AND PHOTOCELL
int state = digitalRead(but);
int yay= 1023 - analogRead(pho);
int bright= map(yay, 200,800,0,200);
//PRINTING VALUES FOR TESTING
// Serial.println(state);
//Serial.println(bright);
//COUNTIN THE TIMES THE BUTTON HAS BEEN PRESSED WHEN DEPRESSED ONLY
if(state!=last&&state==HIGH){
if(state == 1){
butCount++;
}
}
last=state; //SAVING THE STATE
//Serial.println(butCount);
//USING THE BUTTON COUNTS TO MAKE DIFFRENT STATES
//THIS ONE KEEPS THE VALUES UNDER 4
if(butCount>4){
butCount=0;
count++;
}
//THE INITAL STATE IS ON
else if(butCount==0){
setAllColor(255,172,68);
strip.setBrightness(255);
}
//THIS ONE TURNS ON THE LIGHT WHEN DARK ONLY
else if(butCount==1){
if(bright>100){
strip.setBrightness(255);
setAllColor(255,172,68);
}
else{
setAllColor(0,0,0);
}
}
//NEXT STATE IS PHOTOCELL REACTIVE
else if(butCount==2){
strip.setBrightness(bright);
setAllColor(255,172,68);
}
//DISCO MODE
else if(butCount==3){
int r = random(0,255);
int g = random(0,255);
int b = random(0,255);
setAllColor(r,g,b);
strip.setBrightness(200);
strip.show();
}
//OFF
else if(butCount==4){
setAllColor(0,0,0);
strip.show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment