hello everyone,
i'm pretty new to arduino, and i've been working on a testing program which i just can't get to work. i've read a whole lotta references and forum posts but it seems i just cant get the code right. maybe anyone can help me get my thinking straight?
i connected a toggle switch to pin2, and i want to have the onboard led blink one way for 20 times then the other way for 20 times. if the switch is turned to off, i'll just have the led blink quickly.
its a test for a stepper motor driver that will have three different velocities (like the blinking), so instead of setting the coils, in this testing program i just set the led to blink.
here's the code:
int i;
const int inPin = 2;
const int ledPin = 13;
int buttonState = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(inPin, INPUT);
Serial.begin(9600);
}
void loop() {
buttonState = digitalRead(inPin);
Serial.println (buttonState);
if (buttonState == HIGH)
{
for (int i = 0; i < 20; i++);
{
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
Serial.println(i);
}
for (int i = 20; i>0; i--);
{
digitalWrite(13, HIGH);
delay(2000);
digitalWrite(13, LOW);
delay(200);
Serial.println(i);
}
}
else if (buttonState== LOW)
{
digitalWrite(13, HIGH);
delay(200);
digitalWrite(13, LOW);
delay(200);
}
}
any information highly appreciated : ) i'm pretty sure its something very simple that just hadn't crossed my mind...
thank you.