Nucleo SPI Sequencer

Dependencies:   AverageAnalogIn N5110 Nucleo_rtos_UI_Test PinDetect RotaryEncoder Sequence mbed-rtos mbed FilterController

Fork of Nucleo_rtos_UI_Test by Ryo Od

Revision:
0:468e49a35876
Child:
2:8cc6dff1d7fd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue May 24 22:33:03 2016 +0000
@@ -0,0 +1,61 @@
+#include "mbed.h"
+#include "rtos.h"
+#include "N5110.h"
+#include "RotaryEncoder.h"
+
+// SPI2 Morpho
+//        VCC,   SCE,  RST,  D/C,   MOSI,  SCLK,  LED
+N5110 Lcd(PA_12, PB_1, PB_2, PB_12, PB_15, PB_13, PA_11);
+RotaryEncoder RotEnc(D2, D3);
+DigitalOut Led1(LED1);
+
+void LedThread(void const *argument)
+{
+    while (true) {
+        Led1 = !Led1;
+        Thread::wait(500);
+    }
+}
+
+void updateLCD(int count)
+{
+    char buff[20];
+    
+    Lcd.clear();
+    Lcd.printString("RTOS UI Test.", 0, 0);
+    sprintf(buff, "count: %d", count);
+    Lcd.printString(buff, 0, 1);
+    Lcd.refresh();
+}
+
+int main()
+{
+    int count, prevCount;
+    bool isDirty = false;
+
+    printf("\n\n\r*** RTOS UI Test ***\r\n");
+
+    // Init devices
+    RotEnc.setInterval(500);
+    
+    Lcd.init();
+    Lcd.normalMode();      // normal colour mode
+    Lcd.setBrightness(0.5); // put LED backlight on 50%
+    
+    // Thread sart
+    Thread thread1(LedThread, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
+    
+    // Main loop
+    prevCount = -1;
+    while (true) {
+        count = RotEnc.getVal();
+        if (prevCount != count) {
+            prevCount = count;
+            isDirty = true;
+        }
+        if (isDirty) {
+            updateLCD(count);
+            isDirty = false;
+        }
+    }
+}