AS-289R2 test program for micro:bit

Dependencies:   AS289R2 microbit

Fork of microbit-hello-world by micro:bit

Files at this revision

API Documentation at this revision

Comitter:
MACRUM
Date:
Fri Dec 22 01:57:58 2017 +0000
Parent:
0:0041f35b0c4c
Commit message:
Initial commit

Changed in this revision

AS289R2.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
diff -r 0041f35b0c4c -r 8ffcee7d06bc AS289R2.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AS289R2.lib	Fri Dec 22 01:57:58 2017 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/MACRUM/code/AS289R2/#7f8acb87da7c
diff -r 0041f35b0c4c -r 8ffcee7d06bc main.cpp
--- a/main.cpp	Wed Jul 13 16:03:21 2016 +0100
+++ b/main.cpp	Fri Dec 22 01:57:58 2017 +0000
@@ -24,20 +24,36 @@
 */
 
 #include "MicroBit.h"
+#include "AS289R2.h"
 
 MicroBit uBit;
+AS289R2  tp(p16);
+
+void printTemp(MicroBitEvent)
+{
+    tp.printf("温度: %d\r", uBit.thermometer.getTemperature());
+}
+
+void printAcc(MicroBitEvent)
+{
+    int x = uBit.accelerometer.getX();
+    int y = uBit.accelerometer.getY();
+    int z = uBit.accelerometer.getZ();
+    tp.printf("加速度: %+5d, %+5d, %+5d\r", x, y, z);
+}
 
 int main()
 {
     // Initialise the micro:bit runtime.
     uBit.init();
 
-    // Insert your code here!
-    uBit.display.scroll("HELLO WORLD! :)");
+    // Register event handlers for button presses (either button fires!)
+    uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, printTemp);
+    uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, printAcc);
 
-    // If main exits, there may still be other fibers running or registered event handlers etc.
-    // Simply release this fiber, which will mean we enter the scheduler. Worse case, we then
-    // sit in the idle task forever, in a power efficient sleep.
+    tp.initialize();
+    tp.putLineFeed(2);
+    tp.printf("** Thermal Printer Shield **\r\r");
+
     release_fiber();
 }
-