一秒ごとにスイッチのon/off回数を数えるプログラムです。 タイムスタンプのエラーで困ってます。

Dependencies:   Pswitch_Lib TextLCD mbed

main.cpp

Committer:
nanaju
Date:
2014-02-09
Revision:
0:252c31119664

File content as of revision 0:252c31119664:

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

TextLCD lcd(p24,p26,p27,p28,p29,p30);
DigitalOut myled(LED1);
Pswitch mgsw(p8);
Ticker wari;
LocalFileSystem local("local");
int offset_JAPAN = 32400; //JSTのためのオフセット

int main() {//unix timestamm
set_time(1391948455+offset_JAPAN); // Set RTC time to Mon, 18 Apr 2011 13:00:00

}


int rpm=0,count=0;
volatile bool flag;

void time() {
    flag=1;
}

void LFS() {
    char time[16];
lcd.locate(0,0);
    rpm=count*60/2;
    time_t seconds; time(&seconds);
    strftime(time, 16, "%H:%M:%S\n", localtime(&seconds));
    FILE *fp = fopen("/local/out.txt", "a");
    fprintf(fp,"rpm=%4d,count=%4d,%s",rpm,count,time);
    fclose(fp);
    lcd.printf ("count=%4d,%s\r\n",count,time);
    count=0;
}

int main2() {
    wari.attach(&time, 1.0);

    while (1) {
        if (mgsw.count()>0) {

            myled=1;
            count++;
            if (flag==1) {
                LFS();
                flag=0;
            }
        } else {
            myled=0;
        }
        //lcd.printf("%4d",count);
    }
}