This class encapsulates all the algorithms required for the displaying strings and time dependent patterns on the lcd.
Dependents: 200943412_QuickClick
Display.cpp
- Committer:
- domkay97
- Date:
- 2017-04-12
- Revision:
- 6:8840d7e48ce7
- Parent:
- 5:f8df5fe3dc6c
- Child:
- 7:635883dd8c35
File content as of revision 6:8840d7e48ce7:
#include "Display.h" #include "N5110.h" #include "Controller.h" #include <math.h> Display::Display() { _h = 0; _w = 0.4; _a = 0; _A = 0; _v = 0; x = 0; y = 0; x0 = 0; y0 = 0; } Display::~Display() { } void Display::init() { _h = 0; _w = 0.4; _a = 0; _A = 0; _v = 0; x = 0; y = 0; x0 = 0; y0 = 0; } void Display::drawCircle(N5110 &lcd) { Circle(lcd); calculateWait(); _h++; lcd.clear(); lcd.refresh(); } void Display::calculateWait() { _w = 0.4*exp(-0.03465*_h); } void Display::display_instruction(N5110 &lcd, int ran) { lcd.clear(); if (ran == 1){ lcd.printChar('A',40,2); } else if (ran == 2){ lcd.printChar('B',40,2); } else if (ran == 3){ lcd.printChar('X',40,2); } else { lcd.printChar('Y',40,2); } lcd.refresh(); } // function to draw circle void Display::Circle(N5110 &lcd) { // from http://en.wikipedia.org/wiki/Midpoint_circle_algorithm for (int a = 0; a < 8; ++a) { Drawarc(lcd, a); lcd.refresh(); lcd.setBrightness(1.0); wait(_w); lcd.setBrightness(0.0); wait(_w); } } void Display::Drawarc(N5110 &lcd, int a) { x = 20; y = 0; int a1; int b1; radiusError = 1-x; x0 = 42; y0 = 24; while(x >= y) { // if transparent, just draw outline switch(a) { case 0 : {a1 = y; b1 = x * -1; break; } case 1 : {a1 = x; b1 = y * -1; break; } case 2 : {a1 = x; b1 = y; break; } case 3 : {a1 = y; b1 = x; break; } case 4 : {a1 = y * -1; b1 = x; break; } case 5 : {a1 = x * -1; b1 = y; break; } case 6 : {a1 = x * -1; b1 = y * -1; break; } case 7 : {a1 = y * -1; b1 = x * -1; break; } default : { a1 = x; b1 = y * -1; break; } } lcd.setPixel( a1 + x0, b1 + y0); // lcd.setPixel(-x + x0, y + y0); // lcd.setPixel( y + x0, x + y0); // lcd.setPixel(-y + x0, x + y0); // lcd.setPixel(-y + x0, -x + y0); // lcd.setPixel( y + x0, -x + y0); // lcd.setPixel( x + x0, -y + y0); /// lcd.setPixel(-x + x0, -y + y0); y++; if (radiusError<0) { radiusError += 2 * y + 1; } else { x--; radiusError += 2 * (y - x) + 1; } } }