Blinking LED. What is wrong.

Hi
I modified blinking LED program to turn it ON for 1 sec, after that the LED should be OFF,.
The LED is all the time ON.
What is wrong ?

// the setup function runs once when you press reset or power the board

const int ResetPin = PA7;
void setup() {
  // initialize digital pin PB1 as an output.
  pinMode(PB1, OUTPUT);
  pinMode(ResetPin, INPUT_PULLDOWN);
}

// the loop function runs over and over again forever
void loop() {
  /*
   digitalWrite(PB1, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(PB1, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second

*/
if (ResetPin, HIGH)
{
  digitalWrite(PB1, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);
}
else
{
  digitalWrite(PB1, LOW);
}
}

  if (ResetPin, HIGH)What ?

void setup() {
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW) ;
}

void loop() {}

when I press the button attached to PA7 connected to Vcc

The IDE is packed with working programming examples.
Please work through some of them.

Lets consider this:

button is attached to pin 2
led is on pin 13

const byte buttonPin = 2;

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

void loop() {
  digitalWrite(BUILTIN_LED, HIGH);
  if (buttonPin == HIGH) {
    digitalWrite(BUILTIN_LED, LOW);
  }
  delay(1000);
  digitalWrite(BUILTIN_LED, LOW);
  delay(1000);
}

if (buttonPin == HIGH)Exactly the opposite of @Ted's solution :smiley:

Just from there I took a blinking LED program that works.
Something is wrong with the "if" function

ted:
Something is wrong with the "if" function

Please, be serious.

digitalread()

if (digitalRead(buttonPin) == HIGH) {

:o

Something is wrong with the "if" function

Nothing wrong with the "if function" but plenty wrong with how you are trying to use it.

Unsigned_Arduino:
if (digitalRead(buttonPin) == HIGH) {

:o

Unsigned_Arduino:
if (digitalRead(buttonPin) == HIGH) {

:o

Thanks is working.

Just wondering, what is the PA7 const for? I don't see anything declared as PB1 either, hence Jr. member.

Unsigned_Arduino:
Just wondering, what is the PA7 const for? I don't see anything declared as PB1 either, hence Jr. member.

Without it I have error:

exit status 1
'buttonPin' was not declared in this scope

I also just noticed that you commented out the blinking part of your first program:

/*
   digitalWrite(PB1, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(PB1, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second

*/

Oh.

Thanks anyway. :slight_smile:

I'm surprised no-one commented on the pulldown.

Unsigned_Arduino:
Just wondering, what is the PA7 const for? I don't see anything declared as PB1 either, hence Jr. member.

Read the datasheet of a microcontroller. The pins are grouped in ports, that is what the P stands for. Next a microcontroller usually has a few ports; those are 'numbered' A, B etc. And lastly within the group, they have a number (e.g. 7).

What ted did not mention is the board he's using. And that's very likely not an AVR based board; the reason for that conclusion is that his code uses INPUT_PULLDOWN.

In an AVR based Arduino, PB1 simply translates to 1 (the second pin on port B; remember counting from 0) as does e.g. PD1; PA7 does not exist on an Uno but does exist in a Mega.

I have no idea what PB1 and PA7 translate to on ted's board.

The pin names have nothing to do with functionality of this program, they are for STM32.
Naw you learn that the difference between AVR and ARM some time is just in the names of the pins. LOL