4 Rotary encoders with 5110 LCD display. For Nucleo boards

Dependencies:   N5110 mbed

Revision:
9:37975a517fb0
Parent:
8:67732769ecdd
Child:
10:65e7ceb96b39
--- a/main.cpp	Sun Oct 23 16:16:23 2016 +0000
+++ b/main.cpp	Sun Oct 23 18:44:15 2016 +0000
@@ -18,6 +18,8 @@
  * David Lowe Jan 2015
  */
 
+// Port definitions:
+// https://developer.mbed.org/users/mbed_official/code/mbed-src/file/c9b73cd93427/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F411RE/PeripheralPins.c
 
 #include "mbed.h"
 #include "N5110.h"
@@ -38,8 +40,11 @@
 //DigitalOut green(LED3);
 int i;
 
+//pwrPin, scePin, rstPin, dcPin, mosiPin, sclkPin, ledPin)
+
+
 //         VCC,SCE, RST, D/C, MOSI,SCLK,LED
-N5110 lcd(PB_8,PA_4,PA_3,PA_2,PA_10,PA_5,PB_9);  //PA_4 and PA_6 not used
+N5110 lcd(PB_8,PA_4,PB_14,PB_9,PB_15,PB_13,PB_3);  //PA_4 and PA_6 not used
 
 int temperature = 50;
 
@@ -53,20 +58,24 @@
     // or create formatted strings - ensure they aren't more than 14 characters long
     // first need to initialise display
     lcd.init();
-    
+    lcd.printString("**STM Nucleo**",0,0);
     //examples
     
     //counting on A-input only, 2 ticks per cycle, rolls over at 100
-    EncoderInit(&encoder1, &timer1, TIM1, 99, TIM_ENCODERMODE_TI1);
+    //EncoderInit(&encoder1, &timer1, TIM1, 99, TIM_ENCODERMODE_TI1);
+    EncoderInit(&encoder1, &timer1, TIM1, 3600, TIM_ENCODERMODE_TI12);
 
     //counting on both A&B inputs, 4 ticks per cycle, full 32-bit count
-    EncoderInit(&encoder2, &timer2, TIM2, 0xffffffff, TIM_ENCODERMODE_TI12);
+//    EncoderInit(&encoder2, &timer2, TIM2, 0xffffffff, TIM_ENCODERMODE_TI12);
+    EncoderInit(&encoder2, &timer2, TIM2, 3600, TIM_ENCODERMODE_TI12);
 
     //counting on B-input only, 2 ticks per cycle, full 16-bit count
-    EncoderInit(&encoder3, &timer3, TIM3, 0xffff, TIM_ENCODERMODE_TI2);
+//    EncoderInit(&encoder3, &timer3, TIM3, 0xffff, TIM_ENCODERMODE_TI2);
+    EncoderInit(&encoder3, &timer3, TIM3, 3600, TIM_ENCODERMODE_TI12);
     
     //counting on both A&B inputs, 4 ticks per cycle, full 16-bit count
-    EncoderInit(&encoder4, &timer4, TIM4, 0xffff, TIM_ENCODERMODE_TI12);
+    //EncoderInit(&encoder4, &timer4, TIM4, 0xffff, TIM_ENCODERMODE_TI12);
+    EncoderInit(&encoder4, &timer4, TIM4, 3600, TIM_ENCODERMODE_TI12);
     
     //TIM5 is used by mbed for systick
     //EncoderInit(encoder2, timer2, TIM5, 0xffffffff, TIM_ENCODERMODE_TI12);
@@ -76,9 +85,10 @@
     // these are default settings so not strictly needed
     lcd.normalMode();      // normal colour mode
     lcd.setBrightness(0.5); // put LED backlight on 50%
+    __HAL_TIM_SET_COUNTER(&timer2,0);
 
     // can directly print strings at specified co-ordinates
-    lcd.printString("**STM Nucleo**",0,0);
+//    lcd.printString("**STM Nucleo**",0,0);
     while(1) 
     {                
         //OK 401 411 446 TICKER 030
@@ -114,27 +124,28 @@
 //                                             count4, dir4==0 ? "+":"-" );
 
         // int temperature = encoder.getVal();
-        int length = sprintf(buffer,"C1 = %2d ",count1); // print formatted data to buffer
+        int length = sprintf(buffer,"C1 = %06d ",count1); // print formatted data to buffer
         // it is important the format specifier ensures the length will fit in the buffer
         
-        lcd.printString(buffer,0,1);           // display on screen
-        sprintf(buffer,"C2 = %2d ",count2); // print formatted data to buffer
-        lcd.printString(buffer,0,1);           // display on screen
-        sprintf(buffer,"C3 = %2d ",count3); // print formatted data to buffer
-        lcd.printString(buffer,0,1);           // display on screen
-        sprintf(buffer,"C4 = %2d ",count4); // print formatted data to buffer
-        lcd.printString(buffer,0,1);           // display on screen
+        lcd.printString(buffer,1,1);           // display on screen
+        sprintf(buffer,"C2 = %06d ",count2); // print formatted data to buffer
+        lcd.printString(buffer,1,2);           // display on screen
+        sprintf(buffer,"C3 = %06d ",count3); // print formatted data to buffer
+        lcd.printString(buffer,1,3);           // display on screen
+        sprintf(buffer,"C4 = %06d ",count4); // print formatted data to buffer
+        lcd.printString(buffer,1,4);           // display on screen
         
         // can also print individual characters at specified place
-        lcd.printChar('X',5,3);
+        //lcd.printChar('X',5,3);
 
         // draw a line across the display at y = 40 pixels (origin top-left)
         for (int i = 0; i < WIDTH; i++) 
         {
-            lcd.setPixel(i,40);
+            lcd.setPixel(i,50);
         }
         // need to refresh display after setting pixels
         lcd.refresh();
+        wait(.5);
 
         // can also check status of pixels using getPixel(x,y)