hi, please help T^T this time i was assigned to do some parts:
dc motor temperature controlled (i succeed)
potentiometer motor dc speed control (i succeed)
servo push button controlled, when push once it keeps rotating, when push once again it stops. (i failed)
I am using tinkercad to do this and i dont know why when I start the simulation the servo rotates 0-180 and 180-0 first then return back to normal, when button pushed it didnt do anything at all.
Pressing you button only changes the value of variable 'var'...
buttonState = digitalRead(button);
if (buttonState == LOW) {
var =90;
}
else
{
var = 0;
}
...as you don't use the variable 'var' anywhere else in your sketch, the above code is totally pointless.
You might want to look at:
File -> Examples -> 02.Digital -> Debounce
For an example which performs a toggle function. Then use the toggle state to control the motor speed.
pcbbc:
Pressing you button only changes the value of variable 'var'...
buttonState = digitalRead(button);
if (buttonState == LOW) {
var =90;
}
else
{
var = 0;
}
...as you don't use the variable 'var' anywhere else in your sketch, the above code is totally pointless.
You might want to look at:
File -> Examples -> 02.Digital -> Debounce
For an example which performs a toggle function. Then use the toggle state to control the motor speed.
pcbbc:
Pressing you button only changes the value of variable 'var'...
buttonState = digitalRead(button);
if (buttonState == LOW) {
var =90;
}
else
{
var = 0;
}
...as you don't use the variable 'var' anywhere else in your sketch, the above code is totally pointless.
You might want to look at:
File -> Examples -> 02.Digital -> Debounce
For an example which performs a toggle function. Then use the toggle state to control the motor speed.
hi, ive changed the code above, with for function, but it still didnt do anything, can u please help me check it out
Hi,
How have you got your button wired?
If it is between gnd and the input have you got a pullup resistor, if you haven't you can turn the internal controller pullup on instead.
If it is between 5V and the input then you will need to put a 10K resistor between the input pin and gnd.