Go Down

Topic: Time library help (Read 536 times) previous topic - next topic

Hey,

Need a little help. and am fairly new to Arduino. i am trying to use the Time library to make a simple sequence start at a predetermined time. in the full code i have found that all sides of an "if" statement are running . so i simplified to try and see what was happening. the below code is a test to see how the "if" statement is handling the  library.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#include <Time.h>

int led = 13;

void setup(){
  pinMode(led, OUTPUT); 
  Serial.begin(9600);
}

void loop(){

  if (second() <= 30){
    digitalWrite(led, HIGH);
    delay(100);
  }{
    digitalWrite(led, LOW);
    delay(100);
  }
  Serial.print(" ");
  Serial.print(second()); 
  Serial.println();
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
What happens is  i see my time increment in the serial monitor but my LED on Pin 13 is flashing to the delays. i was hopping to just turn the LED on when second() reset to 0 and off when second() reaches 30.

Any Help would be appreciated

Jack Christensen

Couple hints. (1) Do Tools > Auto Format, (2) Use code tags to post code.

Anyhoo, the two braces }{ alone on a line caught my eye. After auto format, it looks like below. Is maybe just an ELSE missing?

Code: [Select]
#include <Time.h>

int led = 13;

void setup(){
    pinMode(led, OUTPUT);
    Serial.begin(9600);
}

void loop(){

    if (second() <= 30){
        digitalWrite(led, HIGH);
        delay(100);
    }
    {
        digitalWrite(led, LOW);
        delay(100);
    }
    Serial.print(" ");
    Serial.print(second());
    Serial.println();
}

Thx for the tip, and the quick response!

... yep that would do it... thx

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy