Grove sensor component example for Seeed Wio 3G

Dependencies:   Grove_LCD_RGB_Backlight Grove_temperature PixelArray Servo WS2812

Fork of Wio_3G_example by Toyomasa Watarai

Revision:
70:cb6d36218441
Parent:
29:0b58d21e87d6
Child:
71:7d17edde2e03
--- a/main.cpp	Fri Jun 15 11:00:02 2018 +0100
+++ b/main.cpp	Fri Aug 03 05:22:15 2018 +0000
@@ -1,10 +1,79 @@
 #include "mbed.h"
+#include "DigitDisplay.h"
+
+#define D20 (PB_4)
+#define D19 (PB_3)
+
+DigitalOut GrovePower(PB_10, 1);
+DigitalOut led1(D38);
+AnalogIn ain(A6);
+InterruptIn btn(D20);
+
+DigitDisplay display(RXD, TXD); // 4-Digit Display connected to UART Grove connector
+
+Ticker ticker;
+volatile uint8_t second = 0;
+volatile uint8_t minute = 0;
+volatile uint8_t hour = 12;
+volatile bool colon_enable = false;
+
+
+///
+
+float get_temp()
+{
+    const int B = 4275;               // B value of the thermistor
+    const int R0 = 100000;            // R0 = 100k
+    AnalogIn temp(A4);
+    
+    float R = 1.0f/temp.read() - 1.0f;
+    R = R0*R;
 
-DigitalOut led1(LED1);
+    float temperature = 1.0/(log(R/R0)/B+1/298.15)-273.15; // convert to temperature via datasheet
+    return temperature;
+}
+///
+
+
+void tick()
+{
+    colon_enable = !colon_enable;
+    display.setColon(colon_enable);
+
+    if (colon_enable) {
+        second++;
+        if (second >= 60) {
+            second = 0;
+            minute++;
+            if (minute >= 60) {
+                minute = 0;
+                hour++;
+                if (hour >= 24) {
+                    hour = 0;
+                }
+            }
+            display.write(hour * 100 + minute);
+        }
+    }
+}
+
+void push()
+{
+        printf("*");
+}
 
 // main() runs in its own thread in the OS
-int main() {
+int main()
+{
+    display.write(hour * 100 + minute);
+    ticker.attach(tick, 0.5);
+    
+    btn.fall(push);
+
+    int cnt = 0;
+    printf("hello, Mbed world\n");
     while (true) {
+        printf("count = %4d, analog = %f, temp = %f\n", cnt++, ain.read(), get_temp());
         led1 = !led1;
         wait(0.5);
     }