Author Topic: what am i doing wrong  (Read 870 times)

0 Members and 1 Guest are viewing this topic.

Offline m3vuvTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 1738
  • Country: gb
what am i doing wrong
« on: July 19, 2019, 09:55:37 am »
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 LED1
  delay(200);                  // wait for 200ms
  digitalWrite(LED2, HIGH);    // turn on LED2
  delay(200);                  // wait for 200ms       
  digitalWrite(LED3, HIGH);    // turn on LED3
  delay(200);                  // wait for 200ms
  digitalWrite(LED1, LOW);     // turn off LED1
  delay(300);                  // wait for 300ms
  digitalWrite(LED2, LOW);     // turn off LED2
  delay(300);                  // wait for 300ms
  digitalWrite(LED3, LOW);     // turn off LED3
  delay(300);                  //
} LED1 = 13


void loop() {
 

Offline m3vuvTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 1738
  • Country: gb
Re: what am i doing wrong
« Reply #1 on: July 19, 2019, 10:08:04 am »
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 LED1
  delay(200);                  // wait for 200ms
  digitalWrite(LED2, HIGH);    // turn on LED2
  delay(200);                  // wait for 200ms       
  digitalWrite(LED3, HIGH);    // turn on LED3
  delay(200);                  // wait for 200ms
  digitalWrite(LED1, LOW);     // turn off LED1
  delay(300);                  // wait for 300ms
  digitalWrite(LED2, LOW);     // turn off LED2
  delay(300);                  // wait for 300ms
  digitalWrite(LED3, LOW);     // turn off LED3
  delay(300);                  // wait for 300ms before running program all over again
}
 

Offline Dave

  • Super Contributor
  • ***
  • Posts: 1356
  • Country: si
  • I like to measure things.
Re: what am i doing wrong
« Reply #2 on: July 19, 2019, 10:14:07 am »
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().
<fellbuendel> it's arduino, you're not supposed to know anything about what you're doing
<fellbuendel> if you knew, you wouldn't be using it
 

Offline kosine

  • Regular Contributor
  • *
  • Posts: 159
  • Country: gb
Re: what am i doing wrong
« Reply #3 on: July 19, 2019, 10:18:44 am »
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.

 

Offline m3vuvTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 1738
  • Country: gb
Re: what am i doing wrong
« Reply #4 on: July 19, 2019, 10:32:57 am »
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
 

Offline kosine

  • Regular Contributor
  • *
  • Posts: 159
  • Country: gb
Re: what am i doing wrong
« Reply #5 on: July 19, 2019, 04:02:28 pm »
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 LED1
   delay(200);                  // wait for 200ms
   digitalWrite(LED2, HIGH);    // turn on LED2
   delay(200);                  // wait for 200ms       
   digitalWrite(LED3, HIGH);    // turn on LED3
   delay(200);                  // wait for 200ms
   digitalWrite(LED1, LOW);     // turn off LED1
   delay(300);                  // wait for 300ms
   digitalWrite(LED2, LOW);     // turn off LED2
   delay(300);                  // wait for 300ms
   digitalWrite(LED3, LOW);     // turn off LED3
   delay(300);                  // wait for 300ms before running program all over again
}


void loop() {
// nothing in here because we only want to run the code once
}
 

Offline m3vuvTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 1738
  • Country: gb
Re: what am i doing wrong
« Reply #6 on: July 19, 2019, 07:01:06 pm »
many thanks,maybe saved me hours of tearing my hair out,cheers and many thanks m3vuv.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf