Hello everyone, sorry for this topic but i can't get out of this.
#include <Servo.h>
Servo servo1;
Servo servo2;
int bottone = 2;
int mossasel = 0;
int testmove = 0;
void setup() {
servo1.attach(9);
servo2.attach(10);
pinMode (bottone, INPUT);
}
void loop() {
if (testmove != 0) {
mossasel = testmove;
}
if (digitalRead) (bottone == HIGH); {
if (mossasel > 2) {
mossasel = 0;
}
if (mossasel == 0) {
mossa1();
}
else if (mossasel == 1) {
mossa2();
}
if (testmove == 0) {
mossasel++;
}
else {
servo1.write (0);
servo2.write (0);
}
}
}
here's the problem, when i upload the cod on my arduino it keeps executing a random positioning with the first servo. Actually i think the problem is when i have to increase the variable for change the subroutine of the servos.
The code should work, when the switch is HIGH it has to do the first subroutine, then the servo will turn off the switch. Then when it comes the second input from the HIGH switch it has to do the second subroutine of movement... then restarts from 0.
Hope you guys can help me.
Yes i've posted the full code.
Everytime the switch is running high i have to do a different subroutine.
Feel free to tell me i'm a dumbass and to change all of my code!!
The project is a uselessbox, with the servo wich everytime it works is gonna pull LOW the switch.
Actually the problem is i can't increase the variable in function of the subroutine i'm running.
For ex:
I = 0 --> SUB1
I++
1 = 1 --> SUB2
...
...
I = 10 --> I = 0
then restart.
Everytime i have to I++ when the switch triggers from Low to High
Lots of issues have been identified in your code. You may, or may not, have fixed them, but changing the code on your computer does NOT change the code in this thread. There is a manual step required (of you).
even if i changed the code the problem it's still the same.
if you want you can modify the code up i've posted, or change it at all lol..
i'm sorry sigh..
just the part when i have to increase the variable..
if (selectedMove == 0) {
mossa1();
}
else if (selectedMove == 1) {
mossa1();
}
You've not met the || operator yet?
What do your Serial.print()s tell you is happening? Why don't you have any?
You are not using the internal pullup resistor, so you need an external pullup or pulldown resistor wired with the switch. Just how IS the switched wired.
The code does something. You expect it to do something. "It doesn't work" doesn't tell us squat.
no i didn't
that's my project for the exams high school.
I'm using a pulldown resistor for the switch, and i'm not using the serial print.. but i'm gonna try to see what the program is running.