void update_display() { // update display LCDclear(); for(int i=0; i<linebuff.size(); i++) LCDdrawstring(0, i*8, (char*)linebuff[i].c_str()); // drawing buttom line for (int i=0; i<83; i+=2) LCDdrawline(i, 40, i, 40, BLACK); // drawing battery LCDdrawrect(70, 42, 12, 5, BLACK); LCDdrawrect(81, 43, 3, 3, BLACK); // battery charge state battery_level = (battery_level>100) ? 100 : battery_level; battery_level = (battery_level<0) ? 0 : battery_level; LCDfillrect(70, 43, battery_level/10+1, 4, BLACK); // battery plugged state if(battery_plugged) { LCDdrawline(66, 43, 68, 43, BLACK); LCDdrawline(66, 45, 68, 45, BLACK); LCDfillrect(63, 42, 3, 5, BLACK); LCDfillrect(61, 43, 2, 3, BLACK); LCDdrawline(58, 44, 61, 44, BLACK); LCDdrawline(56, 45, 58, 45, BLACK); } }
int main (void) { // print infos printf("Raspberry Pi PCD8544 test\n"); printf("========================================\n"); printf("CLK on Port %i \n", _sclk); printf("DIN on Port %i \n", _din); printf("DC on Port %i \n", _dc); printf("CS on Port %i \n", _cs); printf("RST on Port %i \n", _rst); printf("========================================\n"); // check wiringPi setup if (wiringPiSetup() == -1) { printf("wiringPi-Error\n"); exit(1); } // init and clear lcd LCDInit(_sclk, _din, _dc, _cs, _rst, contrast); LCDclear(); // turn all the pixels on (a handy test) printf("Test: All pixels on.\n"); LCDcommand(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYALLON); delay(1000); // back to normal printf("Test: All pixels off.\n"); LCDcommand(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL); LCDclear(); // display logo printf("Test: Display logo.\n"); LCDshowLogo(); delay(2000); LCDclear(); // draw a single pixel printf("Test: Display single pixel.\n"); LCDsetPixel(10, 10, BLACK); LCDdisplay(); delay(2000); LCDclear(); // draw many lines printf("Test: Draw many lines.\n"); int i; for (i=0; i<84; i+=4) { LCDdrawline(0, 0, i, 47, BLACK); } for (i=0; i<48; i+=4) { LCDdrawline(0, 0, 83, i, BLACK); } LCDdisplay(); delay(2000); LCDclear(); // draw rectangles printf("Test: Draw rectangles.\n"); for (i=0; i<48; i+=2) { LCDdrawrect(i, i, 96-i, 48-i, BLACK); } LCDdisplay(); delay(2000); LCDclear(); // draw multiple rectangles printf("Test: Draw multiple rectangles.\n"); for (i=0; i<48; i++) { // alternate colors for moire effect LCDfillrect(i, i, 84-i, 48-i, i%2); } LCDdisplay(); delay(2000); LCDclear(); // draw mulitple circles printf("Test: Draw multiple circles.\n"); for (i=0; i<48; i+=2) { LCDdrawcircle(41, 23, i, BLACK); } LCDdisplay(); delay(2000); LCDclear(); // draw the first ~120 characters in the font printf("Test: Draw the first ~120 chars.\n"); for (i=0; i < 64; i++) { LCDdrawchar((i % 14) * 6, (i/14) * 8, i); } LCDdisplay(); delay(2000); for (i=0; i < 64; i++) { LCDdrawchar((i % 14) * 6, (i/14) * 8, i + 64); } LCDdisplay(); delay(2000); LCDclear(); return 0; }