This class encapsulates all the algorithms required for the displaying strings and time dependent patterns on the lcd.
Dependents: 200943412_QuickClick
Display.cpp@15:c14c72342de7, 2017-04-24 (annotated)
- Committer:
- domkay97
- Date:
- Mon Apr 24 09:46:56 2017 +0000
- Revision:
- 15:c14c72342de7
- Parent:
- 13:505b4fb28caf
- Child:
- 16:8d158d39d438
Commented out printf statements to speed up program
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 | 11:7ad2ea427784 | 8 | _h = 0; |
domkay97 | 11:7ad2ea427784 | 9 | _w = 0.3; |
domkay97 | 11:7ad2ea427784 | 10 | _a = 0; |
domkay97 | 11:7ad2ea427784 | 11 | _v = 0; |
domkay97 | 11:7ad2ea427784 | 12 | x = 0; |
domkay97 | 11:7ad2ea427784 | 13 | y = 0; |
domkay97 | 11:7ad2ea427784 | 14 | x0 = 0; |
domkay97 | 11:7ad2ea427784 | 15 | y0 = 0; |
domkay97 | 0:dd78eca4b004 | 16 | } |
domkay97 | 0:dd78eca4b004 | 17 | |
domkay97 | 0:dd78eca4b004 | 18 | Display::~Display() |
domkay97 | 0:dd78eca4b004 | 19 | { |
domkay97 | 0:dd78eca4b004 | 20 | |
domkay97 | 0:dd78eca4b004 | 21 | } |
domkay97 | 0:dd78eca4b004 | 22 | void Display::init() |
domkay97 | 0:dd78eca4b004 | 23 | { |
domkay97 | 0:dd78eca4b004 | 24 | |
domkay97 | 11:7ad2ea427784 | 25 | _h = 0; |
domkay97 | 11:7ad2ea427784 | 26 | _w = 0.3; |
domkay97 | 11:7ad2ea427784 | 27 | _a = 0; |
domkay97 | 11:7ad2ea427784 | 28 | _v = 0; |
domkay97 | 11:7ad2ea427784 | 29 | x = 0; |
domkay97 | 11:7ad2ea427784 | 30 | y = 0; |
domkay97 | 11:7ad2ea427784 | 31 | x0 = 0; |
domkay97 | 11:7ad2ea427784 | 32 | y0 = 0; |
domkay97 | 0:dd78eca4b004 | 33 | } |
domkay97 | 0:dd78eca4b004 | 34 | |
domkay97 | 9:1e25dcab4927 | 35 | void Display::drawCircle(Controller &pad, N5110 &lcd) |
domkay97 | 11:7ad2ea427784 | 36 | { |
domkay97 | 11:7ad2ea427784 | 37 | Circle(pad, lcd); |
domkay97 | 15:c14c72342de7 | 38 | //printf("Prev Wait:- %3.2f\n",_w); |
domkay97 | 13:505b4fb28caf | 39 | calculateWait(); |
domkay97 | 13:505b4fb28caf | 40 | _h++; |
domkay97 | 15:c14c72342de7 | 41 | //printf("Score:- %d\n",_h); |
domkay97 | 11:7ad2ea427784 | 42 | lcd.clear(); |
domkay97 | 2:f0ecd70c9ea2 | 43 | lcd.refresh(); |
domkay97 | 11:7ad2ea427784 | 44 | } |
domkay97 | 0:dd78eca4b004 | 45 | |
domkay97 | 11:7ad2ea427784 | 46 | void Display::calculateWait() |
domkay97 | 11:7ad2ea427784 | 47 | { |
domkay97 | 15:c14c72342de7 | 48 | _w = 0.2*exp(-0.0231*_h); //this equation models how much time the user has to complete action with larger amounts of iterations. |
domkay97 | 11:7ad2ea427784 | 49 | |
domkay97 | 11:7ad2ea427784 | 50 | } |
domkay97 | 12:41e9ba6d65d3 | 51 | |
domkay97 | 12:41e9ba6d65d3 | 52 | |
domkay97 | 12:41e9ba6d65d3 | 53 | void Display::put_wait(float w) |
domkay97 | 12:41e9ba6d65d3 | 54 | { |
domkay97 | 12:41e9ba6d65d3 | 55 | _w = w; |
domkay97 | 12:41e9ba6d65d3 | 56 | |
domkay97 | 12:41e9ba6d65d3 | 57 | } |
domkay97 | 12:41e9ba6d65d3 | 58 | |
domkay97 | 12:41e9ba6d65d3 | 59 | float Display::get_wait() |
domkay97 | 12:41e9ba6d65d3 | 60 | { |
domkay97 | 12:41e9ba6d65d3 | 61 | return _w; |
domkay97 | 12:41e9ba6d65d3 | 62 | |
domkay97 | 12:41e9ba6d65d3 | 63 | } |
domkay97 | 11:7ad2ea427784 | 64 | |
domkay97 | 15:c14c72342de7 | 65 | void Display::display_instruction(N5110 &lcd, int ran) { //printing a random instruction on the screen |
domkay97 | 6:8840d7e48ce7 | 66 | lcd.clear(); |
domkay97 | 11:7ad2ea427784 | 67 | if (ran == 1){ |
domkay97 | 7:635883dd8c35 | 68 | lcd.printString("PRESS",28,2); |
domkay97 | 11:7ad2ea427784 | 69 | lcd.printChar('A',40,3); } |
domkay97 | 11:7ad2ea427784 | 70 | else if (ran == 2){ |
domkay97 | 7:635883dd8c35 | 71 | lcd.printString("PRESS",28,2); |
domkay97 | 11:7ad2ea427784 | 72 | lcd.printChar('B',40,3); } |
domkay97 | 11:7ad2ea427784 | 73 | else if (ran == 3){ |
domkay97 | 7:635883dd8c35 | 74 | lcd.printString("PRESS",28,2); |
domkay97 | 11:7ad2ea427784 | 75 | lcd.printChar('X',40,3); } |
domkay97 | 11:7ad2ea427784 | 76 | else if (ran == 4){ |
domkay97 | 7:635883dd8c35 | 77 | lcd.printString("PRESS",28,2); |
domkay97 | 11:7ad2ea427784 | 78 | lcd.printChar('Y',40,3); } |
domkay97 | 11:7ad2ea427784 | 79 | else if (ran == 5){ |
domkay97 | 7:635883dd8c35 | 80 | lcd.printString("FLICK",28,2); |
domkay97 | 11:7ad2ea427784 | 81 | lcd.printChar('L',40,3); } |
domkay97 | 11:7ad2ea427784 | 82 | else if (ran == 6){ |
domkay97 | 7:635883dd8c35 | 83 | lcd.printString("FLICK",28,2); |
domkay97 | 11:7ad2ea427784 | 84 | lcd.printChar('R',40,3); } |
domkay97 | 11:7ad2ea427784 | 85 | else { |
domkay97 | 7:635883dd8c35 | 86 | lcd.printString("PRESS",28,2); |
domkay97 | 11:7ad2ea427784 | 87 | lcd.printString("STICK",28,3); } |
domkay97 | 15:c14c72342de7 | 88 | //printf("Random Instruction int:- %d\n", ran); |
domkay97 | 11:7ad2ea427784 | 89 | lcd.refresh(); |
domkay97 | 11:7ad2ea427784 | 90 | } |
domkay97 | 11:7ad2ea427784 | 91 | |
domkay97 | 1:41a1c20a2056 | 92 | // function to draw circle |
domkay97 | 11:7ad2ea427784 | 93 | void Display::Circle(Controller &ctrl ,N5110 &lcd) |
domkay97 | 1:41a1c20a2056 | 94 | { |
domkay97 | 11:7ad2ea427784 | 95 | for (int a = 0; a < 8; ++a) |
domkay97 | 11:7ad2ea427784 | 96 | { |
domkay97 | 15:c14c72342de7 | 97 | //printf("for loop (a):- %d\n",a); |
domkay97 | 11:7ad2ea427784 | 98 | Drawarc(lcd, a); |
domkay97 | 11:7ad2ea427784 | 99 | lcd.refresh(); |
domkay97 | 15:c14c72342de7 | 100 | float Brightness = ctrl.pot_value(); //set brightness to petentiometer value |
domkay97 | 11:7ad2ea427784 | 101 | lcd.setBrightness(0.0); |
domkay97 | 15:c14c72342de7 | 102 | //printf("Brightness:- %3.2f\n",Brightness); |
domkay97 | 15:c14c72342de7 | 103 | //printf("Wait used:- %3.2f\n",_w); |
domkay97 | 11:7ad2ea427784 | 104 | wait(_w); |
domkay97 | 15:c14c72342de7 | 105 | lcd.setBrightness(Brightness); //Variable brightness will change with petentiometer value |
domkay97 | 11:7ad2ea427784 | 106 | wait(_w); |
domkay97 | 11:7ad2ea427784 | 107 | } |
domkay97 | 11:7ad2ea427784 | 108 | |
domkay97 | 11:7ad2ea427784 | 109 | } |
domkay97 | 11:7ad2ea427784 | 110 | |
domkay97 | 11:7ad2ea427784 | 111 | void Display::Drawarc(N5110 &lcd, int a) { |
domkay97 | 1:41a1c20a2056 | 112 | x = 20; |
domkay97 | 1:41a1c20a2056 | 113 | y = 0; |
domkay97 | 11:7ad2ea427784 | 114 | |
domkay97 | 1:41a1c20a2056 | 115 | int a1; |
domkay97 | 1:41a1c20a2056 | 116 | int b1; |
domkay97 | 11:7ad2ea427784 | 117 | radiusMod = 1-x; |
domkay97 | 11:7ad2ea427784 | 118 | x0 = 42; |
domkay97 | 1:41a1c20a2056 | 119 | y0 = 24; |
domkay97 | 0:dd78eca4b004 | 120 | |
domkay97 | 15:c14c72342de7 | 121 | while(x >= y) { |
domkay97 | 13:505b4fb28caf | 122 | |
domkay97 | 13:505b4fb28caf | 123 | switch(a) { |
domkay97 | 13:505b4fb28caf | 124 | |
domkay97 | 15:c14c72342de7 | 125 | case 0 : {a1 = y; //each case statement draws an arc by setting a1 and b1 accordingly |
domkay97 | 11:7ad2ea427784 | 126 | b1 = x * -1; |
domkay97 | 11:7ad2ea427784 | 127 | break; |
domkay97 | 11:7ad2ea427784 | 128 | } |
domkay97 | 11:7ad2ea427784 | 129 | case 1 : {a1 = x; |
domkay97 | 11:7ad2ea427784 | 130 | b1 = y * -1; |
domkay97 | 11:7ad2ea427784 | 131 | break; |
domkay97 | 11:7ad2ea427784 | 132 | } |
domkay97 | 11:7ad2ea427784 | 133 | case 2 : {a1 = x; |
domkay97 | 11:7ad2ea427784 | 134 | b1 = y; |
domkay97 | 11:7ad2ea427784 | 135 | break; |
domkay97 | 11:7ad2ea427784 | 136 | } |
domkay97 | 11:7ad2ea427784 | 137 | case 3 : {a1 = y; |
domkay97 | 11:7ad2ea427784 | 138 | b1 = x; |
domkay97 | 11:7ad2ea427784 | 139 | break; |
domkay97 | 11:7ad2ea427784 | 140 | } |
domkay97 | 11:7ad2ea427784 | 141 | case 4 : {a1 = y * -1; |
domkay97 | 11:7ad2ea427784 | 142 | b1 = x; |
domkay97 | 11:7ad2ea427784 | 143 | break; |
domkay97 | 11:7ad2ea427784 | 144 | } |
domkay97 | 11:7ad2ea427784 | 145 | case 5 : {a1 = x * -1; |
domkay97 | 11:7ad2ea427784 | 146 | b1 = y; |
domkay97 | 11:7ad2ea427784 | 147 | break; |
domkay97 | 11:7ad2ea427784 | 148 | } |
domkay97 | 11:7ad2ea427784 | 149 | case 6 : {a1 = x * -1; |
domkay97 | 11:7ad2ea427784 | 150 | b1 = y * -1; |
domkay97 | 11:7ad2ea427784 | 151 | break; |
domkay97 | 11:7ad2ea427784 | 152 | } |
domkay97 | 11:7ad2ea427784 | 153 | case 7 : {a1 = y * -1; |
domkay97 | 11:7ad2ea427784 | 154 | b1 = x * -1; |
domkay97 | 11:7ad2ea427784 | 155 | break; |
domkay97 | 11:7ad2ea427784 | 156 | } |
domkay97 | 11:7ad2ea427784 | 157 | default : { a1 = x; |
domkay97 | 11:7ad2ea427784 | 158 | b1 = y * -1; |
domkay97 | 10:6f5a88c24a07 | 159 | break; |
domkay97 | 11:7ad2ea427784 | 160 | } |
domkay97 | 1:41a1c20a2056 | 161 | } |
domkay97 | 11:7ad2ea427784 | 162 | |
domkay97 | 11:7ad2ea427784 | 163 | |
domkay97 | 15:c14c72342de7 | 164 | lcd.setPixel( a1 + x0, b1 + y0); //draws octant depending on a1 and b1 |
domkay97 | 11:7ad2ea427784 | 165 | |
domkay97 | 15:c14c72342de7 | 166 | y++; |
domkay97 | 15:c14c72342de7 | 167 | |
domkay97 | 11:7ad2ea427784 | 168 | |
domkay97 | 7:635883dd8c35 | 169 | if (radiusMod<0) { |
domkay97 | 7:635883dd8c35 | 170 | radiusMod += 2*y+1; |
domkay97 | 1:41a1c20a2056 | 171 | } else { |
domkay97 | 1:41a1c20a2056 | 172 | x--; |
domkay97 | 7:635883dd8c35 | 173 | radiusMod += 2*(y-x)+1; |
domkay97 | 1:41a1c20a2056 | 174 | } |
domkay97 | 15:c14c72342de7 | 175 | //printf("a1:- %d\n", a1); |
domkay97 | 15:c14c72342de7 | 176 | //printf("b1:- %d\n", b1); |
domkay97 | 15:c14c72342de7 | 177 | //printf("x:- %d\n", x); |
domkay97 | 15:c14c72342de7 | 178 | //printf("y:- %d\n", y); |
domkay97 | 15:c14c72342de7 | 179 | //printf("radiusMod:- %d\n",radiusMod); |
domkay97 | 1:41a1c20a2056 | 180 | } |
domkay97 | 15:c14c72342de7 | 181 | } |