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.
main.cpp
00001 #include "mbed.h" 00002 00003 DigitalOut myled(LED_USER); 00004 DigitalIn key1(USER_BUTTON0); 00005 Serial pc(USBTX, USBRX); // tx, rx 00006 00007 Ticker flipper; 00008 #define MODE 2 //MODE 00009 #define IN 3 //IN 00010 #define EV_IN 1 //IN 00011 #define EV_MODE 2 //MODE 00012 volatile unsigned char key_dat = 0; 00013 volatile unsigned char key_old = 0; 00014 volatile unsigned char key_buf[2] = {0,0}; 00015 volatile unsigned char key_ev[2] = {0,0}; 00016 /*タイマーデータ*/ 00017 #define MODE_1S 1000 00018 #define MODE_10S 10000 00019 #define REP_1000MS 1000 00020 #define REP_500MS 500 00021 #define EV_10S 4 //10Sイベント 00022 //volatile unsigned char timer_dat = 0; 00023 volatile unsigned char timer_ev[1] = {0}; 00024 //volatile unsigned int mode_1s_t = 0; 00025 volatile unsigned int mode_10s_t = 0; 00026 int c_in = 0,mode = 0; 00027 00028 void flip() { 00029 unsigned char x; 00030 key_buf[0] <<= 1; 00031 if (!key1) { 00032 key_buf[0] ++; 00033 } 00034 key_buf[0] &= 0x0f; 00035 key_dat = 0; 00036 for(x=0;x<1;x++){ 00037 if (key_buf[x] == 0x0f){ 00038 key_dat =key_dat | (1<<x); 00039 } 00040 } 00041 key_ev[0] = key_ev[0] | (~key_old & key_dat); // ON edge EVENT set 00042 key_ev[1] = key_ev[1] | (~key_dat & key_old); // OFF edge EVENT set 00043 key_old = key_dat; 00044 00045 if(mode_10s_t){ 00046 mode_10s_t--; 00047 if(mode_10s_t == 0){ 00048 timer_ev[0] |= EV_10S; 00049 } 00050 } 00051 } 00052 00053 int main() 00054 { 00055 flipper.attach(&flip, 0.001); // the address of the function to be attached (flip) and the interval (2 seconds) 00056 pc.printf("PUSH KEY \r\nSTART "); 00057 00058 while(1) 00059 { 00060 if(mode == 0) 00061 { 00062 if(key_ev[0] & EV_IN) 00063 { 00064 pc.printf("\r\n"); 00065 wait(1.0); 00066 pc.printf("3\r"); 00067 wait(1.0); 00068 pc.printf("3 2\r"); 00069 wait(1.0); 00070 pc.printf("3 2 1\r"); 00071 wait(1.0); 00072 pc.printf(" GO! \r"); 00073 wait(1.0); 00074 key_ev[0] &= ~EV_IN; 00075 mode = 1; 00076 mode_10s_t = MODE_10S; 00077 } 00078 } 00079 if(mode == 1) 00080 { 00081 if(key_ev[0] & EV_IN) 00082 { 00083 c_in++; 00084 myled = 0; 00085 // pc.printf("%2.1f SEC %2d\r",mode_10s_t/100.0,c_in); 00086 key_ev[0] &= ~EV_IN; 00087 } 00088 if((mode_10s_t % 100)==0)pc.printf("%3.1f SEC %2d \r",mode_10s_t/1000.0,c_in); 00089 00090 if(key_ev[1] & EV_IN) 00091 { 00092 myled = 1; 00093 key_ev[1] &= ~EV_IN; 00094 } 00095 } 00096 00097 if(mode == 2) 00098 { 00099 myled = 0; 00100 pc.printf("\r\n\r\n\r\nRESULT=%2.1f\r",c_in/10.0); 00101 wait(100); 00102 } 00103 if(timer_ev[0] & EV_10S) 00104 { 00105 timer_ev[0] &= ~EV_10S; 00106 mode = 2; 00107 } 00108 } 00109 }
Generated on Sun Jul 17 2022 15:14:15 by
1.7.2