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

Dependencies:   AQM0802A DigitalSw mbed

Files at this revision

API Documentation at this revision

Comitter:
suupen
Date:
Sat May 20 01:33:48 2017 +0000
Child:
1:d4291fd3a94c
Commit message:
priodMsurement??????????

Changed in this revision

AQM0802A.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
priodMsurement.cpp Show annotated file Show diff for this revision Revisions of this file
priodMsurement.h Show annotated file Show diff for this revision Revisions of this file
testLed.cpp Show annotated file Show diff for this revision Revisions of this file
testLed.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AQM0802A.lib	Sat May 20 01:33:48 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/tetsuya256/code/AQM0802A/#5cc8d4df601d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat May 20 01:33:48 2017 +0000
@@ -0,0 +1,78 @@
+#include "mbed.h"
+#include <AQM0802A.h>
+#include "testLed.h"
+
+I2C i2c(p28, p27);
+AQM0802A lcd(i2c);    // if 5.0v supply, (i2c, false);
+
+//DigitalOut myled1(LED1);
+DigitalOut myled2(LED2);
+DigitalOut myled3(LED3);
+DigitalOut myled4(LED4);
+
+Timer timer;
+uint16_t onTime;
+uint16_t offTime;
+
+Ticker tickerLed1;
+Ticker tickerLed2;
+
+InterruptIn lightIn(p16);
+
+void ledOn(void)
+{
+//    myled4 = 1;
+
+    offTime = timer.read_ms();
+    timer.reset();
+        lcd.cls();
+    lcd.printf("on %d off %d",onTime, offTime);
+
+    }
+
+void ledOff(void)
+{
+ //   myled4 = 0;
+
+    onTime = timer.read_ms();
+    timer.reset();
+        lcd.cls();
+    lcd.printf("on %d off %d",onTime, offTime);
+
+
+    }
+
+void outputLed1(void)
+{
+//    myled1 = !myled1;
+    }
+
+void outputLed2(void)
+{
+    myled4 = !myled4;
+    }
+
+int main() {
+        testLedInitalize();
+        
+        lcd.cls();
+//    lcd.printf("iter: \r\n");
+    lcd.printf("test");
+    
+    timer.start();
+
+    lightIn.rise(&ledOn);
+    lightIn.fall(&ledOff);
+ 
+    tickerLed1.attach(&outputLed1, 0.1);
+    tickerLed2.attach(&outputLed2, 0.5);
+
+
+        testLedMain(true);
+     
+    while(1) {
+        testLedMain(false);
+  //      myled3 =lightIn;
+
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat May 20 01:33:48 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/4eea097334d6
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testLed.cpp	Sat May 20 01:33:48 2017 +0000
@@ -0,0 +1,144 @@
+#include "mbed.h"
+#include "testLed.h"
+
+DigitalOut testLed(LED1);
+
+Timer timerTestLed;
+bool brinkRequest = false;
+
+void testLedInitalize(void)
+{
+    timerTestLed.start();
+    timerTestLed.reset();
+    brinkRequest = false;
+
+}
+
+uint8_t brinkPosition = 0;  // brinkPattern[][ここ]
+uint16_t brinkPriod = 0;    // 点滅時間 1/1 ([ms]/count)
+uint32_t brinkPattern[][2] = {
+    {1,10},
+    {0,10},
+    
+    {1,100},
+    {0,100},
+    
+    {1,10},
+    {0,10},
+    
+    {1,100},
+    {0,100},
+    
+    {1,10},
+    {0,10},
+    
+    {1,100},
+    {0,100},
+    
+    {1,10},
+    {0,10},
+    
+    {1,100},
+    {0,100},
+    
+    {1,10},
+    {0,10},
+    
+    {1,200},
+    {0,300},
+    
+    {1,100},
+    {0,100},
+    
+    {1,10},
+    {0,10},
+    
+    {1,200},
+    {0,300},
+    
+    {1,100},
+    {0,100},
+    
+    {1,10},
+    {0,10},
+    
+    {1,200},
+    {0,300},
+    
+    {1,100},
+    {0,100},
+    
+    {1,10},
+    {0,10},
+    
+    {1,200},
+    {0,300},
+    
+    {1,100},
+    {0,100},
+    
+    {1,10},
+    {0,10},
+    
+    {1,200},
+    {0,300},
+    
+    {1,100},
+    {0,100},
+    
+    {1,10},
+    {0,10},
+    
+    {1,200},
+    {0,300},
+    
+    {1,100},
+    {0,100},
+    
+    {1,10},
+    {0,10},
+    
+    {1,200},
+    {0,300},
+    
+    {1,100},
+    {0,100},
+    
+    {1,10},
+    {0,10},
+    
+    {1,200},
+    {0,300},
+    
+    {2,0}       // end
+};
+
+bool testLedMain(bool request)
+{
+    if(brinkRequest == false) {
+        if(request == true) {
+            brinkRequest = true;
+            brinkPosition = 0;
+            testLed = brinkPattern[brinkPosition][0];
+            brinkPriod = brinkPattern[brinkPosition][1];
+
+            timerTestLed.reset();
+        } else {
+            // nothing
+        }
+    } else {
+        if(timerTestLed.read_ms() > brinkPriod) {
+            brinkPosition++;
+            if(brinkPattern[brinkPosition][0] == 2) {
+                testLed = 0;
+                brinkRequest = false;
+            } else {
+                testLed = brinkPattern[brinkPosition][0];
+                brinkPriod = brinkPattern[brinkPosition][1];
+            timerTestLed.reset();
+
+            }
+        }
+    }
+    return (brinkRequest);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testLed.h	Sat May 20 01:33:48 2017 +0000
@@ -0,0 +1,19 @@
+#ifndef TESTLED_H
+#define TESTLED_H
+
+
+
+/** test led brink initialize
+ */
+ void testLedInitalize(void);
+
+
+/** test led brink control
+ * @parm bool request true:start request, false:non request
+ * @return bool true:brinking false:stop
+ */
+bool testLedMain(bool request);
+
+
+
+#endif // TESTLED_H
\ No newline at end of file