Pages: [1]   Go Down
Author Topic: Loop repeats, time counter does not increment, whats goin on?  (Read 1029 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 1
Posts: 34
Nub
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

my code:

#include <Time.h>
#include <TimeAlarms.h>
#include <IRremote.h>

int RECV_PIN = 9;
const int RELAY_0 = A0;
const int RELAY_1 = A1;
const int RELAY_2 = A2;
const int RELAY_3 = A3;
const int RELAY_4 = A4;
const int RELAY_5 = A5;
int sethour;
int setmin;
int setsec = 00;
int setday;
int setmonth;
int setyear = 11;

int count;

IRrecv irrecv(RECV_PIN);

decode_results results;

#define one 0x801
#define two 0x802
#define three 0x803
#define four 0x804
#define five 0x805
#define six 0x806
#define seven 0x807
#define eight 0x808
#define nine 0x809
#define zero 0x800


void setup()
{
  pinMode(RELAY_0, OUTPUT);
  pinMode(RELAY_1, OUTPUT);
  pinMode(RELAY_2, OUTPUT);
  pinMode(RELAY_3, OUTPUT);
  pinMode(RELAY_4, OUTPUT);
  pinMode(RELAY_5, OUTPUT);
  pinMode(13, OUTPUT);
  irrecv.enableIRIn();  // start the receiver
  Serial.begin(9600);   
 
 
}
int on = 0;
unsigned long last = millis();
boolean cycle = true;  //auto-cylce mode

/*
void MorningAlarm()
{
  Serial.println("Alarm: - turn lights off");   
}

void EveningAlarm()
{
  Serial.println("Alarm: - turn lights on");           
}

void RepeatTask()
{
  Serial.println("15 second timer");         
}

void OnceOnlyTask()
{
  Serial.println("This timer only triggers once"); 
}
*/
void  loop() {
 
  int buttonValue = digitalRead(RECV_PIN);
  while (irrecv.decode (&results)){
  Serial.println("Input the hour using the remote. (Military time 0-24) \n For example: Three am would be 0 followed by 3, 1 pm would be 1 followed by 3");
  Serial.println("\n");
      if (results.value == zero){
    sethour = 0;
    cycle = false;
  }
  else if (results.value == one){
    sethour = 1;
    cycle = false;
  }
   else if (results.value == two){
    sethour = 2;
    cycle = false;
  }
   else if (results.value == three){
    sethour = 3;
    cycle = false;
  }
   else if (results.value == four){
    sethour = 4;
    cycle = false;
  }
   else if (results.value == five){
    sethour = 5;
    cycle = false;
  }
   else if (results.value == six){
    sethour = 6;
    cycle = false;
  }
  irrecv.resume();

  Serial.println("Input the minute. \n For example 8 would be 0 followed by 8, 23 would be 2 followed by 3");
  Serial.println("\n");
  if (results.value == zero){
    setmin = 0;
    cycle = false;
  }
  else if (results.value == one){
    setmin = 1;
    cycle = false;
  }
   else if (results.value == two){
    setmin = 2;
    cycle = false;
  }
   else if (results.value == three){
    setmin = 3;
    cycle = false;
  }
   else if (results.value == four){
    setmin = 4;
    cycle = false;
  }
   else if (results.value == five){
    setmin = 5;
    cycle = false;
  }
   else if (results.value == six){
    setmin = 6;
    cycle = false;
   }
   irrecv.resume();
   Serial.println("Input the day using the same method as above.");
   Serial.println("\n");
    if (results.value == zero){
    setday = 0;
    cycle = false;
  }
  else if (results.value == one){
    setday = 1;
    cycle = false;
  }
   else if (results.value == two){
    setday = 2;
    cycle = false;
  }
   else if (results.value == three){
    setday = 3;
  }
   else if (results.value == four){
    setday = 4;
  }
   else if (results.value == five){
    setday = 5;
  }
   else if (results.value == six){
    setday = 6;
   }
   irrecv.resume();
   Serial.println("Input the month using the same method as above.");
   Serial.println("\n");
    if (results.value == zero){
    setmonth = 0;
  }
  else if (results.value == one){
    setmonth = 1;
  }
   else if (results.value == two){
    setmonth = 2;
  }
   else if (results.value == three){
    setmonth = 3;
  }
   else if (results.value == four){
    setmonth = 4;
  }
   else if (results.value == five){
    setmonth = 5;
  }
   else if (results.value == six){
    setmonth = 6;
   }
   irrecv.resume();
  }
 
 


 
  //setTime(sethour,setmin,setsec,setday,setmonth,setyear); // set time
/*
  Alarm.alarmRepeat(8,30,0, MorningAlarm);  // 8:30am every day
  Alarm.alarmRepeat(17,45,0,EveningAlarm);  // 5:45pm every day
 
  Alarm.timerRepeat(15, RepeatTask);            // timer for every 15 seconds   
  Alarm.timerOnce(10, OnceOnlyTask);            // called once after 10 seconds
*/

  digitalClockDisplay();
  Alarm.delay(1000); // wait one second between clock display
}

void digitalClockDisplay()
{
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.println();
}

void printDigits(int digits)
{
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}




on the serial monitor, everything repeats itself, when i push a button on the remote, the value is passed into the setTime function but does not start counting up.

i tried setting some logic flags but nothing worked.  smiley-mad

what is the problem with my code?
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 538
Posts: 27097
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Look at your void loop().
Looks to me like all it is set up to do is receive the time setting commands.
Where is the connection to this code to actually display the time?
Code:
void digitalClockDisplay()
{
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.println();
}

void printDigits(int digits)
{
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26312
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
Serial.println("Input the hour using the remote. (Military time 0-24) \n
I never knew the military managed to squeeze an extra hour into the day.
That's efficiency for you! smiley
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Newbie
*
Karma: 1
Posts: 34
Nub
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Haha  smiley-wink thanks for noticing my mistake with military time.

The display code is connected with the code but the problem im trying to deal with is programming the hour first, then the minute, then the day and finally the month.

The serial monitor keeps repeating:

Input the hour using the remote. (Military time 1-24)
 For example: Three am would be 0 followed by 3, 1 pm would be 1 followed by 3


Input the minute.
 For example 8 would be 0 followed by 8, 23 would be 2 followed by 3


Input the day using the same method as above.


Input the month using the same method as above.


0:00:00
Input the hour using the remote. (Military time 1-24)

what should i do so i can input variables one step at a time?
Logged

California
Offline Offline
Full Member
***
Karma: 0
Posts: 129
That's me, the boy with the broken halo.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
Serial.println("Input the hour using the remote. (Military time 0-24) \n
I never knew the military managed to squeeze an extra hour into the day.
That's efficiency for you! smiley

Hell yeah they do, I was in OT division, and that's what we put in every day... Over Time.
Logged

0
Offline Offline
Sr. Member
****
Karma: 4
Posts: 310
Posts: 40382
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

maybe like this, just going by my experience with the ir library.  http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1279084882

if (irrecv.decode(&results) ) {         //I used 'if' instead of 'while'
  if (hoursdone==0){     //haven't done hours yet
       if (results.value == zero){
           sethour = 0;
           cycle = false;
           hoursdone=1;
           //other if statements here
           }
    irrecv.resume(); // Receive the next value
  } else if (hoursdone==1){
   //do the minutes if hours have been done already
 irrecv.resume(); // Receive the next value
}

Logged

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

Well...

I am going to take a shot and say if you don't want something to loop, it shouldn't be in loop(). The whole setting-up section can go in... well, setup(). That may not be necessarily true, but I think it work inside setup().

Other than that, I have no idea what second(), hour(), and minute() do. Though I wonder why you have setTime() commented out?
Logged

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 217
Posts: 13718
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

for all those

if (results.value == zero){
    setday = 0;
    cycle = false;
  }
else if ...
else if (results.value == siz){
    setday = 0;
    cycle = false;
  }
I would use

setday = result.value & 0x00FF; 

much simpler. idem for setmonth etc.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

0
Offline Offline
Newbie
*
Karma: 1
Posts: 34
Nub
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

neither work in setup nor in loop, the if statements are completely skipped at first and the time is set to a defualt of 00:00:00.

once i press a button on the remote, the hours are programmed to that button but the same number is passed into the minutes and it does not start incrementing.
Logged

Pages: [1]   Go Up
Jump to: