r/ArduinoHelp • • 15d 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

1

u/peno64 15d ago

LEDs turned around?

1

u/Terrible-Seat-7346 15d ago • Bravo

Pin variables doesn’t have value

1

u/VinMega6468 15d ago

thanks :D

4

u/Terrible-Seat-7346 15d ago

int DIGITAL_PIN_7 = 7;

int DIGITAL_PIN_6 = 6;

1

u/TrustednotVerified 15d 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 14d 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 13d ago

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

1

u/gm310509 13d ago edited 12d 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)

3

u/Carlss32 14d ago

The issue is that you declared none in the pins, after defining int pins.

It should be like this, assuming:

Digital_Pin = 7;

Another tips. The variable name should be aligned to what purpose it was. Example, the thing you want to create a simple correct or incorrect visual feedback.

Therefore, it should be like this:

int correctLed = 2;
int inCorrectLed = 3;

So, with this, it makes your pins more concise of what their purpose would be. Another thing, ensure that your resistor is not too high because this may dim the LED light. Calculating the correct resistor output is ideal, or stick with standard value (220 ohms)

1

u/imseakin 15d ago

Looks good to me. Maybe the apparent brightness of the LEDs in the simulator makes them look hard to see on the screen.

Remove the resistors from circuit. Just join pins directly to positive side of LEDs and try again.

1

u/SirLlama123 14d ago

happy cake day

1

u/PsychologicalTry3972 13d ago

Maybe, you need to set DIGITAL_PIN_n variables to actual pins?

0

u/fat_jak 12d ago

"Your C++ code has a bug. You need to assign the pin numbers: int DIGITAL_PIN_7 = 7;, int DIGITAL_PIN_6 = 6;, int DIGITAL_PIN_5 = 5;. Otherwise, they all default to pin 0."