This class encapsulates all the algorithms required for the displaying strings and time dependent patterns on the lcd.
Dependents: 200943412_QuickClick
Display.cpp@10:6f5a88c24a07, 2017-04-16 (annotated)
- Committer:
- domkay97
- Date:
- Sun Apr 16 13:44:55 2017 +0000
- Revision:
- 10:6f5a88c24a07
- Parent:
- 9:1e25dcab4927
- Child:
- 11:7ad2ea427784
Tidying up and formatting
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 | 10:6f5a88c24a07 | 8 | |
domkay97 | 0:dd78eca4b004 | 9 | } |
domkay97 | 0:dd78eca4b004 | 10 | |
domkay97 | 0:dd78eca4b004 | 11 | Display::~Display() |
domkay97 | 0:dd78eca4b004 | 12 | { |
domkay97 | 0:dd78eca4b004 | 13 | |
domkay97 | 0:dd78eca4b004 | 14 | } |
domkay97 | 0:dd78eca4b004 | 15 | void Display::init() |
domkay97 | 0:dd78eca4b004 | 16 | { |
domkay97 | 0:dd78eca4b004 | 17 | |
domkay97 | 10:6f5a88c24a07 | 18 | _h = 0; |
domkay97 | 10:6f5a88c24a07 | 19 | _w = 0.3; |
domkay97 | 10:6f5a88c24a07 | 20 | _a = 0; |
domkay97 | 10:6f5a88c24a07 | 21 | _v = 0; |
domkay97 | 10:6f5a88c24a07 | 22 | x = 0; |
domkay97 | 10:6f5a88c24a07 | 23 | y = 0; |
domkay97 | 10:6f5a88c24a07 | 24 | x0 = 0; |
domkay97 | 10:6f5a88c24a07 | 25 | y0 = 0; |
domkay97 | 0:dd78eca4b004 | 26 | } |
domkay97 | 0:dd78eca4b004 | 27 | |
domkay97 | 9:1e25dcab4927 | 28 | void Display::drawCircle(Controller &pad, N5110 &lcd) |
domkay97 | 10:6f5a88c24a07 | 29 | { |
domkay97 | 10:6f5a88c24a07 | 30 | Circle(pad, lcd); |
domkay97 | 10:6f5a88c24a07 | 31 | calculateWait(); |
domkay97 | 10:6f5a88c24a07 | 32 | printf("%d\n",_h); |
domkay97 | 2:f0ecd70c9ea2 | 33 | _h++; |
domkay97 | 10:6f5a88c24a07 | 34 | lcd.clear(); |
domkay97 | 2:f0ecd70c9ea2 | 35 | lcd.refresh(); |
domkay97 | 10:6f5a88c24a07 | 36 | } |
domkay97 | 0:dd78eca4b004 | 37 | |
domkay97 | 10:6f5a88c24a07 | 38 | void Display::calculateWait() |
domkay97 | 10:6f5a88c24a07 | 39 | { |
domkay97 | 10:6f5a88c24a07 | 40 | printf("Arc Number :- %d\n",_h); |
domkay97 | 10:6f5a88c24a07 | 41 | _w = 0.3*exp(-0.03465*_h); |
domkay97 | 10:6f5a88c24a07 | 42 | printf("Wait 1 :- %f7.6/n",_w); |
domkay97 | 10:6f5a88c24a07 | 43 | } |
domkay97 | 10:6f5a88c24a07 | 44 | |
domkay97 | 10:6f5a88c24a07 | 45 | void Display::display_instruction(N5110 &lcd, int ran) |
domkay97 | 10:6f5a88c24a07 | 46 | { |
domkay97 | 6:8840d7e48ce7 | 47 | lcd.clear(); |
domkay97 | 10:6f5a88c24a07 | 48 | printf("Random number :- %d\n",ran); |
domkay97 | 10:6f5a88c24a07 | 49 | if (ran == 1) { |
domkay97 | 7:635883dd8c35 | 50 | lcd.printString("PRESS",28,2); |
domkay97 | 10:6f5a88c24a07 | 51 | lcd.printChar('A',40,3); |
domkay97 | 10:6f5a88c24a07 | 52 | } else if (ran == 2) { |
domkay97 | 7:635883dd8c35 | 53 | lcd.printString("PRESS",28,2); |
domkay97 | 10:6f5a88c24a07 | 54 | lcd.printChar('B',40,3); |
domkay97 | 10:6f5a88c24a07 | 55 | } else if (ran == 3) { |
domkay97 | 7:635883dd8c35 | 56 | lcd.printString("PRESS",28,2); |
domkay97 | 10:6f5a88c24a07 | 57 | lcd.printChar('X',40,3); |
domkay97 | 10:6f5a88c24a07 | 58 | } else if (ran == 4) { |
domkay97 | 7:635883dd8c35 | 59 | lcd.printString("PRESS",28,2); |
domkay97 | 10:6f5a88c24a07 | 60 | lcd.printChar('Y',40,3); |
domkay97 | 10:6f5a88c24a07 | 61 | } else if (ran == 5) { |
domkay97 | 7:635883dd8c35 | 62 | lcd.printString("FLICK",28,2); |
domkay97 | 10:6f5a88c24a07 | 63 | lcd.printChar('L',40,3); |
domkay97 | 10:6f5a88c24a07 | 64 | } else if (ran == 6) { |
domkay97 | 7:635883dd8c35 | 65 | lcd.printString("FLICK",28,2); |
domkay97 | 10:6f5a88c24a07 | 66 | lcd.printChar('R',40,3); |
domkay97 | 10:6f5a88c24a07 | 67 | } else { |
domkay97 | 7:635883dd8c35 | 68 | lcd.printString("PRESS",28,2); |
domkay97 | 10:6f5a88c24a07 | 69 | lcd.printString("STICK",28,3); |
domkay97 | 10:6f5a88c24a07 | 70 | } |
domkay97 | 10:6f5a88c24a07 | 71 | lcd.refresh(); |
domkay97 | 10:6f5a88c24a07 | 72 | } |
domkay97 | 10:6f5a88c24a07 | 73 | |
domkay97 | 1:41a1c20a2056 | 74 | // function to draw circle |
domkay97 | 9:1e25dcab4927 | 75 | void Display::Circle(Controller &pad ,N5110 &lcd) |
domkay97 | 1:41a1c20a2056 | 76 | { |
domkay97 | 10:6f5a88c24a07 | 77 | for (int a = 0; a < 8; ++a) { |
domkay97 | 10:6f5a88c24a07 | 78 | printf("forloop (a) :- %d\n",a); |
domkay97 | 10:6f5a88c24a07 | 79 | Drawarc(lcd, a); |
domkay97 | 10:6f5a88c24a07 | 80 | lcd.refresh(); |
domkay97 | 10:6f5a88c24a07 | 81 | float Brightness = pad.pot_value(); |
domkay97 | 10:6f5a88c24a07 | 82 | lcd.setBrightness(Brightness); |
domkay97 | 10:6f5a88c24a07 | 83 | printf("potentiometer value :- %f7.6/n",Brightness); |
domkay97 | 10:6f5a88c24a07 | 84 | printf("%f7.6/n",_w); |
domkay97 | 10:6f5a88c24a07 | 85 | wait(_w); |
domkay97 | 10:6f5a88c24a07 | 86 | lcd.setBrightness(0.0); |
domkay97 | 10:6f5a88c24a07 | 87 | wait(_w); |
domkay97 | 10:6f5a88c24a07 | 88 | } |
domkay97 | 10:6f5a88c24a07 | 89 | |
domkay97 | 10:6f5a88c24a07 | 90 | } |
domkay97 | 10:6f5a88c24a07 | 91 | |
domkay97 | 10:6f5a88c24a07 | 92 | void Display::Drawarc(N5110 &lcd, int a) |
domkay97 | 10:6f5a88c24a07 | 93 | { |
domkay97 | 1:41a1c20a2056 | 94 | x = 20; |
domkay97 | 1:41a1c20a2056 | 95 | y = 0; |
domkay97 | 10:6f5a88c24a07 | 96 | |
domkay97 | 1:41a1c20a2056 | 97 | int a1; |
domkay97 | 1:41a1c20a2056 | 98 | int b1; |
domkay97 | 10:6f5a88c24a07 | 99 | radiusMod = 1-x; |
domkay97 | 10:6f5a88c24a07 | 100 | printf("RadiusMod :- %d\n",radiusMod); |
domkay97 | 10:6f5a88c24a07 | 101 | x0 = 42; |
domkay97 | 1:41a1c20a2056 | 102 | y0 = 24; |
domkay97 | 0:dd78eca4b004 | 103 | |
domkay97 | 1:41a1c20a2056 | 104 | while(x >= y) { |
domkay97 | 10:6f5a88c24a07 | 105 | |
domkay97 | 10:6f5a88c24a07 | 106 | printf("x = %d\n", x); |
domkay97 | 10:6f5a88c24a07 | 107 | printf("y = %d\n", y); |
domkay97 | 10:6f5a88c24a07 | 108 | |
domkay97 | 10:6f5a88c24a07 | 109 | switch(a) { |
domkay97 | 10:6f5a88c24a07 | 110 | case 0 : { |
domkay97 | 10:6f5a88c24a07 | 111 | a1 = y; |
domkay97 | 10:6f5a88c24a07 | 112 | b1 = x * -1; |
domkay97 | 10:6f5a88c24a07 | 113 | printf("a1 = %d\n", a1); |
domkay97 | 10:6f5a88c24a07 | 114 | printf("b1 = %d\n", b1); |
domkay97 | 10:6f5a88c24a07 | 115 | break; |
domkay97 | 10:6f5a88c24a07 | 116 | } |
domkay97 | 10:6f5a88c24a07 | 117 | case 1 : { |
domkay97 | 10:6f5a88c24a07 | 118 | a1 = x; |
domkay97 | 10:6f5a88c24a07 | 119 | b1 = y * -1; |
domkay97 | 10:6f5a88c24a07 | 120 | printf("a1 = %d\n", a1); |
domkay97 | 10:6f5a88c24a07 | 121 | printf("b1 = %d\n", b1); |
domkay97 | 10:6f5a88c24a07 | 122 | break; |
domkay97 | 10:6f5a88c24a07 | 123 | } |
domkay97 | 10:6f5a88c24a07 | 124 | case 2 : { |
domkay97 | 10:6f5a88c24a07 | 125 | a1 = x; |
domkay97 | 10:6f5a88c24a07 | 126 | b1 = y; |
domkay97 | 10:6f5a88c24a07 | 127 | printf("a1 = %d\n", a1); |
domkay97 | 10:6f5a88c24a07 | 128 | printf("b1 = %d\n", b1); |
domkay97 | 10:6f5a88c24a07 | 129 | break; |
domkay97 | 10:6f5a88c24a07 | 130 | } |
domkay97 | 10:6f5a88c24a07 | 131 | case 3 : { |
domkay97 | 10:6f5a88c24a07 | 132 | a1 = y; |
domkay97 | 10:6f5a88c24a07 | 133 | b1 = x; |
domkay97 | 10:6f5a88c24a07 | 134 | printf("a1 = %d\n", a1); |
domkay97 | 10:6f5a88c24a07 | 135 | printf("b1 = %d\n", b1); |
domkay97 | 10:6f5a88c24a07 | 136 | break; |
domkay97 | 10:6f5a88c24a07 | 137 | } |
domkay97 | 10:6f5a88c24a07 | 138 | case 4 : { |
domkay97 | 10:6f5a88c24a07 | 139 | a1 = y * -1; |
domkay97 | 10:6f5a88c24a07 | 140 | b1 = x; |
domkay97 | 10:6f5a88c24a07 | 141 | printf("a1 = %d\n", a1); |
domkay97 | 10:6f5a88c24a07 | 142 | printf("b1 = %d\n", b1); |
domkay97 | 10:6f5a88c24a07 | 143 | break; |
domkay97 | 10:6f5a88c24a07 | 144 | } |
domkay97 | 10:6f5a88c24a07 | 145 | case 5 : { |
domkay97 | 10:6f5a88c24a07 | 146 | a1 = x * -1; |
domkay97 | 10:6f5a88c24a07 | 147 | b1 = y; |
domkay97 | 10:6f5a88c24a07 | 148 | printf("a1 = %d\n", a1); |
domkay97 | 10:6f5a88c24a07 | 149 | printf("b1 = %d\n", b1); |
domkay97 | 10:6f5a88c24a07 | 150 | break; |
domkay97 | 10:6f5a88c24a07 | 151 | } |
domkay97 | 10:6f5a88c24a07 | 152 | case 6 : { |
domkay97 | 10:6f5a88c24a07 | 153 | a1 = x * -1; |
domkay97 | 1:41a1c20a2056 | 154 | b1 = y * -1; |
domkay97 | 10:6f5a88c24a07 | 155 | printf("a1 = %d\n", a1); |
domkay97 | 10:6f5a88c24a07 | 156 | printf("b1 = %d\n", b1); |
domkay97 | 1:41a1c20a2056 | 157 | break; |
domkay97 | 10:6f5a88c24a07 | 158 | } |
domkay97 | 10:6f5a88c24a07 | 159 | case 7 : { |
domkay97 | 10:6f5a88c24a07 | 160 | a1 = y * -1; |
domkay97 | 10:6f5a88c24a07 | 161 | b1 = x * -1; |
domkay97 | 10:6f5a88c24a07 | 162 | printf("a1 = %d\n", a1); |
domkay97 | 10:6f5a88c24a07 | 163 | printf("b1 = %d\n", b1); |
domkay97 | 10:6f5a88c24a07 | 164 | break; |
domkay97 | 10:6f5a88c24a07 | 165 | } |
domkay97 | 10:6f5a88c24a07 | 166 | default : { |
domkay97 | 10:6f5a88c24a07 | 167 | a1 = x; |
domkay97 | 10:6f5a88c24a07 | 168 | b1 = y * -1; |
domkay97 | 10:6f5a88c24a07 | 169 | printf("a1 = %d\n", a1); |
domkay97 | 10:6f5a88c24a07 | 170 | printf("b1 = %d\n", b1); |
domkay97 | 10:6f5a88c24a07 | 171 | break; |
domkay97 | 10:6f5a88c24a07 | 172 | } |
domkay97 | 1:41a1c20a2056 | 173 | } |
domkay97 | 10:6f5a88c24a07 | 174 | |
domkay97 | 10:6f5a88c24a07 | 175 | |
domkay97 | 10:6f5a88c24a07 | 176 | lcd.setPixel( a1 + x0, b1 + y0); |
domkay97 | 10:6f5a88c24a07 | 177 | |
domkay97 | 10:6f5a88c24a07 | 178 | y++; |
domkay97 | 10:6f5a88c24a07 | 179 | |
domkay97 | 10:6f5a88c24a07 | 180 | |
domkay97 | 7:635883dd8c35 | 181 | if (radiusMod<0) { |
domkay97 | 7:635883dd8c35 | 182 | radiusMod += 2*y+1; |
domkay97 | 1:41a1c20a2056 | 183 | } else { |
domkay97 | 1:41a1c20a2056 | 184 | x--; |
domkay97 | 7:635883dd8c35 | 185 | radiusMod += 2*(y-x)+1; |
domkay97 | 1:41a1c20a2056 | 186 | } |
domkay97 | 10:6f5a88c24a07 | 187 | printf("radiusMod 1 = %d\n", radiusMod); |
domkay97 | 1:41a1c20a2056 | 188 | } |
domkay97 | 1:41a1c20a2056 | 189 | } |