Dimitar Marinov
/
Nucleo_4_encoders_w_Nokia5110
4 Rotary encoders with 5110 LCD display. For Nucleo boards
main.cpp
- Committer:
- triochi
- Date:
- 2016-09-18
- Revision:
- 2:7d10aa2795c5
- Parent:
- 1:d7d729404013
- Child:
- 3:bf5e17e09fe3
File content as of revision 2:7d10aa2795c5:
#include "mbed.h" #include "N5110.h" #include "REnc.h" //DigitalOut red(LED1); //DigitalOut blue(LED2); //DigitalOut green(LED3); int i; // 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++) { // red = i & 1; // blue = i & 2; // green = i & 4; // wait(0.2); // } // } while(1) { // these are default settings so not strictly needed lcd.normalMode(); // normal colour mode lcd.setBrightness(0.5); // put LED backlight on 50% // can directly print strings at specified co-ordinates lcd.printString("Hello, World!",0,0); 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 = 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 lcd.printString(buffer,0,1); // display on screen float pressure = 1012.3; // same idea with floats length = sprintf(buffer,"P = %.2f mb",pressure); if (length <= 14) lcd.printString(buffer,0,2); // can also print individual characters at specified place 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); } // need to refresh display after setting pixels lcd.refresh(); // can also check status of pixels using getPixel(x,y) 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(); } }