int led= 30;
int led 2= 40;
void setup() {
pinMode(30, OUTPUT);
pinMode(40, OUTPUT);
}
void loop(){
digitalWrite(30,HIGH);
delay(5000);
digitalWrite(30,LOW);
delay(300);
digitalWrite(40, HIGH);
delay(600)
digitalWrite(30, LOW);
delay(400);
loop()
}
I am trying to initialize two LED'S on the same breadboard. Do I need to seperate the code for each LED and just delay them a certain time so both can blink or can I initialize two LED's in the same bracket. Thanks
Not sure what you asking but you need to post code in a code block as shown below. Also why are you calling loop() from your loop function?
int led= 30;
int led 2= 40;
void setup() {
pinMode(30, OUTPUT);
pinMode(40, OUTPUT);
}
void loop(){
digitalWrite(30,HIGH);
delay(5000);
digitalWrite(30,LOW);
delay(300);
digitalWrite(40, HIGH);
delay(600)
digitalWrite(30, LOW);
delay(400);
loop()
}
Pay attention to which pins you are writing to in the digitalWrite() statements.
Why bother giving pins meaningful names then not using them in pinMode() and digitalWrite() ?
Oh yeah, I forgot, I am a dummy. I was not using the pin name I was using the pin value so it got mixed up. Thanks
What about the reason for calling loop() in loop() ?
The compiler will do some checks on your code. For example, it sees a problem in Line 2:
sketch_feb29a:2:9: error: expected initializer before numeric constant
int led 2= 40;
^
Your name "led 2" can't have a space in it. Since an underscore ('_') is allowed in variable names it is not uncommon to use that when a space is desired in a name.
It has a problem with lines 16 and 19 because you forgot to put a ';' at the ends of two of your statements (lines 15 and 18).
After fixing those three problems the compiler can't help you any further. It only reports syntax errors (where the order of characters don't fit the language) and warnings about code that looks like it might be a mistake. That only catches a very small portion of possible mistakes.
One obvious mistake ia having loop() call loop(). This is known as a "recursive" call and should only be used in very rare circumstances. Yours is not one of those circumstances and the recursive call will eventually cause the Arduino to crash.
After fixing the known problems and using my preferred naming convention and formatting, the sketch looks like this:
const byte Led_DOPin = 30;
const byte Led2_DOPin= 40;
void setup()
{
pinMode(Led_DOPin, OUTPUT);
pinMode(Led2_DOPin, OUTPUT);
}
void loop()
{
digitalWrite(Led_DOPin,HIGH);
delay(5000);
digitalWrite(Led_DOPin,LOW);
delay(300);
digitalWrite(Led2_DOPin, HIGH);
delay(600);
digitalWrite(Led2_DOPin, LOW);
delay(400);
}
Note: The "_DOPin" is to remind me, and future readers, that the named constant is a Digital Output pin number.