0

Heres the code i've Wrote i feel like the issue lies in how ive used the if statement

int ledPinS = 13; //Classifies pin 13 as Connected to an LED
                //Flashes every second 
int ledPinM = 12; //Classifies pin 13 as Connected to an LED
                //Flashes every minuite

byte seconds;

byte minutes;

  void setup() { 
   pinMode(ledPinS, OUTPUT);
   digitalWrite(ledPinS, LOW);
   pinMode(ledPinM, OUTPUT);
   digitalWrite(ledPinM, LOW);
  }

    void loop() {
     while (seconds<=59){//flash every second and reset when Seconds =59
     delay(900);
     digitalWrite(ledPinS,HIGH);
     delay(100);
     digitalWrite(ledPinS,LOW);
     seconds++;
    }
 delay(200);   // flash ledPin M Once when Seconds = 59
 digitalWrite(ledPinM,HIGH);
 delay(100);
 digitalWrite(ledPinM,LOW);
 seconds = 0;
 minutes++; // add a minute
 if(minutes=5){ // if minutes = 5 flash ledPinM twice and reset   
          delay(200);
        digitalWrite(ledPinM,HIGH);
        delay(100);
        digitalWrite(ledPinM,LOW);
        delay(200);
        digitalWrite(ledPinM,HIGH);
        delay(100);
        digitalWrite(ledPinM,LOW);
        minutes = 0;
    }
}

Any Help would be Appreciated.

1
  • your code is very badly formatted ... proper indentation is very important, especially for a beginner programmer
    – jsotola
    Oct 3 at 3:07
0

Although your code is formatted horribly, it does appear to be mostly correct.

I also recommend making your pin numbers "const int". This tells the compiler that they cannot be changed. Otherwise you could change those values in your code accidentally.

You also have un-initialized variables. Best practice would be to declare and initialise them at the same time. E.g.

byte seconds = 0;

Props for adding comments, though. Well done there.

You need an extra equals sign in your if statement.

if (minutes = 5) {

should be

if (minutes == 5) {

Classic mistake. We've all done it. You are assigning the value of 5 to minutes instead of checking for equality. This will always return true.

1
  • Thanks so much I know I'm very new to C++ programming you've helped me a great deal thank you.
    – Ben Seaman
    Oct 3 at 14:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.