Pages: [1]   Go Down
Author Topic: Time library help  (Read 430 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4084
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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();
}
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thx for the tip, and the quick response!

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

Pages: [1]   Go Up
Jump to: