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

Dependencies:   AQM0802A DigitalSw mbed

Files at this revision

API Documentation at this revision

Comitter:
suupen
Date:
Mon Jun 05 12:31:15 2017 +0000
Parent:
2:f22110fb3925
Child:
4:001603e48dc8
Commit message:
LCD????????????

Changed in this revision

DigitalSw.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
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
testSound.cpp Show annotated file Show diff for this revision Revisions of this file
testSound.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DigitalSw.lib	Mon Jun 05 12:31:15 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/suupen/code/DigitalSw/#9198c5c0afcb
--- a/main.cpp	Sat May 27 08:20:20 2017 +0000
+++ b/main.cpp	Mon Jun 05 12:31:15 2017 +0000
@@ -1,28 +1,73 @@
+#define LCD
+
+
 #include "mbed.h"
 #include "testLed.h"
+#include "testSound.h"
 #include "priodMsurement.h"
+#include "DigitalSw.h"
 
 
+#ifdef LCD
+#include <AQM0802A.h>
+I2C i2c(p28, p27);
+AQM0802A lcd(i2c);    // if 5.0v supply, (i2c, false);
+#endif // LCD
+
 //DigitalOut myled1(LED1);
 DigitalOut myled2(LED2);
 //DigitalOut myled3(LED3);
 //DigitalOut myled4(LED4);
 
+
 DigitalIn demoLedSw(p20, PullUp);
-
+//DigitalSw startSw(p20);
+DigitalSw upSw(p8);
+DigitalSw downSw(p14);
 
 int main()
 {
-    testLedInitalize();
-    priodMsurementInitalize();
+    int8_t p = 0;
+    int32_t loPriod;
+    int32_t hiPriod;
 
+    priodMsurementInitalize();
+    testLedInitalize();
+    testSoundInitalize();
 
-    testLedMain(true);
+    int count =0;
 
     while(1) {
+    myled2 = !myled2;
+
+#if 0
+        testSoundMain(!demoLedSw);
         testLedMain(!demoLedSw);
-    priodMsurementMain();
+#endif
+
+        priodMsurementMain();
+
+        if(upSw.getOnEdge() == 1) {
+            if(++p >= 50) {
+                p = 49;
+            }
+        }
+
+        if(downSw.getOnEdge() == 1) {
+            if(--p <= 0) {
+                p = 0;
+            }
+        }
+
+#ifdef LCD
+        if(true ==  surementData((uint8_t)p, &hiPriod, &loPriod)) {
+            lcd.cls();
+            lcd.printf("p = %2d  hi = %d\n",p, hiPriod);
+            lcd.printf("        lo = %d",loPriod);
+            wait(0.2);
+        }
+#endif // LCD
 
     }
-    
+
 }
--- a/priodMsurement.cpp	Sat May 27 08:20:20 2017 +0000
+++ b/priodMsurement.cpp	Mon Jun 05 12:31:15 2017 +0000
@@ -1,12 +1,9 @@
 #include "mbed.h"
-#include <AQM0802A.h>
 #include "priodMsurement.h"
 
 DigitalOut dbgPort (p19);
 DigitalOut dbg2Port (p18);
 
-I2C i2c(p28, p27);
-AQM0802A lcd(i2c);    // if 5.0v supply, (i2c, false);
 
 Timer hiTimer;  // hi priod timer
 Timer loTimer; // low priod timer
@@ -17,11 +14,44 @@
 int32_t hiCompleteTime;    // 1/1 [ms]/count
 int32_t loCompleteTime;
 
+int32_t D_surement[50][2];  // LCD表示用測定値保管
+uint8_t P_surement = 0;     // D_surement[ここ][] のポインタ
+#define Z_nonSurement (-1)  // D_surementの最終位置(不定値)
+
 int8_t beforeLevel = -1; // 0:Lo 1:Hi -1:timeOut(non Pluse)
 
+#define Z_initialSurement (-1)// surementPut()への初期化指示
+#define Z_hiSurement (0)     // surementPut()へのON時間記憶指示
+#define Z_loSurement (1)     // surementPut()へのOFF時間記憶指示
+void surementPut(int8_t hilo, int32_t surement)
+{
+    if(hilo == Z_initialSurement) {
+        P_surement = 0;
+        D_surement[P_surement][Z_hiSurement] = (int32_t)Z_initialSurement;
+        D_surement[P_surement][Z_loSurement] = (int32_t)Z_initialSurement;
+    } else {
+        D_surement[P_surement][hilo] = surement;
+        D_surement[P_surement + 1][hilo] = (int32_t)Z_initialSurement;
+        
+        if(hilo == Z_loSurement){
+            P_surement++;
+            }
+    }
+}
+
 InterruptIn lightIn(p22);
 DigitalOut monitor(LED4);
 
+bool surementData(uint8_t p, int32_t *hiPriod, int32_t *loPriod)
+{
+    bool ans = beforeLevel == -1 ? true : false;
+    
+    *hiPriod = D_surement[p][Z_hiSurement];
+    *loPriod = D_surement[p][Z_loSurement];
+    
+    return (ans);
+    }
+
 void priodMsurementMain(void)
 {
 
@@ -33,10 +63,12 @@
     hiTimer.reset();
     if(beforeLevel == 0) {
         loCompleteTime = loTimer.read_ms();
+    surementPut(Z_loSurement, loCompleteTime);
         printf("hi = %d,  lo = %d\r\n",hiCompleteTime, loCompleteTime);
     }
     if(beforeLevel == -1) {
         printf("start\r\n");
+    surementPut(Z_initialSurement, (int32_t)Z_initialSurement);
     }
     beforeLevel = 1;
     monitor = 1;
@@ -47,6 +79,7 @@
     loTimer.reset();
     if(beforeLevel == 1) {
         hiCompleteTime = hiTimer.read_ms();
+    surementPut(Z_hiSurement, hiCompleteTime);
     }
     beforeLevel = 0;
     monitor = 0;
--- a/priodMsurement.h	Sat May 27 08:20:20 2017 +0000
+++ b/priodMsurement.h	Mon Jun 05 12:31:15 2017 +0000
@@ -7,6 +7,7 @@
  */
 void priodMsurementInitalize(void);
 void priodMsurementMain(void);
+bool surementData(uint8_t p, int32_t *hiPriod, int32_t *loPriod);
 
 
 #endif // PRIODMSUREMENT_H
\ No newline at end of file
--- a/testLed.cpp	Sat May 27 08:20:20 2017 +0000
+++ b/testLed.cpp	Mon Jun 05 12:31:15 2017 +0000
@@ -4,6 +4,7 @@
 void tick(void);
 Ticker ticker;
 DigitalOut myled3(LED3);
+DigitalOut dbgLedPort(p25);
 
 DigitalOut testLed(LED1);
 
@@ -51,6 +52,7 @@
 
 void tick(void)
 {
+    dbgLedPort = !dbgLedPort;
     myled3 = !myled3;
     if(testLedLevel == true) {
         testLed = !testLed;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testSound.cpp	Mon Jun 05 12:31:15 2017 +0000
@@ -0,0 +1,92 @@
+#include "mbed.h"
+#include "testSound.h"
+
+void tickSound(void);
+Ticker tickSounder;
+
+DigitalOut dbgSoundPort(p25);
+DigitalOut testSound(p26);
+
+Timer timerTestSound;
+bool brinkRequestSound = false;
+
+
+
+void testSoundInitalize(void)
+{
+    timerTestSound.start();
+    timerTestSound.reset();
+    brinkRequestSound = false;
+
+    tickSounder.attach_us(&tickSound, 250);
+}
+
+uint8_t brinkPositionSound = 0;  // brinkPatternSound[][ここ]
+uint16_t brinkPriodSound = 0;    // 点滅時間 1/1 ([ms]/count)
+bool testSoundLevel = false;  // false:Off true:On
+uint32_t brinkPatternSound[][2] = {
+    {1,100},
+    {0,100},
+
+    {1,200},
+    {0,200},
+
+    {1,300},
+    {0,300},
+
+    {1,400},
+    {0,400},
+
+    {1,500},
+    {0,500},
+
+    {1,100},
+    {0,200},
+
+ 
+
+
+    {2,0}       // end
+};
+
+void tickSound(void)
+{
+    dbgSoundPort = !dbgSoundPort;
+    if(testSoundLevel == true) {
+        testSound = !testSound;
+    } else {
+        testSound = 0;
+    }
+}
+
+
+
+bool testSoundMain(bool request)
+{
+    if(brinkRequestSound == false) {
+        if(request == true) {
+            brinkRequestSound = true;
+            brinkPositionSound = 0;
+            testSoundLevel = brinkPatternSound[brinkPositionSound][0];
+            brinkPriodSound = brinkPatternSound[brinkPositionSound][1];
+
+            timerTestSound.reset();
+        } else {
+            // nothing
+        }
+    } else {
+        if(timerTestSound.read_ms() > brinkPriodSound) {
+            brinkPositionSound++;
+            if(brinkPatternSound[brinkPositionSound][0] == 2) {
+                testSoundLevel = 0;
+                brinkRequestSound = false;
+            } else {
+                testSoundLevel = brinkPatternSound[brinkPositionSound][0];
+                brinkPriodSound = brinkPatternSound[brinkPositionSound][1];
+                timerTestSound.reset();
+
+            }
+        }
+    }
+    return (brinkRequestSound);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testSound.h	Mon Jun 05 12:31:15 2017 +0000
@@ -0,0 +1,19 @@
+#ifndef TESTSOUND_H
+#define TESTSOUND_H
+
+
+
+/** test sound brink initialize
+ */
+ void testSoundInitalize(void);
+
+
+/** test sound brink control
+ * @parm bool request true:start request, false:non request
+ * @return bool true:brinking false:stop
+ */
+bool testSoundMain(bool request);
+
+
+
+#endif // TESTLED_H
\ No newline at end of file