I'm fairly new to Arduino, but I'm slowly figuring it out.
I have three different "Statuses", where it tells a servo to do something different at each status. I'm testing this with LED's right now.
My goal is that when I press my button, I want it to add one to the "Status Level", which would run that if statement, then when I hit it again, it would run the next status level and so on.
The problem is that when I connect my leds, and i press the button, it goes through status one (and runs it, flashes the first LED), and it continues to Status two(Where the second LED stays lit). How do I fix this. I've spend some time searching and googling but I can't seem to figure it out.
Below is a copy of the code I'm running. It's kind of messy and in the first stages.
Thanks,
David
/*General Info
Servo x is set to pin 5
Button is set to pin 2
*/
#include <Servo.h>
/*Status' --------------------------------------------------------------------
0. reset/default position
- move right/left
- Pull arm back
- Release throw
- Reset status
*/
//declaring variables----------------------------------------------------------
Servo servox;
int Status = 0;
int degreex = 90 ;
int button = 2 ;
int servo = 5;
int pressed = 0;
//Start of Setup ---------------------------------------------------------------
void setup() {
pinMode(13, OUTPUT);//red light
pinMode(12, OUTPUT);
//attaches hardware
servox.attach(5);
pinMode(button, INPUT); //states that the button is an input
}
void loop () {
pressed = digitalRead(button); //Links status to button
if(pressed == HIGH){
Status = Status + 1 ;
if(Status == 1) {
digitalWrite(13, HIGH);
}
if(Status == 2) {
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
}
}