Hello, my question serious, the programming is fine?, it says that it is deactivated by pressing buttons 1 and 3, but it is not deactivated and already check that the buttons are fine. Thank you!
const int buttonpin1=2; //combination of button
const int buttonpin2=4; //combination of button
const int buttonpin3=7; //combination of button
const int led_pin9=9;
const int led_pin10=10;
const int led_pin11=11;
int leds[]={9,10,11}; //arrangement for the LEDs to light up
int tiempo=1000;
const int buttonpin8=8; //pin to activate alarm ,,, leds
void setup()
{
pinMode(buttonpin1,INPUT);
pinMode(buttonpin2,INPUT);
pinMode(buttonpin3,INPUT);
pinMode(buttonpin8,INPUT);
pinMode(led_pin9,OUTPUT);
pinMode(led_pin10,OUTPUT);
pinMode(led_pin11,OUTPUT);
}
void loop()
{
int buttonstate=digitalRead(buttonpin8);
if(buttonstate==HIGH){
for(int contadorleds=0;contadorleds<3;contadorleds++)
{
for (int contadorcolor=0;contadorcolor<=255;contadorcolor++) //cycle that allows us to turn on three LEDs +++++
{
analogWrite(leds[contadorleds],contadorcolor);
}
delay(tiempo);
//desactivar();
}
desactivar();
}
}
void desactivar()
{
if((digitalRead(buttonpin1)==1)&&(digitalRead(buttonpin2)==0)&&(digitalRead(buttonpin3)==1)) //if the combination is going to turn on the focus
{
digitalWrite(leds[9,10,11],LOW); // the alarm goes off
}
else
{
Serial.println("Incorrect code"); //print the value of the variable in the arduino console with wrong code
}
}
By the way, the Arduino IDE should have given you warnings like
...\sketch_sep29a.ino:45:26: warning: left operand of comma operator has no effect [-Wunused-value]
digitalWrite(leds[9, 10, 11], LOW); // the alarm goes off
^
...\sketch_sep29a.ino:45:30: warning: right operand of comma operator has no effect [-Wunused-value]
digitalWrite(leds[9, 10, 11], LOW); // the alarm goes off
but you might have had to look closely to see them. This is poor but valid C/C++ code that results in
digitalWrite(leds[11], LOW); // the alarm goes off
not
fine
it wanders
all
over
the
screen
and has obvious programming errors.
Can you please fix the formatting to make it something that we can read? Making it harder to help you is a good way to severely limit the amount of help you get.
Also note that during that long double for loop, none of your other code is running so you may see issues with this being unresponsive. Why use for loops there when the loop function already loops?