Go Down

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

drewgibson0096

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();
}
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

drewgibson0096

Thx for the tip, and the quick response!

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

Go Up