![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
create and send the file to pc
Dependencies: MCP23017 WattBob_TextLCD mbed
Fork of HelloWorld by
main.cpp
- Committer:
- haseo1989
- Date:
- 2014-02-26
- Revision:
- 4:b5b159adc261
- Parent:
- 3:6cc06b58870b
- Child:
- 5:27b1b41b2366
File content as of revision 4:b5b159adc261:
#include "mbed.h" //#include "mon.cpp" DigitalIn IP1s(p5); DigitalIn IP1_400ms(p6); DigitalIn IP2_400ms(p7); AnalogIn IP1_800ms(p19); AnalogIn IP2_800ms(p20); DigitalOut bit4(LED1); DigitalOut bit3(LED2); DigitalOut bit2(LED3); DigitalOut bit1(LED4); int IP1s,IP400ms1,IP400ms2 = 0; int IP800ms1[4],IP800ms2[4] = 0; int freq = 0; int aver_anl1,aver_anl2 = 0; int digi_val = 0; int ero_code = 0; int flag4task3 = 0; int run_task = 0; int led_show = 0; int main() { while(1) { } } // wait(1) -> waiting 10ms void task1_check_wava1s() // check the square wave per second { IP1s = 0; for(int i = 0; i < 1000; i++) //the accuracy is 1us if(IP1s == 1) IP1s++; //the lasting time of the impulse of square wave } void task2_checkDIP400ms() //check the SWes per 400ms { if( IP1_400ms != 0 ) IP400ms1 = 1; else IP400ms1 = 0; if( IP2_400ms !=0 ) IP400ms2 = 1; else TP400ms2 = 0; } void task3_checkAIP800ms() { IP800ms1[flag4task3] = IP1_800ms; IP800ms2[flag4task3] = IP2_800ms; flag4task3++; flag4task3 = flag4task3%4; } void task4_display2s() { double freq2; freq2 = 1/IP1s; freq2 = freq2*1000000; freq = freq2/1; //frenquency of square wave double aver_anl3,aver_anl4 = 0; aver_anl3 = IP800ms1[0] + IP800ms1[1] + IP800ms1[2] + IP800ms1[3]; aver_nal3 = aver_anl3/4; aver_nal1 = aver_anl3/1; //averaging analog input1 aver_anl4 = IP800ms2[0] + IP800ms2[1] + IP800ms2[2] + IP800ms2[3]; aver_nal4 = aver_anl4/4; aver_nal2 = aver_anl4/1; //averaging analog input2 if ( IP400ms2 ==0 && IP400ms1 ==0 ) digi_val = 00; else if ( IP400ms2 ==0 && IP400ms1 ==1 ) digi_val = 01; else if ( IP400ms2 ==1 && IP400ms1 ==0 ) digi_val = 10; else digi_val = 11; // digital value // show out all the values } void task5_check_SWes1.8s() { if((IP400ms1 == 1) && (aver_anl1 > aver_anl2)) ero_code = 3; else ero_code = 0; //error code if(IP400ms2 == 1) run_task = 1; else run_task = 0; } void run_task1.5s() //blink led { led_show = led_show%15; int num_led = led_show; if(num_led > 7) {num_led = num_led - 8; bit4 = 1 } else bit4 = 0; if(num_led > 3) {num_led = num_led - 4; bit3 = 1} else bit3 = 0; if(num_led > 1) {num_led = num_led - 2; bit2 = 1} else bit2 = 0; bit1 = num; led_show++; } void task6_updated5s() //update A.Frequency value B.digital input values C.Filtered analogue values { {