stoppuhr

Dependencies:   C12832 mbed

main.cpp

Committer:
TFuchsbichler
Date:
2015-12-18
Revision:
0:1237acf021fa

File content as of revision 0:1237acf021fa:

#include "mbed.h"
#include "C12832.h"

Ticker Tick;
InterruptIn button1(p15);
InterruptIn button2(p12);
InterruptIn button3(p14);

Serial pc(USBTX, USBRX);

C12832 lcd(p5, p7, p6, p8, p11);

float a;
int msek;
int sek;
int min;
int stund;
bool mode;


void zaehl()
{
    if(mode==true) {
        msek++;
        if(msek==100) {
            sek++;
            msek=0;
            
            pc.printf("Stu:%d  Min:%d  Sek:%d \n",stund, min, sek);
        }

        if(sek==60) {
            min++;
            sek=0;

        }

        if(min==60) {
            stund++;
            min=0;
        }
        if(stund==24) {
            msek=0;
            sek=0;
            min=0;
            stund=0;
        }

    }
     
}

void on()
{
    mode=true;
}

void off()
{
    mode=false;
}

void reset()
{
    msek=0;
    sek=0;
    min=0;
    stund=0;
}

int main()
{
    Tick.attach(&zaehl, 0.01);
    button1.rise(&on);
    button2.rise(&off);
    button3.rise(&reset);

    mode=false;
    
    lcd.cls();
    lcd.locate(0,3);
    
    while(1) {
            lcd.printf("Stu:%d  Min:%d  Sek:%d ",stund, min, sek);
            lcd.locate(0,3);

    }
}