4 Rotary encoders with 5110 LCD display. For Nucleo boards

Dependencies:   N5110 mbed

Revision:
1:d7d729404013
Parent:
0:b7e471386653
Child:
2:7d10aa2795c5
diff -r b7e471386653 -r d7d729404013 main.cpp
--- a/main.cpp	Sun Sep 18 18:01:03 2016 +0000
+++ b/main.cpp	Sun Sep 18 18:49:37 2016 +0000
@@ -1,5 +1,6 @@
 #include "mbed.h"
 #include "N5110.h"
+#include "REnc.h"
 
 
 //DigitalOut red(LED1);
@@ -9,10 +10,25 @@
 
 //         VCC,SCE, RST, D/C, MOSI,SCLK,LED
 N5110 lcd(PB_8,PA_4,PA_0,PA_1,PA_7,PA_5,PB_9);  //PA_4 and PA_6 not used
+REnc encoder(PC_3, PC_2);
+int temperature = 50;
+
+void CCW_Handle(void)
+{
+    temperature--;
+}
+    
+void CW_Handle(void)
+{
+    temperature++;
+}
+    
 
 int main() {
      // first need to initialise display
         lcd.init();
+        encoder.setHandleCCW(CCW_Handle);
+         encoder.setHandleCC(CW_Handle);
 
 //    while(1) {
 //        for (i=1; i<7; i++) {
@@ -34,7 +50,7 @@
            char buffer[14];  // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
            // so can display a string of a maximum 14 characters in length
            // or create formatted strings - ensure they aren't more than 14 characters long
-           int temperature = 27;
+          // int temperature = encoder.getVal();
            int length = sprintf(buffer,"T = %2d C",temperature); // print formatted data to buffer
            // it is important the format specifier ensures the length will fit in the buffer
            if (length <= 14)  // if string will fit on display
@@ -56,9 +72,15 @@
            lcd.refresh();
 
            // can also check status of pixels using getPixel(x,y)
-
-           wait(5.0);
-
+           while(1)
+           {               
+                wait(.5);
+               
+                length = sprintf(buffer,"T = %2d C",temperature); // print formatted data to buffer
+           
+                if (length <= 14)  // if string will fit on display
+                    lcd.printString(buffer,0,1);           // display on screen
+           }
            lcd.clear();
 
        }