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

Show parent comment

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 • Bravo

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.

0

u/JoTheScienceBro 20d ago

You talk a lot about best practice for a child's toy.

1

u/gm310509 19d ago edited 18d ago

First off, it isn't a child's toy.

An Arduino is a development board for a specific MCU. Just like all of the others (edit: i.e. dev boards from other vendors).

The fact that it is targeted at beginners, doesn't mean that it is a child's toy.

Indeed many of the MCUs they use are certified to automotive and military standards. The manufacturer won't do that for a child's toy. Not to mention that some models are based upon Arm Cortex MCUs.

Lastly, as something that is targeted at beginners it is best to mention best practices earlier rather than later.

This is especially true for when people like you who make the "child's toy" claim also criticise Arduino for teaching bad practices (which I do not believe that they do - beyond keeping it simple for those early getting started steps)