Is it brocken?

Hello people,
I have no other experience of programming, but I excited with the capabilities of the Arduino UNO, so I decided to buy one. More specifically I bought a Genuino Starter Kit from Arduino.cc, and I started straight away with the projects book’s first and second project.

In the second project (spaceship interface), after I did all the whirring, and had written the code I noticed that something is going wrong. According to the code as you know when I type “digitalWrite(3, HIGH);”, the led that is connected to pin 3 should be ON, and when I type “digitalWrite(3, LOW);”, the led that is connected to pin 3 should be OFF, but the exact opposite is happening.

The board information is:
BN: Arduino/Genuino Uno
VID: 2341
PID: 0243
SN: 755333538373513071F0

And I use Arduino 1.8.2 to compile the code on Windows 10 PC.

Is there any way to fix this or any other potential issues?
Thankyou in advance.

This is the code:

const int ledred0 = 5;
const int ledred1 = 4;
const int ledgreen = 3;
const int button = 2;

int buttonstate = 0;

void setup()
{

pinMode(ledgreen, OUTPUT);
pinMode(ledred0, OUTPUT);
pinMode(ledred1, OUTPUT);
pinMode(button, INPUT);

}

void loop()
{

buttonstate = digitalRead(button);

if (buttonstate == LOW)
{
digitalWrite(ledred0, HIGH);
digitalWrite(ledred1, HIGH);
digitalWrite(ledgreen, LOW);
}
else
{
digitalWrite(ledred0, HIGH);
digitalWrite(ledred1, LOW);
digitalWrite(ledgreen, LOW);
delay(125);
digitalWrite(ledred0, LOW);
digitalWrite(ledred1, HIGH);
delay(125);
}
}

How is the LED wired? Arduino to LED anode, LED cathode (short pin, pin with flat spot on LED to a resistor, resistor to Gnd?

Or 5V to LED anode, LED cathode to resistor, resistor to Arduino pin?

(resistor and LED positions may be swapped in the component path)

No, it's not broken. You may have wired it wrong or the instructions may be wrong. You could easily change it to have a HIGH turn the LED on and vice versa but it's actually very common to wire things as active LOW. A trick I like to do so that it doesn't really matter, is easy to read the code, and easy to change by editing only a couple of lines of code is demonstrated by this modification of the Blink sketch:

const byte LEDonState = LOW;
const byte LEDoffState = HIGH;
const byte LEDpin = 3;
const unsigned int blinkInterval = 1000;

void setup() {
  pinMode(LEDpin, OUTPUT);
}

void loop() {
  digitalWrite(LEDpin, LEDonState);
  delay(blinkInterval);
  digitalWrite(LEDpin, LEDoffState);
  delay(blinkInterval);
}

I uploaded some pictures and the code for you to see
Short leg of the LED is connected to DIGITAL ~PWM and long leg to 5V through 220ohm resistor

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that 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. Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

When you attach and image it’s helpful to also embed it in the post following these instructions

That will allow people to more easily view the image.

Moschos:
Short leg of the LED is connected to DIGITAL ~PWM and long leg to 5V through 220ohm resistor

That’s the reason, If you look at the schematic you’ll see that it shows the short leg of the LED connected to ground through the resistor.