LEDの点滅や、ブザーのOn,Offの周期測定をおこなう。 搬送波の周期は測定できない(10ms周期以上のON,OFF)

Dependencies:   AQM0802A DigitalSw mbed

Committer:
suupen
Date:
Sat May 20 01:33:48 2017 +0000
Revision:
0:c5384fa0fc28
Child:
1:d4291fd3a94c
priodMsurement??????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
suupen 0:c5384fa0fc28 1 #include "mbed.h"
suupen 0:c5384fa0fc28 2 #include <AQM0802A.h>
suupen 0:c5384fa0fc28 3 #include "testLed.h"
suupen 0:c5384fa0fc28 4
suupen 0:c5384fa0fc28 5 I2C i2c(p28, p27);
suupen 0:c5384fa0fc28 6 AQM0802A lcd(i2c); // if 5.0v supply, (i2c, false);
suupen 0:c5384fa0fc28 7
suupen 0:c5384fa0fc28 8 //DigitalOut myled1(LED1);
suupen 0:c5384fa0fc28 9 DigitalOut myled2(LED2);
suupen 0:c5384fa0fc28 10 DigitalOut myled3(LED3);
suupen 0:c5384fa0fc28 11 DigitalOut myled4(LED4);
suupen 0:c5384fa0fc28 12
suupen 0:c5384fa0fc28 13 Timer timer;
suupen 0:c5384fa0fc28 14 uint16_t onTime;
suupen 0:c5384fa0fc28 15 uint16_t offTime;
suupen 0:c5384fa0fc28 16
suupen 0:c5384fa0fc28 17 Ticker tickerLed1;
suupen 0:c5384fa0fc28 18 Ticker tickerLed2;
suupen 0:c5384fa0fc28 19
suupen 0:c5384fa0fc28 20 InterruptIn lightIn(p16);
suupen 0:c5384fa0fc28 21
suupen 0:c5384fa0fc28 22 void ledOn(void)
suupen 0:c5384fa0fc28 23 {
suupen 0:c5384fa0fc28 24 // myled4 = 1;
suupen 0:c5384fa0fc28 25
suupen 0:c5384fa0fc28 26 offTime = timer.read_ms();
suupen 0:c5384fa0fc28 27 timer.reset();
suupen 0:c5384fa0fc28 28 lcd.cls();
suupen 0:c5384fa0fc28 29 lcd.printf("on %d off %d",onTime, offTime);
suupen 0:c5384fa0fc28 30
suupen 0:c5384fa0fc28 31 }
suupen 0:c5384fa0fc28 32
suupen 0:c5384fa0fc28 33 void ledOff(void)
suupen 0:c5384fa0fc28 34 {
suupen 0:c5384fa0fc28 35 // myled4 = 0;
suupen 0:c5384fa0fc28 36
suupen 0:c5384fa0fc28 37 onTime = timer.read_ms();
suupen 0:c5384fa0fc28 38 timer.reset();
suupen 0:c5384fa0fc28 39 lcd.cls();
suupen 0:c5384fa0fc28 40 lcd.printf("on %d off %d",onTime, offTime);
suupen 0:c5384fa0fc28 41
suupen 0:c5384fa0fc28 42
suupen 0:c5384fa0fc28 43 }
suupen 0:c5384fa0fc28 44
suupen 0:c5384fa0fc28 45 void outputLed1(void)
suupen 0:c5384fa0fc28 46 {
suupen 0:c5384fa0fc28 47 // myled1 = !myled1;
suupen 0:c5384fa0fc28 48 }
suupen 0:c5384fa0fc28 49
suupen 0:c5384fa0fc28 50 void outputLed2(void)
suupen 0:c5384fa0fc28 51 {
suupen 0:c5384fa0fc28 52 myled4 = !myled4;
suupen 0:c5384fa0fc28 53 }
suupen 0:c5384fa0fc28 54
suupen 0:c5384fa0fc28 55 int main() {
suupen 0:c5384fa0fc28 56 testLedInitalize();
suupen 0:c5384fa0fc28 57
suupen 0:c5384fa0fc28 58 lcd.cls();
suupen 0:c5384fa0fc28 59 // lcd.printf("iter: \r\n");
suupen 0:c5384fa0fc28 60 lcd.printf("test");
suupen 0:c5384fa0fc28 61
suupen 0:c5384fa0fc28 62 timer.start();
suupen 0:c5384fa0fc28 63
suupen 0:c5384fa0fc28 64 lightIn.rise(&ledOn);
suupen 0:c5384fa0fc28 65 lightIn.fall(&ledOff);
suupen 0:c5384fa0fc28 66
suupen 0:c5384fa0fc28 67 tickerLed1.attach(&outputLed1, 0.1);
suupen 0:c5384fa0fc28 68 tickerLed2.attach(&outputLed2, 0.5);
suupen 0:c5384fa0fc28 69
suupen 0:c5384fa0fc28 70
suupen 0:c5384fa0fc28 71 testLedMain(true);
suupen 0:c5384fa0fc28 72
suupen 0:c5384fa0fc28 73 while(1) {
suupen 0:c5384fa0fc28 74 testLedMain(false);
suupen 0:c5384fa0fc28 75 // myled3 =lightIn;
suupen 0:c5384fa0fc28 76
suupen 0:c5384fa0fc28 77 }
suupen 0:c5384fa0fc28 78 }