This class encapsulates all the algorithms required for the displaying strings and time dependent patterns on the lcd.
Dependents: 200943412_QuickClick
Display.cpp@12:41e9ba6d65d3, 2017-04-21 (annotated)
- Committer:
- domkay97
- Date:
- Fri Apr 21 10:54:41 2017 +0000
- Revision:
- 12:41e9ba6d65d3
- Parent:
- 11:7ad2ea427784
- Child:
- 13:505b4fb28caf
Added multiplayer features to display
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 | 11:7ad2ea427784 | 38 | calculateWait(); |
domkay97 | 2:f0ecd70c9ea2 | 39 | _h++; |
domkay97 | 11:7ad2ea427784 | 40 | lcd.clear(); |
domkay97 | 2:f0ecd70c9ea2 | 41 | lcd.refresh(); |
domkay97 | 11:7ad2ea427784 | 42 | } |
domkay97 | 0:dd78eca4b004 | 43 | |
domkay97 | 11:7ad2ea427784 | 44 | void Display::calculateWait() |
domkay97 | 11:7ad2ea427784 | 45 | { |
domkay97 | 11:7ad2ea427784 | 46 | _w = 0.2*exp(-0.0231*_h); |
domkay97 | 11:7ad2ea427784 | 47 | |
domkay97 | 11:7ad2ea427784 | 48 | } |
domkay97 | 12:41e9ba6d65d3 | 49 | |
domkay97 | 12:41e9ba6d65d3 | 50 | |
domkay97 | 12:41e9ba6d65d3 | 51 | void Display::put_wait(float w) |
domkay97 | 12:41e9ba6d65d3 | 52 | { |
domkay97 | 12:41e9ba6d65d3 | 53 | _w = w; |
domkay97 | 12:41e9ba6d65d3 | 54 | |
domkay97 | 12:41e9ba6d65d3 | 55 | } |
domkay97 | 12:41e9ba6d65d3 | 56 | |
domkay97 | 12:41e9ba6d65d3 | 57 | float Display::get_wait() |
domkay97 | 12:41e9ba6d65d3 | 58 | { |
domkay97 | 12:41e9ba6d65d3 | 59 | return _w; |
domkay97 | 12:41e9ba6d65d3 | 60 | |
domkay97 | 12:41e9ba6d65d3 | 61 | } |
domkay97 | 11:7ad2ea427784 | 62 | |
domkay97 | 11:7ad2ea427784 | 63 | void Display::display_instruction(N5110 &lcd, int ran) { |
domkay97 | 6:8840d7e48ce7 | 64 | lcd.clear(); |
domkay97 | 11:7ad2ea427784 | 65 | if (ran == 1){ |
domkay97 | 7:635883dd8c35 | 66 | lcd.printString("PRESS",28,2); |
domkay97 | 11:7ad2ea427784 | 67 | lcd.printChar('A',40,3); } |
domkay97 | 11:7ad2ea427784 | 68 | else if (ran == 2){ |
domkay97 | 7:635883dd8c35 | 69 | lcd.printString("PRESS",28,2); |
domkay97 | 11:7ad2ea427784 | 70 | lcd.printChar('B',40,3); } |
domkay97 | 11:7ad2ea427784 | 71 | else if (ran == 3){ |
domkay97 | 7:635883dd8c35 | 72 | lcd.printString("PRESS",28,2); |
domkay97 | 11:7ad2ea427784 | 73 | lcd.printChar('X',40,3); } |
domkay97 | 11:7ad2ea427784 | 74 | else if (ran == 4){ |
domkay97 | 7:635883dd8c35 | 75 | lcd.printString("PRESS",28,2); |
domkay97 | 11:7ad2ea427784 | 76 | lcd.printChar('Y',40,3); } |
domkay97 | 11:7ad2ea427784 | 77 | else if (ran == 5){ |
domkay97 | 7:635883dd8c35 | 78 | lcd.printString("FLICK",28,2); |
domkay97 | 11:7ad2ea427784 | 79 | lcd.printChar('L',40,3); } |
domkay97 | 11:7ad2ea427784 | 80 | else if (ran == 6){ |
domkay97 | 7:635883dd8c35 | 81 | lcd.printString("FLICK",28,2); |
domkay97 | 11:7ad2ea427784 | 82 | lcd.printChar('R',40,3); } |
domkay97 | 11:7ad2ea427784 | 83 | else { |
domkay97 | 7:635883dd8c35 | 84 | lcd.printString("PRESS",28,2); |
domkay97 | 11:7ad2ea427784 | 85 | lcd.printString("STICK",28,3); } |
domkay97 | 11:7ad2ea427784 | 86 | lcd.refresh(); |
domkay97 | 11:7ad2ea427784 | 87 | } |
domkay97 | 11:7ad2ea427784 | 88 | |
domkay97 | 1:41a1c20a2056 | 89 | // function to draw circle |
domkay97 | 11:7ad2ea427784 | 90 | void Display::Circle(Controller &ctrl ,N5110 &lcd) |
domkay97 | 1:41a1c20a2056 | 91 | { |
domkay97 | 11:7ad2ea427784 | 92 | for (int a = 0; a < 8; ++a) |
domkay97 | 11:7ad2ea427784 | 93 | { |
domkay97 | 11:7ad2ea427784 | 94 | Drawarc(lcd, a); |
domkay97 | 11:7ad2ea427784 | 95 | lcd.refresh(); |
domkay97 | 11:7ad2ea427784 | 96 | float Brightness = ctrl.pot_value(); |
domkay97 | 11:7ad2ea427784 | 97 | lcd.setBrightness(0.0); |
domkay97 | 11:7ad2ea427784 | 98 | wait(_w); |
domkay97 | 11:7ad2ea427784 | 99 | lcd.setBrightness(Brightness); |
domkay97 | 11:7ad2ea427784 | 100 | wait(_w); |
domkay97 | 11:7ad2ea427784 | 101 | } |
domkay97 | 11:7ad2ea427784 | 102 | |
domkay97 | 11:7ad2ea427784 | 103 | } |
domkay97 | 11:7ad2ea427784 | 104 | |
domkay97 | 11:7ad2ea427784 | 105 | void Display::Drawarc(N5110 &lcd, int a) { |
domkay97 | 1:41a1c20a2056 | 106 | x = 20; |
domkay97 | 1:41a1c20a2056 | 107 | y = 0; |
domkay97 | 11:7ad2ea427784 | 108 | |
domkay97 | 1:41a1c20a2056 | 109 | int a1; |
domkay97 | 1:41a1c20a2056 | 110 | int b1; |
domkay97 | 11:7ad2ea427784 | 111 | radiusMod = 1-x; |
domkay97 | 11:7ad2ea427784 | 112 | x0 = 42; |
domkay97 | 1:41a1c20a2056 | 113 | y0 = 24; |
domkay97 | 0:dd78eca4b004 | 114 | |
domkay97 | 1:41a1c20a2056 | 115 | while(x >= y) { |
domkay97 | 11:7ad2ea427784 | 116 | |
domkay97 | 11:7ad2ea427784 | 117 | switch(a) { |
domkay97 | 11:7ad2ea427784 | 118 | case 0 : {a1 = y; |
domkay97 | 11:7ad2ea427784 | 119 | b1 = x * -1; |
domkay97 | 11:7ad2ea427784 | 120 | break; |
domkay97 | 11:7ad2ea427784 | 121 | } |
domkay97 | 11:7ad2ea427784 | 122 | case 1 : {a1 = x; |
domkay97 | 11:7ad2ea427784 | 123 | b1 = y * -1; |
domkay97 | 11:7ad2ea427784 | 124 | break; |
domkay97 | 11:7ad2ea427784 | 125 | } |
domkay97 | 11:7ad2ea427784 | 126 | case 2 : {a1 = x; |
domkay97 | 11:7ad2ea427784 | 127 | b1 = y; |
domkay97 | 11:7ad2ea427784 | 128 | break; |
domkay97 | 11:7ad2ea427784 | 129 | } |
domkay97 | 11:7ad2ea427784 | 130 | case 3 : {a1 = y; |
domkay97 | 11:7ad2ea427784 | 131 | b1 = x; |
domkay97 | 11:7ad2ea427784 | 132 | break; |
domkay97 | 11:7ad2ea427784 | 133 | } |
domkay97 | 11:7ad2ea427784 | 134 | case 4 : {a1 = y * -1; |
domkay97 | 11:7ad2ea427784 | 135 | b1 = x; |
domkay97 | 11:7ad2ea427784 | 136 | break; |
domkay97 | 11:7ad2ea427784 | 137 | } |
domkay97 | 11:7ad2ea427784 | 138 | case 5 : {a1 = x * -1; |
domkay97 | 11:7ad2ea427784 | 139 | b1 = y; |
domkay97 | 11:7ad2ea427784 | 140 | break; |
domkay97 | 11:7ad2ea427784 | 141 | } |
domkay97 | 11:7ad2ea427784 | 142 | case 6 : {a1 = x * -1; |
domkay97 | 11:7ad2ea427784 | 143 | b1 = y * -1; |
domkay97 | 11:7ad2ea427784 | 144 | break; |
domkay97 | 11:7ad2ea427784 | 145 | } |
domkay97 | 11:7ad2ea427784 | 146 | case 7 : {a1 = y * -1; |
domkay97 | 11:7ad2ea427784 | 147 | b1 = x * -1; |
domkay97 | 11:7ad2ea427784 | 148 | break; |
domkay97 | 11:7ad2ea427784 | 149 | } |
domkay97 | 11:7ad2ea427784 | 150 | default : { a1 = x; |
domkay97 | 11:7ad2ea427784 | 151 | b1 = y * -1; |
domkay97 | 10:6f5a88c24a07 | 152 | break; |
domkay97 | 11:7ad2ea427784 | 153 | } |
domkay97 | 1:41a1c20a2056 | 154 | } |
domkay97 | 11:7ad2ea427784 | 155 | |
domkay97 | 11:7ad2ea427784 | 156 | |
domkay97 | 11:7ad2ea427784 | 157 | lcd.setPixel( a1 + x0, b1 + y0); |
domkay97 | 11:7ad2ea427784 | 158 | |
domkay97 | 11:7ad2ea427784 | 159 | y++; |
domkay97 | 11:7ad2ea427784 | 160 | |
domkay97 | 11:7ad2ea427784 | 161 | |
domkay97 | 7:635883dd8c35 | 162 | if (radiusMod<0) { |
domkay97 | 7:635883dd8c35 | 163 | radiusMod += 2*y+1; |
domkay97 | 1:41a1c20a2056 | 164 | } else { |
domkay97 | 1:41a1c20a2056 | 165 | x--; |
domkay97 | 7:635883dd8c35 | 166 | radiusMod += 2*(y-x)+1; |
domkay97 | 1:41a1c20a2056 | 167 | } |
domkay97 | 11:7ad2ea427784 | 168 | |
domkay97 | 1:41a1c20a2056 | 169 | } |
domkay97 | 1:41a1c20a2056 | 170 | } |