4 Rotary encoders with 5110 LCD display. For Nucleo boards

Dependencies:   N5110 mbed

Committer:
triochi
Date:
Sun Sep 18 18:01:03 2016 +0000
Revision:
0:b7e471386653
Child:
1:d7d729404013
Test print on nokia working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
triochi 0:b7e471386653 1 #include "mbed.h"
triochi 0:b7e471386653 2 #include "N5110.h"
triochi 0:b7e471386653 3
triochi 0:b7e471386653 4
triochi 0:b7e471386653 5 //DigitalOut red(LED1);
triochi 0:b7e471386653 6 //DigitalOut blue(LED2);
triochi 0:b7e471386653 7 //DigitalOut green(LED3);
triochi 0:b7e471386653 8 int i;
triochi 0:b7e471386653 9
triochi 0:b7e471386653 10 // VCC,SCE, RST, D/C, MOSI,SCLK,LED
triochi 0:b7e471386653 11 N5110 lcd(PB_8,PA_4,PA_0,PA_1,PA_7,PA_5,PB_9); //PA_4 and PA_6 not used
triochi 0:b7e471386653 12
triochi 0:b7e471386653 13 int main() {
triochi 0:b7e471386653 14 // first need to initialise display
triochi 0:b7e471386653 15 lcd.init();
triochi 0:b7e471386653 16
triochi 0:b7e471386653 17 // while(1) {
triochi 0:b7e471386653 18 // for (i=1; i<7; i++) {
triochi 0:b7e471386653 19 // red = i & 1;
triochi 0:b7e471386653 20 // blue = i & 2;
triochi 0:b7e471386653 21 // green = i & 4;
triochi 0:b7e471386653 22 // wait(0.2);
triochi 0:b7e471386653 23 // }
triochi 0:b7e471386653 24 // }
triochi 0:b7e471386653 25 while(1) {
triochi 0:b7e471386653 26
triochi 0:b7e471386653 27 // these are default settings so not strictly needed
triochi 0:b7e471386653 28 lcd.normalMode(); // normal colour mode
triochi 0:b7e471386653 29 lcd.setBrightness(0.5); // put LED backlight on 50%
triochi 0:b7e471386653 30
triochi 0:b7e471386653 31 // can directly print strings at specified co-ordinates
triochi 0:b7e471386653 32 lcd.printString("Hello, World!",0,0);
triochi 0:b7e471386653 33
triochi 0:b7e471386653 34 char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
triochi 0:b7e471386653 35 // so can display a string of a maximum 14 characters in length
triochi 0:b7e471386653 36 // or create formatted strings - ensure they aren't more than 14 characters long
triochi 0:b7e471386653 37 int temperature = 27;
triochi 0:b7e471386653 38 int length = sprintf(buffer,"T = %2d C",temperature); // print formatted data to buffer
triochi 0:b7e471386653 39 // it is important the format specifier ensures the length will fit in the buffer
triochi 0:b7e471386653 40 if (length <= 14) // if string will fit on display
triochi 0:b7e471386653 41 lcd.printString(buffer,0,1); // display on screen
triochi 0:b7e471386653 42
triochi 0:b7e471386653 43 float pressure = 1012.3; // same idea with floats
triochi 0:b7e471386653 44 length = sprintf(buffer,"P = %.2f mb",pressure);
triochi 0:b7e471386653 45 if (length <= 14)
triochi 0:b7e471386653 46 lcd.printString(buffer,0,2);
triochi 0:b7e471386653 47
triochi 0:b7e471386653 48 // can also print individual characters at specified place
triochi 0:b7e471386653 49 lcd.printChar('X',5,3);
triochi 0:b7e471386653 50
triochi 0:b7e471386653 51 // draw a line across the display at y = 40 pixels (origin top-left)
triochi 0:b7e471386653 52 for (int i = 0; i < WIDTH; i++) {
triochi 0:b7e471386653 53 lcd.setPixel(i,40);
triochi 0:b7e471386653 54 }
triochi 0:b7e471386653 55 // need to refresh display after setting pixels
triochi 0:b7e471386653 56 lcd.refresh();
triochi 0:b7e471386653 57
triochi 0:b7e471386653 58 // can also check status of pixels using getPixel(x,y)
triochi 0:b7e471386653 59
triochi 0:b7e471386653 60 wait(5.0);
triochi 0:b7e471386653 61
triochi 0:b7e471386653 62 lcd.clear();
triochi 0:b7e471386653 63
triochi 0:b7e471386653 64 }
triochi 0:b7e471386653 65 }