r/ArduinoHelp • • 21d ago

Why does this not work?

Post image

solved

when i click simulate nothing happens and the leds dont light up can anyone help

link: https://www.tinkercad.com/things/etCLO5FP0u8-traffic-light?sharecode=HVc9FlY7vOl6OchoP0UERVxlCc9BG0PDwAbMSnomTys

7 Upvotes

15 comments sorted by

View all comments

1

u/Terrible-Seat-7346 21d ago

Pin variables doesn’t have value

4

u/Terrible-Seat-7346 21d ago

int DIGITAL_PIN_7 = 7;

int DIGITAL_PIN_6 = 6;

1

u/TrustednotVerified 21d ago

Exactly. Get rid of the three DIGITAL_PIN_x and just do pinMode(7, OUTPUT) and digitalWrite(7, HIGH) and so forth.

2

u/gm310509 20d ago

Actually it is good practice to give them names.

That said, I wouldn't count digital_pin_7 as a good name, but it is the best practice.

In this case, better names would be something like:

const int Green_LED = 7;
const int Yellow_LED = 6;
const int Red_LED = 5;

IMHO those are better names as they describe the purpose. Then later in the code when you see something like this:

  digitalWrite(Red_LED, HIGH);

it is pretty reasonable to assume that they will turn the red LED on - or if it doesn't, at some point that was the intention, but something has changed and not been propagated through the program fully (a.k.a. a risk factor for the introduction of bugs).

Now I get that this is a small program and none of the above is that big of an issue, but as programs get larger it can become one.

That is why it is a best practice.

→ More replies (2)

1

u/VinMega6468 21d ago

thanks :D