I have the arduino being activated in a certain pin "trigger"
and then it activates a pin if "trigger" is HIGH
I'll put here a part of the code:
void loop(){
digitalWrite(x, HIGH); //set pin_number X to HIGH
delay(time_delay);
digitalWrite(x, LOW); //set pin_number X to LOW
delay(time_delay);
}
My question: when I run the arduino, it outputs several times to HIGH in "pin_number X" because it is on "void loop" function
but I want it to output only once, and then put that pin to LOW forever (until I reset it again)
I tried to put that code on the "void setup", but like that it doesn't output correctly (or doesn't even output anything)
Thank you
I would add a counter variable. Something like this (completely untested). The variable count will only eqaul zero once.
void setup(){
int count =0;
}
void loop(){
if (count==0)
{
digitalWrite(x, HIGH); //set pin_number X to HIGH
delay(time_delay);
count=1;
}
digitalWrite(x, LOW); //set pin_number X to LOW
delay(time_delay);
}
I would add a counter variable. Something like this (completely untested).
Good thing you stated that. Creating the variable in setup() and trying to access it in loop() is doomed to failure. As a global, it would work. As a static variable, created in loop(), it would work. As written, it will not.