The laser will not turn off I had it now It is gone. It works but I have absolutely no idea what I am doing. Cobbled together Code so far:
unsigned long buttonState = 0;
int funcState=0;
int ledRED = 13; //the pin we connect the led
int ledRED2 = 12; //the pin we connect the led
int ledORANGE = 11; //the pin we connect the led
int Button = 6; //the pin where we connect the button
int LASER = 7; //the pin we connect the laser
int speaker = 8; //the pin we connect the speaker
enum fcnMode {
OFF,
LASER1,
LED1,
LED2,
LED3,
FADE1,
ALL,
BLINK,
NBSTATE
}; // OFF = 0 and NBSTATE=7
void buttonPressed() {
buttonState = pulseIn(Button,HIGH,1000000);
if (buttonState > 50){
funcState += 1;
Serial.print("Button state n: ");
Serial.println(funcState);
}
switch(funcState){
case OFF:
break;
case LASER1:
break;
case LED1:
break;
case LED2:
break;
case LED3:
break;
case FADE1:
digitalWrite(ledRED2,HIGH);
digitalWrite(ledORANGE,LOW);
break;
case ALL:
break;
case BLINK:
digitalWrite(ledRED2,LOW);
break;
}
funcState=funcState; buttonState;
}
void setup() {
pinMode(ledRED, OUTPUT);
pinMode(ledRED2, OUTPUT);
pinMode(ledORANGE, OUTPUT);
pinMode(Button, INPUT_PULLUP); //set the button pin as INPUT
pinMode(LASER, OUTPUT); //set the LASER pin as OUTPUT
pinMode (speaker, OUTPUT); //set the speaker pin as OUTPUT
}
void loop() {
int stateButton = digitalRead(Button); //read the state of the button
if(stateButton == 1) { //if pressed
digitalWrite(LASER, LOW); //write 1 or HIGH to LASER pin
delay(500);
} else { //if not pressed
digitalWrite(LASER, HIGH); //write 0 or low to LASER pin
delay(500);
analogWrite (speaker, 255);
delay (500);
analogWrite (speaker, 0);
delay (10);
int brightness = 0;
int fadeAmount = 5;
for (brightness=0;brightness<=255;brightness+=fadeAmount){
analogWrite(ledRED, brightness);
delay(5000);
for (brightness=100;brightness<=555;brightness+=fadeAmount){
analogWrite(ledRED2, brightness);
delay(5000);
for (brightness=0;brightness<=155;brightness+=fadeAmount){
analogWrite(ledORANGE, brightness);
delay(5000);
}
int stateButton = digitalRead(Button); //read the state of the button
if(stateButton == 1) { //if pressed
digitalWrite(ledRED, HIGH);
delay(2000);
} else { //if not pressed
digitalWrite(ledRED, LOW);
delay(2000);
int stateButton = digitalRead(Button); //read the state of the button
if(stateButton == 1) { //if pressed
digitalWrite(ledRED2, HIGH);
delay(2000);
} else { //if not pressed
digitalWrite(ledRED2, LOW);
delay(2000);
int stateButton = digitalRead(Button); //read the state of the button
if(stateButton == 1) { //if pressed
digitalWrite(ledORANGE, HIGH);
delay(2000);
} else { //if not pressed
digitalWrite(ledORANGE, LOW);
delay(2000);
}
}
}
}
}
}
}