I have project by Arduino mega which have 22 inputs and 22 outputs and buzzer reset and output reset pushbuttons , it have two status
- if the input is high(not continuous ) the output will on and the buzzer will be on, if output reset pushbutton is pressed the output will off , if buzzer reset pushbutton is pressed the buzzer will off.
- if the input is always high (continuous high signal on input ) the output will on and the buzzer will be on, in this case we will not reset the output even if the output reset pushbutton is pressed , and we will be able to reset the(turn off) buzzer by the buzzer reset pushbutton, and wait until input state to change to high again to repeat procedure
help me with editing my code
//int input[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,23,24}; //input pins (23 for reset ,24 for buzzer reset)
//int output[] = {26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 24, 34, 44, 45, 46, 47, 48,49}; //output pins (49 for buzzer)
int in1 = 2;
int in25 = 26;// for output reset
int in26 = 27;// for buzzer reset
///////////////
int out1 = 28 ;
int out24= 51 ;
int out25= 52 ; // output for buzzer
////////////////////////////////////
int buttonState1 = 0;
int buttonState24 = 0;
int buttonState25 = 0; //for reset
int buttonState26 = 0; //for buzzer reset
//unsigned long previousMillis = 0; // will store last time buzzer was updated
//const long interval = 10000; // interval at which to buzzer (milliseconds)
//int buzzerState = LOW; // buzzerState used to set the buzzer
void setup() {
pinMode(in1 , INPUT);
pinMode(in24 , INPUT);
pinMode(in25 , INPUT);
pinMode(in26 , INPUT);
///////////////////////////
pinMode(out1, OUTPUT);
pinMode(out2, OUTPUT);
pinMode(out24, OUTPUT);
pinMode(out25, OUTPUT);
digitalWrite(out25, LOW); // buzzer LOW
}
void loop() {
buttonState1 = digitalRead(in1);
if (buttonState1 == HIGH) {
digitalWrite(out1, LOW);
//digitalWrite(out25, LOW);
//delay(10000);
//digitalWrite(buzzer, LOW);
}
buttonState25 = digitalRead(in25); //read reset button state from input (25) pin 26
if (buttonState25 == HIGH )
{
digitalWrite(out1, HIGH); //reset out1
//digitalWrite(buzzer, LOW);
}
//else {
// buttonState26 = digitalRead(in26); //read the buzzer reset button state from input (26)pin 27
// if (buttonState26 == HIGH) {
// digitalWrite(out25, HIGH);
// }
//}
// while (digitalRead(input1) == HIGH);
//digitalWrite(buzzerrelay, LOW);
////////////////////////////////////////////////////////////
buttonState2 = digitalRead(in2);
if (buttonState2 == HIGH) {
digitalWrite(out2, LOW);
// digitalWrite(out25, LOW);
//delay(10000);
//digitalWrite(buzzer, LOW);
}
buttonState25 = digitalRead(in25); //read reset button state
if (buttonState25 == HIGH )
{
digitalWrite(out2, HIGH); //reset the output
//digitalWrite(buzzer, LOW);
}
// else {
// buttonState26 = digitalRead(in26); //read the buzzer reset button state
//if (buttonState26 == HIGH) {
// digitalWrite(out25, HIGH);
//}
// }
//////////////////////////////////////////////////////////////
// }
// }
}
in[1]
,in[2]
, etc. because you can use afor
loop to access the variables... you cannot use a loop forin1
,in2
, etc. so you are forced to repeat the same code multiple times