what am i doing wrong - Page 1
Forum section: electronics / projects

author: m3vuv
author_rank: Super Contributor
timestamp: July 19, 2019, 09:55:37 am
content: Hi all im trying to switch 3 leds on in sequence but have it just do it once untill i reset the arduino,it gives errors when trying to compile,any ideas what im doing wrong and how to fix it?,im using an arduino uno,cheersd Paul m3vuv.int;int LED2 = 12;int LED3 = 11;void setup() {pinMode(LED1, OUTPUT);pinMode(LED2, OUTPUT);pinMode(LED3, OUTPUT);}digitalWrite(LED1, HIGH); // turn on LED1delay(200); // wait for 200msdigitalWrite(LED2, HIGH); // turn on LED2delay(200); // wait for 200msdigitalWrite(LED3, HIGH); // turn on LED3delay(200); // wait for 200msdigitalWrite(LED1, LOW); // turn off LED1delay(300); // wait for 300msdigitalWrite(LED2, LOW); // turn off LED2delay(300); // wait for 300msdigitalWrite(LED3, LOW); // turn off LED3delay(300); //} LED1 = 13void loop() {

author: m3vuv
author_rank: Super Contributor
timestamp: July 19, 2019, 10:08:04 am
content: sorry got it wrong,heres the original sketch,need it just to run 1 time until the uno is reset,any ideas?/* A simple program to sequentially turn on and turn off 3 LEDs */int LED1 = 13;int LED2 = 12;int LED3 = 11;void setup() {pinMode(LED1, OUTPUT);pinMode(LED2, OUTPUT);pinMode(LED3, OUTPUT);}void loop() {digitalWrite(LED1, HIGH); // turn on LED1delay(200); // wait for 200msdigitalWrite(LED2, HIGH); // turn on LED2delay(200); // wait for 200msdigitalWrite(LED3, HIGH); // turn on LED3delay(200); // wait for 200msdigitalWrite(LED1, LOW); // turn off LED1delay(300); // wait for 300msdigitalWrite(LED2, LOW); // turn off LED2delay(300); // wait for 300msdigitalWrite(LED3, LOW); // turn off LED3delay(300); // wait for 300ms before running program all over again}

author: Dave
author_rank: Super Contributor
timestamp: July 19, 2019, 10:14:07 am
content: Either move the whole code from loop() to the bottom of setup(), or put a while(1); to the bottom of the code inside loop().

author: kosine
author_rank: Regular Contributor
timestamp: July 19, 2019, 10:18:44 am
content: Your sketch compiles fine, so if there's a problem uploading it's likely with the board setup. Could be the USB drivers, wrong serial port or wrong board selected.Try verifying the sketch before uploading it to make sure the code is OK.

author: m3vuv
author_rank: Super Contributor
timestamp: July 19, 2019, 10:32:57 am
content: is there any way you could do it for me,i just seem to screw it up and then it wont compile,maybe if you can edit it i can cut and paste it ?cheers Paul m3vuv

author: kosine
author_rank: Regular Contributor
timestamp: July 19, 2019, 04:02:28 pm
content: In case you're tearing your hair out (we've all been there!), the necessary code is below.I'd suggest copying this into the Arduino IDE and hit the "verify" button (the first one with the tick). That'll compile the code but without uploading anything. It should work with no errors, and you don't even need a board plugged in to do this, so maybe unplug the Arduino for good measure.If do you still get errors, then there's something wrong with your installation. Maybe try re-installing or download a fresh version, or even switch computer if you have that option.Another thing you can try is "verifying/compiling" the BareMinimum sketch in file > examples > 01 basics. Again, there should be no compile errors (because there's no code to go wrong). Once you've confirmed that verfiy works, plug in the Arduino and try to upload (the second button with the arrow).If you run into problems at this stage then there's something wrong with either your board, your cable or your setup. Try a different board if you have one, make sure you've selected the correct board in the first place, try different USB ports, and also try different USB cables. These are often an issue because some are just charger cables and don't carry data./* A simple program to sequentially turn on and turn off 3 LEDs */int LED1 = 13;int LED2 = 12;int LED3 = 11;void setup() {pinMode(LED1, OUTPUT);pinMode(LED2, OUTPUT);pinMode(LED3, OUTPUT);digitalWrite(LED1, HIGH); // turn on LED1delay(200); // wait for 200msdigitalWrite(LED2, HIGH); // turn on LED2delay(200); // wait for 200msdigitalWrite(LED3, HIGH); // turn on LED3delay(200); // wait for 200msdigitalWrite(LED1, LOW); // turn off LED1delay(300); // wait for 300msdigitalWrite(LED2, LOW); // turn off LED2delay(300); // wait for 300msdigitalWrite(LED3, LOW); // turn off LED3delay(300); // wait for 300ms before running program all over again}void loop() {// nothing in here because we only want to run the code once}

author: m3vuv
author_rank: Super Contributor
timestamp: July 19, 2019, 07:01:06 pm
content: many thanks,maybe saved me hours of tearing my hair out,cheers and many thanks m3vuv.