Trouble Passing Variable Alarm Time using Timealarm library


hello forum,

first post here of new fan of arduino world.  i've been working on project involves use of timealarm library , having problems getting work. using uno board, i've got potentiometer hooked pin a5 , buzzer on digital pin 10.

here's i've got:

code: [select]

#include <potentiometer.h>
#include <time.h>
#include <timealarms.h>
potentiometer potentiometer = potentiometer(a5);
int alarm1hrs;
int alarm1mins;

void setup()
  {
  serial.begin(9600);
  potentiometer.setsectors(3);
  settime(7,28,0,1,1,2013);
 
  alarm.alarmrepeat(alarm1hrs,alarm1mins,0, morningalarm);  //this doesn't work
  alarm.alarmrepeat(12,30,0, afternoonalarm);  //these work
  alarm.alarmrepeat(19,30,0, eveningalarm);
  }

void loop() {

  int potread = potentiometer.getsector();
  serial.println(potread);
  alarm.delay(10);
  serial.println(alarm1hrs);
  delay(500);
  serial.println(alarm1mins);
 
switch(potread){
    case 0:{
      //do something
    }
    break;
   
    case 1:{
      //set alarm1hrs , alarm1min variables
      alarm1hrs = 7;
      alarm1mins = 29;
    }
    break;
   
    case 2:{
      //do else, etc.
    }
    break;
  }
}
void morningalarm()
  {
    beep(200);
    serial.print("hello morning!");
  }

void afternoonalarm()
  {
    beep(200);
    serial.print("hello afternoon!");
  }
void eveningalarm()
  {
   beep(200);
   serial.print("hello evening!");
  }

void beep(unsigned char delayms){
  analogwrite(10, 20);      // value can used except 0 , 255
  delay(delayms);          // wait delayms ms
  analogwrite(10, 0);       // 0 turns off
  delay(delayms);          // wait delayms ms   
  } 


the hard coded alarm times work fine, times defined variables in switch statement don't seem passing alarmrepeat handler.   i have tested potentiometer in each position, no avail.

is possible this class?  i'm not super great @ c, when @ class, looks defined constants.

any appreciated.  conceptual issue me, once solved, can build out how use hardware assign variables.

code: [select]
  serial.println(alarm1hrs);
  delay(500);
  serial.println(alarm1mins);
 
switch(potread){
    case 0:{
      //do something
    }
    break;
   
    case 1:{
      //set alarm1hrs , alarm1min variables
      alarm1hrs = 7;
      alarm1mins = 29;
    }
    break;
   
    case 2:{
      //do else, etc.
    }
    break;
  }

printing, setting, variables putting card before horse. haven't learned thing.

only 1 pot setting anything, , nothing undoes does, so, once has been done, never gets undone.

where use values? call alarmrepeat() not bind variables. values passed,by value, once function.


Arduino Forum > Using Arduino > Programming Questions > Trouble Passing Variable Alarm Time using Timealarm library


arduino

Comments

Popular posts from this blog

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

How to format a Get Request

avrdude: verification error, first mismatch at byte 0x0000 0x0c != 0x62