Skip to content

Instantly share code, notes, and snippets.

@TamEg

TamEg/ps Secret

Created Jun 2, 2014
Embed
What would you like to do?
ps
/*P R A Y S T A T I O N*/
int led1=11;
int led2=10;
int led3=9;
int led4=6;
int button1=4;
int button2=2;
int buttonState1;
int buttonState2;
int pressCount;
int lastButtonState;
int brightness1;
int brightness2;
int brightness3;
int brightness4;
int fadeAmount1=1;
int fadeAmount2=1;
int fadeAmount3=1;
int fadeAmount4=1;
void setup(){
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(led4,OUTPUT);
pinMode(button1,INPUT);
pinMode(button2,INPUT);
Serial.begin(9600);
}
void loop(){
lastButtonState=buttonState1;
buttonState1=digitalRead(button1);
buttonState2=digitalRead(button2);
if(lastButtonState==LOW){
if(buttonState1==HIGH){
pressCount=pressCount+1;
}
}
if(buttonState1==HIGH && buttonState2==HIGH){
brightness1=brightness1+fadeAmount1;
analogWrite(led1,brightness1);
Serial.print(" B1: ");
Serial.println(brightness1);
if(brightness1==255){
fadeAmount1=0;}
if(brightness1>=33){
brightness2=brightness2+fadeAmount2;
analogWrite(led2,brightness2);
if(brightness2==255){
fadeAmount2=0;}
if(brightness1>=66){
brightness3=brightness3+fadeAmount3;
analogWrite(led3,brightness3);
if(brightness3==255){
fadeAmount3=0;}
if(brightness1>=99){
brightness4=brightness4+fadeAmount4;
analogWrite(led4,brightness4);
if(brightness4==255){
fadeAmount4=0;}
}
}
}
}
if(buttonState1==LOW && buttonState2==LOW){
if(brightness1==255 && brightness2==255 && brightness3==255 && brightness3==255){
brightness1=0;
digitalWrite(led1, LOW);
delay(66);
brightness2=0;
digitalWrite(led2, LOW);
delay(66);
brightness3=0;
digitalWrite(led3, LOW);
delay(66);
brightness4=0;
digitalWrite(led4, LOW);
}
}
if(buttonState1==LOW && buttonState2==LOW){
if(brightness1>0){
fadeAmount1=-1;
brightness1=brightness1+fadeAmount1;
analogWrite(led1,brightness1);
if(brightness1==0){
fadeAmount1=0;}
}
if(brightness2>0){
fadeAmount2=-1;
brightness2=brightness2+fadeAmount2;
analogWrite(led2,brightness2);
if(brightness2==0){
fadeAmount2=0;}
}
if(brightness3>0){
fadeAmount3=-1;
brightness3=brightness3+fadeAmount3;
analogWrite(led3,brightness3);
if(brightness3==0);{
fadeAmount3=0;}
}
if(brightness4>0){
fadeAmount4=-1;
brightness4=brightness4+fadeAmount4;
analogWrite(led4,brightness4);
if(brightness4==0){
fadeAmount4=0;}
}
}
// Serial.print(" pC: ");
// Serial.print(pressCount);
// Serial.print(" F1: ");
// Serial.print(fadeAmount1);
// Serial.print(" B1: ");
// Serial.print(brightness1);
// Serial.print(" F2: ");
// Serial.print(fadeAmount2);
// Serial.print(" B2: ");
// Serial.print(brightness2);
// Serial.print(" F3: ");
// Serial.print(fadeAmount3);
// Serial.print(" B3: ");
// Serial.print(brightness3);
// Serial.print(" F4: ");
// Serial.print(fadeAmount4);
// Serial.print(" B4: ");
// Serial.println(brightness4);
if(pressCount==2){
fadeAmount1=1;
fadeAmount2=1;
fadeAmount3=1;
fadeAmount4=1;
pressCount=1;
}
delay(66);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment