This class encapsulates all the algorithms required for the displaying strings and time dependent patterns on the lcd.
Dependents: 200943412_QuickClick
Display.cpp@8:aa20647ac4e6, 2017-04-14 (annotated)
- Committer:
- domkay97
- Date:
- Fri Apr 14 23:42:33 2017 +0000
- Revision:
- 8:aa20647ac4e6
- Parent:
- 7:635883dd8c35
- Child:
- 9:1e25dcab4927
Added score categories informing user of performance
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
domkay97 | 0:dd78eca4b004 | 1 | #include "Display.h" |
domkay97 | 0:dd78eca4b004 | 2 | #include "N5110.h" |
domkay97 | 6:8840d7e48ce7 | 3 | #include "Controller.h" |
domkay97 | 1:41a1c20a2056 | 4 | #include <math.h> |
domkay97 | 0:dd78eca4b004 | 5 | |
domkay97 | 0:dd78eca4b004 | 6 | Display::Display() |
domkay97 | 0:dd78eca4b004 | 7 | { |
domkay97 | 0:dd78eca4b004 | 8 | _h = 0; |
domkay97 | 8:aa20647ac4e6 | 9 | _w = 0.3; |
domkay97 | 0:dd78eca4b004 | 10 | _a = 0; |
domkay97 | 1:41a1c20a2056 | 11 | _A = 0; |
domkay97 | 1:41a1c20a2056 | 12 | _v = 0; |
domkay97 | 1:41a1c20a2056 | 13 | x = 0; |
domkay97 | 1:41a1c20a2056 | 14 | y = 0; |
domkay97 | 1:41a1c20a2056 | 15 | x0 = 0; |
domkay97 | 1:41a1c20a2056 | 16 | y0 = 0; |
domkay97 | 0:dd78eca4b004 | 17 | } |
domkay97 | 0:dd78eca4b004 | 18 | |
domkay97 | 0:dd78eca4b004 | 19 | Display::~Display() |
domkay97 | 0:dd78eca4b004 | 20 | { |
domkay97 | 0:dd78eca4b004 | 21 | |
domkay97 | 0:dd78eca4b004 | 22 | } |
domkay97 | 0:dd78eca4b004 | 23 | void Display::init() |
domkay97 | 0:dd78eca4b004 | 24 | { |
domkay97 | 0:dd78eca4b004 | 25 | |
domkay97 | 0:dd78eca4b004 | 26 | _h = 0; |
domkay97 | 8:aa20647ac4e6 | 27 | _w = 0.3; |
domkay97 | 0:dd78eca4b004 | 28 | _a = 0; |
domkay97 | 1:41a1c20a2056 | 29 | _A = 0; |
domkay97 | 1:41a1c20a2056 | 30 | _v = 0; |
domkay97 | 1:41a1c20a2056 | 31 | x = 0; |
domkay97 | 1:41a1c20a2056 | 32 | y = 0; |
domkay97 | 1:41a1c20a2056 | 33 | x0 = 0; |
domkay97 | 6:8840d7e48ce7 | 34 | y0 = 0; |
domkay97 | 0:dd78eca4b004 | 35 | } |
domkay97 | 0:dd78eca4b004 | 36 | |
domkay97 | 0:dd78eca4b004 | 37 | void Display::drawCircle(N5110 &lcd) |
domkay97 | 1:41a1c20a2056 | 38 | { |
domkay97 | 2:f0ecd70c9ea2 | 39 | Circle(lcd); |
domkay97 | 2:f0ecd70c9ea2 | 40 | calculateWait(); |
domkay97 | 2:f0ecd70c9ea2 | 41 | _h++; |
domkay97 | 2:f0ecd70c9ea2 | 42 | lcd.clear(); |
domkay97 | 2:f0ecd70c9ea2 | 43 | lcd.refresh(); |
domkay97 | 0:dd78eca4b004 | 44 | } |
domkay97 | 0:dd78eca4b004 | 45 | |
domkay97 | 6:8840d7e48ce7 | 46 | void Display::calculateWait() |
domkay97 | 0:dd78eca4b004 | 47 | { |
domkay97 | 8:aa20647ac4e6 | 48 | _w = 0.3*exp(-0.03465*_h); |
domkay97 | 4:b74041216336 | 49 | |
domkay97 | 1:41a1c20a2056 | 50 | } |
domkay97 | 2:f0ecd70c9ea2 | 51 | |
domkay97 | 6:8840d7e48ce7 | 52 | void Display::display_instruction(N5110 &lcd, int ran) { |
domkay97 | 6:8840d7e48ce7 | 53 | lcd.clear(); |
domkay97 | 6:8840d7e48ce7 | 54 | if (ran == 1){ |
domkay97 | 7:635883dd8c35 | 55 | lcd.printString("PRESS",28,2); |
domkay97 | 7:635883dd8c35 | 56 | lcd.printChar('A',40,3); } |
domkay97 | 7:635883dd8c35 | 57 | else if (ran == 2){ |
domkay97 | 7:635883dd8c35 | 58 | lcd.printString("PRESS",28,2); |
domkay97 | 7:635883dd8c35 | 59 | lcd.printChar('B',40,3); } |
domkay97 | 7:635883dd8c35 | 60 | else if (ran == 3){ |
domkay97 | 7:635883dd8c35 | 61 | lcd.printString("PRESS",28,2); |
domkay97 | 7:635883dd8c35 | 62 | lcd.printChar('X',40,3); } |
domkay97 | 7:635883dd8c35 | 63 | else if (ran == 4){ |
domkay97 | 7:635883dd8c35 | 64 | lcd.printString("PRESS",28,2); |
domkay97 | 7:635883dd8c35 | 65 | lcd.printChar('Y',40,3); } |
domkay97 | 7:635883dd8c35 | 66 | else if (ran == 5){ |
domkay97 | 7:635883dd8c35 | 67 | lcd.printString("FLICK",28,2); |
domkay97 | 7:635883dd8c35 | 68 | lcd.printChar('L',40,3); } |
domkay97 | 7:635883dd8c35 | 69 | else if (ran == 6){ |
domkay97 | 7:635883dd8c35 | 70 | lcd.printString("FLICK",28,2); |
domkay97 | 7:635883dd8c35 | 71 | lcd.printChar('R',40,3); } |
domkay97 | 4:b74041216336 | 72 | else { |
domkay97 | 7:635883dd8c35 | 73 | lcd.printString("PRESS",28,2); |
domkay97 | 8:aa20647ac4e6 | 74 | lcd.printString("STICK",37,2); } |
domkay97 | 1:41a1c20a2056 | 75 | lcd.refresh(); |
domkay97 | 1:41a1c20a2056 | 76 | } |
domkay97 | 1:41a1c20a2056 | 77 | |
domkay97 | 1:41a1c20a2056 | 78 | // function to draw circle |
domkay97 | 1:41a1c20a2056 | 79 | void Display::Circle(N5110 &lcd) |
domkay97 | 1:41a1c20a2056 | 80 | { |
domkay97 | 1:41a1c20a2056 | 81 | // from http://en.wikipedia.org/wiki/Midpoint_circle_algorithm |
domkay97 | 1:41a1c20a2056 | 82 | |
domkay97 | 1:41a1c20a2056 | 83 | |
domkay97 | 1:41a1c20a2056 | 84 | |
domkay97 | 1:41a1c20a2056 | 85 | for (int a = 0; a < 8; ++a) |
domkay97 | 1:41a1c20a2056 | 86 | { |
domkay97 | 1:41a1c20a2056 | 87 | Drawarc(lcd, a); |
domkay97 | 1:41a1c20a2056 | 88 | lcd.refresh(); |
domkay97 | 2:f0ecd70c9ea2 | 89 | lcd.setBrightness(1.0); |
domkay97 | 2:f0ecd70c9ea2 | 90 | wait(_w); |
domkay97 | 2:f0ecd70c9ea2 | 91 | lcd.setBrightness(0.0); |
domkay97 | 2:f0ecd70c9ea2 | 92 | wait(_w); |
domkay97 | 2:f0ecd70c9ea2 | 93 | } |
domkay97 | 0:dd78eca4b004 | 94 | |
domkay97 | 1:41a1c20a2056 | 95 | } |
domkay97 | 1:41a1c20a2056 | 96 | |
domkay97 | 1:41a1c20a2056 | 97 | void Display::Drawarc(N5110 &lcd, int a) { |
domkay97 | 1:41a1c20a2056 | 98 | x = 20; |
domkay97 | 1:41a1c20a2056 | 99 | y = 0; |
domkay97 | 1:41a1c20a2056 | 100 | |
domkay97 | 1:41a1c20a2056 | 101 | int a1; |
domkay97 | 1:41a1c20a2056 | 102 | int b1; |
domkay97 | 7:635883dd8c35 | 103 | radiusMod = 1-x; |
domkay97 | 1:41a1c20a2056 | 104 | x0 = 42; |
domkay97 | 1:41a1c20a2056 | 105 | y0 = 24; |
domkay97 | 0:dd78eca4b004 | 106 | |
domkay97 | 1:41a1c20a2056 | 107 | while(x >= y) { |
domkay97 | 1:41a1c20a2056 | 108 | // if transparent, just draw outline |
domkay97 | 1:41a1c20a2056 | 109 | switch(a) { |
domkay97 | 1:41a1c20a2056 | 110 | case 0 : {a1 = y; |
domkay97 | 1:41a1c20a2056 | 111 | b1 = x * -1; |
domkay97 | 1:41a1c20a2056 | 112 | break; |
domkay97 | 1:41a1c20a2056 | 113 | } |
domkay97 | 1:41a1c20a2056 | 114 | case 1 : {a1 = x; |
domkay97 | 1:41a1c20a2056 | 115 | b1 = y * -1; |
domkay97 | 1:41a1c20a2056 | 116 | break; |
domkay97 | 1:41a1c20a2056 | 117 | } |
domkay97 | 1:41a1c20a2056 | 118 | case 2 : {a1 = x; |
domkay97 | 1:41a1c20a2056 | 119 | b1 = y; |
domkay97 | 1:41a1c20a2056 | 120 | break; |
domkay97 | 1:41a1c20a2056 | 121 | } |
domkay97 | 1:41a1c20a2056 | 122 | case 3 : {a1 = y; |
domkay97 | 1:41a1c20a2056 | 123 | b1 = x; |
domkay97 | 1:41a1c20a2056 | 124 | break; |
domkay97 | 1:41a1c20a2056 | 125 | } |
domkay97 | 1:41a1c20a2056 | 126 | case 4 : {a1 = y * -1; |
domkay97 | 1:41a1c20a2056 | 127 | b1 = x; |
domkay97 | 1:41a1c20a2056 | 128 | break; |
domkay97 | 1:41a1c20a2056 | 129 | } |
domkay97 | 1:41a1c20a2056 | 130 | case 5 : {a1 = x * -1; |
domkay97 | 1:41a1c20a2056 | 131 | b1 = y; |
domkay97 | 1:41a1c20a2056 | 132 | break; |
domkay97 | 1:41a1c20a2056 | 133 | } |
domkay97 | 1:41a1c20a2056 | 134 | case 6 : {a1 = x * -1; |
domkay97 | 1:41a1c20a2056 | 135 | b1 = y * -1; |
domkay97 | 1:41a1c20a2056 | 136 | break; |
domkay97 | 1:41a1c20a2056 | 137 | } |
domkay97 | 1:41a1c20a2056 | 138 | case 7 : {a1 = y * -1; |
domkay97 | 1:41a1c20a2056 | 139 | b1 = x * -1; |
domkay97 | 1:41a1c20a2056 | 140 | break; |
domkay97 | 1:41a1c20a2056 | 141 | } |
domkay97 | 1:41a1c20a2056 | 142 | default : { a1 = x; |
domkay97 | 1:41a1c20a2056 | 143 | b1 = y * -1; |
domkay97 | 1:41a1c20a2056 | 144 | break; |
domkay97 | 1:41a1c20a2056 | 145 | } |
domkay97 | 1:41a1c20a2056 | 146 | } |
domkay97 | 7:635883dd8c35 | 147 | |
domkay97 | 1:41a1c20a2056 | 148 | |
domkay97 | 1:41a1c20a2056 | 149 | lcd.setPixel( a1 + x0, b1 + y0); |
domkay97 | 1:41a1c20a2056 | 150 | |
domkay97 | 1:41a1c20a2056 | 151 | y++; |
domkay97 | 1:41a1c20a2056 | 152 | |
domkay97 | 1:41a1c20a2056 | 153 | |
domkay97 | 7:635883dd8c35 | 154 | if (radiusMod<0) { |
domkay97 | 7:635883dd8c35 | 155 | radiusMod += 2*y+1; |
domkay97 | 1:41a1c20a2056 | 156 | } else { |
domkay97 | 1:41a1c20a2056 | 157 | x--; |
domkay97 | 7:635883dd8c35 | 158 | radiusMod += 2*(y-x)+1; |
domkay97 | 1:41a1c20a2056 | 159 | } |
domkay97 | 1:41a1c20a2056 | 160 | |
domkay97 | 1:41a1c20a2056 | 161 | } |
domkay97 | 1:41a1c20a2056 | 162 | } |