Hi,
Need to loop cycle, for now its working only 1 time:
#include <Servo.h>
Servo myservo;
int val;
int Vah;
void setup()
{
Serial.begin(9600);
myservo.attach(2); //Pin where Servo motor signal is connected.
Vah = 0;
}
void loop()
{
val = analogRead(7); //Pin where LDR is connected.
Serial.println(val);
myservo.write(90);
if (val > 1000 && Vah == 0)
{
myservo.write(45);
Vah = 1;
delay(1000);
do
{
delay(2000);
val = analogRead(7);
Serial.println(val);
}
while (val > 1000);
}
if (val > 1000 && Vah == 1)
{
myservo.write(0);
Vah = 3;
delay(1000);
}
}
while (true) {...} - not working
for (; {...} - not working
SOLUTION ! :
Found Solution, it was very simple command, just add Vah = 0; after Vah=3;
Arduino nano was used
What is "cycle"?
artgeneralist:
Vah = 0;
It's already zero before the setup function executes.
horace
February 11, 2023, 11:48am
3
have a read of how-to-get-the-best-out-of-this-forum
in particular
what arduino are you using?
used code tages </> when uploading code
post a schematic or your wiring
upload a copy of the serial monitor text output
b707
February 11, 2023, 11:54am
4
Yes, because you wrote it such way that it runs only once.
Look to the code - first condition match only if Vah == 0
, then you change Vah to 1.
The second condition will run if Vah == 1
and then you change the variable to 3.
That's all. The Vah value never will 0 or 1 again and your loops never run.
gcjr
February 11, 2023, 11:59am
5
what are you trying to do?
val = analogRead(7);
can IO-pin 7 be used as analog input?
This wokwi-simulation makes visible what your code is doing
Run IoT and embedded projects in your browser: ESP32, Arduino, Pi Pico, and more. No installation required!
best regards Stefan
No, but pin A7 (aka 7) on a Nano or Mega can.
The OP didn't tell us which processor they're using.
Let's wait until we find out.
system
Closed
August 10, 2023, 7:33pm
8
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.