r/ArduinoHelp • u/VinMega6468 • 15d ago
Why does this not work?
solved
when i click simulate nothing happens and the leds dont light up can anyone help
1
u/Terrible-Seat-7346
15d ago
•
Pin variables doesn’t have value
1
4
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 •
![]()
Actually it is good practice to give them names.
That said, I wouldn't count
digital_pin_7as 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
1
1
1
u/peno64 15d ago
LEDs turned around?