LCD 課題4 ストップウォッチ

Dependencies:   TextLCD mbed

main.cpp

Committer:
nakano_han
Date:
2016-09-30
Revision:
0:8854ce57371e
Child:
1:e676f29f471a

File content as of revision 0:8854ce57371e:

#include "mbed.h"
#include "TextLCD.h"

TextLCD lcd(D8,D10,D11,D12,D13,D14); // rs, e, d4, d5, d6, d7)
AnalogIn sw1(A4);

int main()
{
    int c = 0;
    int ms = 0;
    int s = 0;
    int m = 0;
    
    lcd.cls();
    while(1)
    {   
        if(sw1 == 1)
        {
            wait(0.25);
            c++;
        }
            if(c == 1)
            {
                ms++;
                wait(0.0073);
                if(ms == 99)
                {
                    ms = 0;
                    s++;
                    if(s == 60)
                    {
                        s = 0;
                        m++;
                    }
                }
            }
            if(c >= 3)
            {
                ms = 0;
                s = 0;
                m = 0;
                c = 0;
            }
        
        lcd.locate(0,0);
        lcd.putc((m/10) % 10 + '0');
        lcd.putc((m/1)  % 10 + '0');
        lcd.puts(":");
        
        lcd.locate(3,0);
        lcd.putc((s/10) % 10 + '0');
        lcd.putc((s/1)  % 10 + '0');
        lcd.puts(":");
        
        lcd.locate(6,0);
        lcd.putc((ms/10) % 10 + '0');
        lcd.putc((ms/1)  % 10 + '0');
    }
}