Error in simple code

Hi Mr,

i am learn arduino, but are hard.
I make an code to led POWER ON in 2 pin ( 7 and A5).

I want led On in moments separate, but have time, 2 leds are ON in some time, i not get think in error.

my code is it :

void setup()
{
pinMode(7, OUTPUT);
pinMode (A5, OUTPUT);
}

void loop()
{
digitalWrite(7,HIGH);
delay(1000);
digitalWrite(7,LOW);
delay(1000);
digitalWrite(A5,HIGH);
delay(1000);
digitalWrite(A5,LOW);
delay(1000);

}

.... video is it.

if i' am not wrong you just want led to blink and have a delay time right ?You can tried this

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(7, OUTPUT);
  pinMode(A5, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(7, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1500);                       // wait for a second
  digitalWrite(A5, LOW);    // turn the LED off by making the voltage LOW
  delay(1500);                       // wait for a second
  digitalWrite(A5,HIGH);
  delay(1500);
  digitalWrite(7, LOW);
}

or you can look this website : https://www.arduino.cc/en/tutorial/blink

A frequent misconception beginners have is thinking that HIGH always means on. In fact, it's more common for LOW to be the active state.

I find it very helpful to define some variables naming the states:

byte LEDonState = LOW;
byte LEDoffState = HIGH;

and then use those variables instead of HIGH and LOW throughout the rest of my code. If you do that, I think you'll be able to see the problem with your code.

I think that it's strange.
I can't find wrong points in your codes.
(but i'm a new arduino-er.)

Looking at the video, I'd say it's pretty clear that the LEDs are wired so that LOW is on (ie, other end of the LED-and-resistor is connected to Vcc, not Gnd.

This wiring scheme is actually more common than the opposite, and is generally better practice (The AVRs have symetric drive capabilities, ie, they drive HIGH and LOW equally well - but many other parts you'll encounter don't - some can only pull LOW, others have different drive strength for HIGH vs LOW)

Never could understand people's abhorrence to low side switching, seems all they can conceive of is hot wire to switch, switch to light bulb, light bulb to ground, anything else is alien and incomprehensible. :slight_smile:

all they can conceive of is hot wire to switch, switch to light bulb, light bulb to ground, anything else is alien and incomprehensible.

Anything else is dangerous, leaving "hot" levels on both sides of the light bulb .

pert:
A frequent misconception beginners have is thinking that HIGH always means on. In fact, it's more common for LOW to be the active state.

I find it very helpful to define some variables naming the states:

byte LEDonState = LOW;

byte LEDoffState = HIGH;



and then use those variables instead of HIGH and LOW throughout the rest of my code. If you do that, I think you'll be able to see the problem with your code.

send me pleasy complete code.

DrAzzy:
Looking at the video, I'd say it's pretty clear that the LEDs are wired so that LOW is on (ie, other end of the LED-and-resistor is connected to Vcc, not Gnd.

This wiring scheme is actually more common than the opposite, and is generally better practice (The AVRs have symetric drive capabilities, ie, they drive HIGH and LOW equally well - but many other parts you'll encounter don't - some can only pull LOW, others have different drive strength for HIGH vs LOW)

So, what solution ?

I not can change anything in board.
You can send me correct code ?

ederangelo:
send me pleasy complete code.

That's not how it works here. We want to help you learn, not do your project for you. If you want someone to do your project for you, there is a forum section specifically for offering paid work. If that's what you want, you can click the "Report to moderator" link and request nicely that this thread to be moved to the "Gigs and Collaborations" forum section.

...or you can do as I recommended and then post your updated code.

pert:
That's not how it works here. We want to help you learn, not do your project for you. If you want someone to do your project for you, there is a forum section specifically for offering paid work. If that's what you want, you can click the "Report to moderator" link and request nicely that this thread to be moved to the "Gigs and Collaborations" forum section.

...or you can do as I recommended and then post your updated code.

Of Course Mr... i know, but i with code in hand i will study... it not is an aplication, is only to learn.

xxxxxxxxxxxxxxxx

i am using code mr @Mrtian2 , but with modification, but led only bright by 0,000s ( word generic ) , it show with something inverter in code or in board ( how Pert speak before ).

Check code, and check movie.

void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(7, OUTPUT);
pinMode(A5, OUTPUT);
}

// the loop function runs over and over again forever
void loop()
{
digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1500); // wait for a second
digitalWrite(A5, LOW); // turn the LED off by making the voltage LOW
delay(1); // wait for a second
digitalWrite(A5,HIGH);
delay(1500);
digitalWrite(7, LOW);
delay(1);
}

movie

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar, then you can manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

ederangelo:
digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level)

Have you verified that comment is correct?

Have you verified that comment is correct?
[/quote]

I not know, i only copy code of friend before.... but not correct ?

Perform an experiment to find out.

pert:
Perform an experiment to find out.

code before are correct, all digits are correct, you see it movie ? https://youtu.be/tRrbGtZ3w7c

I've already explained the problem multiple times. I can't help you any further. Good luck.

I think they're trying to say that for one of the pins, low is on and high is off. Give this a shot and see if it works, let me know what happens if not. What kind of arduino do you have?

void setup()
{
  pinMode(7, OUTPUT);
  pinMode (A5, OUTPUT);
}

void loop()
{
  digitalWrite(7,HIGH);
  delay(1000);
  digitalWrite(7,LOW);
  delay(1000);
   digitalWrite(A5,LOW);
  delay(1000);
  digitalWrite(A5,HIGH);
  delay(1000);

}

There is a Portuguese forum here Português - Arduino Forum which you might find more useful.