Hi my name is Nick .I have written the following code in an attempt to turn a led on for varying lengths of time by changing the timer values but I have incurred a number of errors which I am unable to solve.The error messages are attached as a seperate doc . My concept for this code came from an iPad app and I thought it might work
any help would be greatly appreciated
cheers
Nick
int timer = 500; // put your setup code here, to run once:
int timer1 = 1000;
int timer2 = 2000;
int thisPin = 13;
void setup() {
// put your main code here, to run repeatedly:
for (int thisPin = 13; thisPin++;);
pinMode(thisPin,OUTPUT);
}
void loop() {
for (int thisPin = 13); thisPin++);
digitalWrite(thisPin, HIGH);
delay(timer);
digitalWrite (thisPin, LOW);
for (int thisPin = 13); thisPin++);
digitalWrite(thisPin, HIGH);
delay(timer1);
digitalWrite (thisPin, LOW);
for (int thisPin = 13); thisPin++);
digitalWrite(thisPin, HIGH);
delay(timer2);
digitalWrite thisPin, LOW);
}
}
Hi All sorry I havn't been on in a while. I have re-written the code , which now compiles and works. Thank you for you time and effort in replying. I have done a lot off looking around and I think I understand this code better than my first post Thank you again
//this code now works
int timer = 200; // create different timer values to use
int timer1 = 50;
int timer2 = 100;
int thisPin = 13;
void setup() {
// create a loop, to run repeatedly:
for (int thisPin = 13; thisPin++;);
pinMode(thisPin,OUTPUT);
}
void loop() {
for (int thisPin = 13; thisPin < 14; thisPin++); {
digitalWrite(thisPin, HIGH); //turn on
delay(timer); //pause/ wait
digitalWrite (thisPin, LOW); //turn off
delay(timer2);
digitalWrite(thisPin, HIGH);
delay(timer1);
digitalWrite (thisPin, LOW);
delay(timer1);
digitalWrite(thisPin, HIGH);
delay(timer2);
digitalWrite (thisPin, LOW);
delay(timer2);
}
}
Alright, first of all: in the setup you don't need to run the loop. In fact, since you don't have a stoping condition for it, this loop will run indefinitely and try to set all pins up to 2147483647 (the maximum number you can store in an integer).
Second: the for-loop in your loop() section does indeed have a stop-condition, but is completely unneccessary since you do nothing else in your main loop and even if, it yould only run once.
So, just take your two for-loops out, and your program should run as expected.
In fact, since you don't have a stoping condition for it, this loop will run indefinitely and try to set all pins up to 2147483647 (the maximum number you can store in an integer).
In practice the only code that will run because of the for loop is the semicolon following it. However, as thisPin will be out of scope after the for loop the code won't compile anyway.
2147483647 where on Earth did this number come from ?
Thank you for your replies . The code may not be well written but it does compile and does run at least on a Freetronics Eleven.
However I can see that is very messy and that it is possible to simplify it greatly and John's version is now running
cheers
Nick