Dimitar Marinov
/
Nucleo_4_encoders_w_Nokia5110
4 Rotary encoders with 5110 LCD display. For Nucleo boards
Diff: main.cpp
- Revision:
- 8:67732769ecdd
- Parent:
- 7:62c2c1382d86
- Child:
- 9:37975a517fb0
--- a/main.cpp Sun Oct 23 15:48:58 2016 +0000 +++ b/main.cpp Sun Oct 23 16:16:23 2016 +0000 @@ -39,7 +39,7 @@ 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 +N5110 lcd(PB_8,PA_4,PA_3,PA_2,PA_10,PA_5,PB_9); //PA_4 and PA_6 not used int temperature = 50; @@ -47,10 +47,14 @@ uint16_t count1=0, count3=0, count4=0; uint32_t count2=0; int8_t dir1, dir2, dir3, dir4; - - // first need to initialise display + + char buffer[16]; // 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 + // first need to initialise display lcd.init(); - //examples + + //examples //counting on A-input only, 2 ticks per cycle, rolls over at 100 EncoderInit(&encoder1, &timer1, TIM1, 99, TIM_ENCODERMODE_TI1); @@ -67,19 +71,16 @@ //TIM5 is used by mbed for systick //EncoderInit(encoder2, timer2, TIM5, 0xffffffff, TIM_ENCODERMODE_TI12); - printf("STM HAL encoder demo\n\r"); +// printf("STM HAL encoder demo\n\r"); -// while(1) { -// for (i=1; i<7; i++) { -// red = i & 1; -// blue = i & 2; -// green = i & 4; -// wait(0.2); -// } -// } + // 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("**STM Nucleo**",0,0); while(1) - { - + { //OK 401 411 446 TICKER 030 //count1=TIM1->CNT; //dir1=TIM1->CR1&TIM_CR1_DIR; @@ -112,29 +113,18 @@ // count3, dir3==0 ? "+":"-", // count4, dir4==0 ? "+":"-" ); - // 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 + int length = sprintf(buffer,"C1 = %2d ",count1); // 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); - } + + 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 + // can also print individual characters at specified place lcd.printChar('X',5,3); @@ -147,15 +137,7 @@ 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(); + +// lcd.clear(); } }