allarm timer arduino + set buttons lcd


hi guys made draft of code that's going set time , date alarm of arduino directly buttons. below place sketch if give @ beginner again , surely there errorini.
thanks in advance

code: [select]
#include <wire.h>
#include <rtclib.h>
#include <liquidcrystal.h>


#define relay_pin 2                   // pin definitions

#define backlight 2
#define contrast  3

#define set       a0
#define piu       a1
#define meno      a2

#define state_off  0                  //fsm states
#define state_on   1                  //fsm states
int fsm_state;

char buffer[10];
unsigned long time=0;
unsigned long timeset=0;
int  setmodetime=3000;

rtc_ds1307 rtc;
liquidcrystal lcd(12, 11, 5, 4, 3, 2);

void setup () {
    pinmode( backlight, output );
    pinmode( contrast, output );
   
    digitalwrite( backlight, high );
    analogwrite( contrast, 40 );
   
     pinmode(relay_pin, output);
     digitalwrite(relay_pin, low);
     
    fsm_state = state_off;
   
    wire.begin();
    rtc.begin();
    lcd.begin(16, 2);

    if (! rtc.isrunning()) {
      serial.println("rtc not running!");
      rtc.adjust(datetime(__date__, __time__));
    }

    pinmode( set, input );
    pinmode( piu, input );
    pinmode( meno, input );
}

void loop () {

    if ( analogread( set ) < 1000) { time = millis(); }

    datetime = rtc.now();
    int nowhourminute = now.hour() * 100 + now.minute();


    sprintf(buffer,  "%02d/%02d/%d", now.day(), now.month(), now.year());
    lcd.setcursor(0,0);
    lcd.print( buffer );

    char buffer[10] = ""; 
    sprintf(buffer,  "%02d:%02d:%02d", now.hour(), now.minute(), now.second());
    lcd.setcursor(0,1);
    lcd.print( buffer );
   
     char buffer_allarm[10] = ""; 
    sprintf(buffer,  "%02d:%02d:%02d", now.hour(), now.minute(), now.second());
    lcd.setcursor(0,3);
    lcd.print( buffer_allarm );

    if (time > 0 && setmodetime < (millis() - time) ) { setmode( ); }

    delay(1000);
}

void setmode( datetime ) {
    boolean setmode = true;
    int setmodelevel = 0;

    int _day = now.day();
    int _month = now.month();
    int _year = now.year();
    int _hour = now.hour();
    int _min = now.minute();
    int _sec = now.second();
    int _hourallarm = now.hour();
    int _minuteallarm = now.minute();
    int _secallarm = now.second();
   
    lcd.clear();
    lcd.setcursor(0,0);
    sprintf(buffer,  "%s: %02d", "giorno", _day);
    delay( 1000 );
    timeset = millis();

    while ( setmode ) {
      if ( analogread(set) > 1000 || analogread(piu) > 1000 || analogread(meno) > 1000 ) { timeset = millis(); }

      lcd.setcursor(0,0);

      // set day
      if ( setmodelevel == 0 ) {
        if ( analogread(piu) > 1000 && _day < 31) { _day++; }
        if ( analogread(meno) > 1000 && _day > 1) { _day--; }

        sprintf(buffer,  "%s: %02d", "giorno", _day);
      }
      // set month
      if ( setmodelevel == 1 ) {
        if ( analogread(piu) > 1000 && _month < 12) { _month++; }
        if ( analogread(meno) > 1000 && _month > 1) { _month--; }

        sprintf(buffer,  "%s: %02d", "mese", _month);
      }
      // set year
      if ( setmodelevel == 2 ) {
        if ( analogread(piu) > 1000 && _year < 9999) { _year++; }
        if ( analogread(meno) > 1000 && _year > 1900) { _year--; }

        sprintf(buffer,  "%s: %02d", "anno", _year);
      }
      // set hour
      if ( setmodelevel == 3 ) {
        if ( analogread(piu) > 1000 && _hour < 24) { _hour++; }
        if ( analogread(meno) > 1000 && _hour > 1) { _hour--; }

        sprintf(buffer,  "%s: %02d", "ora", _hour);
      }
      // set minute
      if ( setmodelevel == 4 ) {
        if ( analogread(piu) > 1000 && _min < 60) { _min++; }
        if ( analogread(meno) > 1000 && _min > 1) { _min--; }

        sprintf(buffer,  "%s: %02d", "minuti", _min);
      }
      // set second
      if ( setmodelevel == 5 ) {
        if ( analogread(piu) > 1000 && _sec < 60) { _sec++; }
        if ( analogread(meno) > 1000 && _sec > 0) { _sec--; }

        sprintf(buffer,  "%s: %02d", "secondi", _sec);
      }
       // set hour
      if ( setmodelevel == 6 ) {
        if ( analogread(piu) > 1000 && _hour < 24) { _hour++; }
        if ( analogread(meno) > 1000 && _hour > 1) { _hour--; }

        sprintf(buffer,  "%s: %02d", "ora", _hourallarm);
      }
      // set minute
      if ( setmodelevel == 7 ) {
        if ( analogread(piu) > 1000 && _min < 60) { _min++; }
        if ( analogread(meno) > 1000 && _min > 1) { _min--; }

        sprintf(buffer,  "%s: %02d", "minuti", _minuteallarm);
      }
      // set second
      if ( setmodelevel == 8 ) {
        if ( analogread(piu) > 1000 && _sec < 60) { _sec++; }
        if ( analogread(meno) > 1000 && _sec > 0) { _sec--; }

        sprintf(buffer,  "%s: %02d", "secondi", _secallarm);
      }
   
     
      lcd.print( buffer );
      if ( analogread(set) > 1000 ) { lcd.clear(); setmodelevel++;  }
      if ( setmodelevel > 8 ) { setmodelevel=0; }

      if (timeset > 0 && (setmodetime*2) < (millis() - timeset) ) {
         rtc.adjust(datetime(_year, _month, _day, _hour, _min, _sec));
         setmode = false;
      }
      delay(200);
    }
     lcd.print( buffer );
      if ( analogread(set) > 1000 ) { lcd.clear(); setmodelevel++;  }
      if ( setmodelevel > 8 ) { setmodelevel=0; }

      if (timeset > 0 && (setmodetime*2) < (millis() - timeset) ) {
         rtc.adjust(datetime(_hourallarm, _minuteallarm, _secallarm));
         setmode = false;
      }
      delay(200);
    }



Arduino Forum > Using Arduino > LEDs and Multiplexing > allarm timer arduino + set buttons lcd


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