Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed C12832_lcd
main.cpp
- Committer:
- mazmonem
- Date:
- 2018-11-15
- Revision:
- 2:684c698024c4
- Parent:
- 1:13aae0117bbf
- Child:
- 3:d235ec2ba7b8
File content as of revision 2:684c698024c4:
#include "mbed.h"
#include "C12832_lcd.h"
C12832_LCD lcd;
Timeout increment;
BusIn up(p15);
BusIn down(p12);
BusIn left(p13);
BusIn right(p16);
BusIn centre(p14);
int hours=0;
int minutes=0;
bool toggle=false;
// How to detect if up is hold not press?
if (up){ // switching between increasing hrs and minutes
        if (left) {
        inc_hrs(); 
        }
    else if (right){
        inc_min();
        }
    }
if (down) //switching between decreasing minutes and hours
{
    if (left) {
        inc_hrs();
    } else if (right) {
        inc_min();
    }
}
/**
    Adjust minutes
*/
void adj_min()
{
    if (minutes>59) {
        minutes=0;
    } else if (minutes<59) {
        minutes=0;
        )
}
/**
    adj hrs
*/
void adj_hrs()
{
    if (hours>23) {
        hours=0;
        }
        else if (hours<23) {
        hours=0;
        )
}
/**
    Increment minutes
*/
void inc_min()
{
    minutes++;
    adj_min();
}
void inc_hrs()
{
    hours++;
    adj_hrs();
}
//function for decrementing 
/**
    Main entry point
*/
int main()
{
    while(true) {
        increment.attach(&inc_min, 60.0);
    }
    lcd.cls();
    lcd.locate(0,15);
// Check if minutes are less than 10 so a 0 can be prefixed onto the display
    string mins = "00"; // String to display in lcd screen
    if(minutes < 10) {
        mins = "0" + minutes;
    } else {
        mins = minutes;
    }
    lcd.printf("%s", mins);
}
}