This class encapsulates all the algorithms required for the displaying strings and time dependent patterns on the lcd.

Dependents:   200943412_QuickClick

Committer:
domkay97
Date:
Sat Apr 15 15:38:51 2017 +0000
Revision:
9:1e25dcab4927
Parent:
8:aa20647ac4e6
Child:
10:6f5a88c24a07
Completed functional game, classes and functions completed

Who changed what in which revision?

UserRevisionLine numberNew 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 9:1e25dcab4927 37 void Display::drawCircle(Controller &pad, N5110 &lcd)
domkay97 1:41a1c20a2056 38 {
domkay97 9:1e25dcab4927 39 Circle(pad, 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 9:1e25dcab4927 74 lcd.printString("STICK",28,3); }
domkay97 1:41a1c20a2056 75 lcd.refresh();
domkay97 1:41a1c20a2056 76 }
domkay97 1:41a1c20a2056 77
domkay97 1:41a1c20a2056 78 // function to draw circle
domkay97 9:1e25dcab4927 79 void Display::Circle(Controller &pad ,N5110 &lcd)
domkay97 1:41a1c20a2056 80 {
domkay97 1:41a1c20a2056 81 for (int a = 0; a < 8; ++a)
domkay97 1:41a1c20a2056 82 {
domkay97 1:41a1c20a2056 83 Drawarc(lcd, a);
domkay97 1:41a1c20a2056 84 lcd.refresh();
domkay97 9:1e25dcab4927 85 float Brightness = pad.read_pot();
domkay97 9:1e25dcab4927 86 lcd.setBrightness(Brightness);
domkay97 2:f0ecd70c9ea2 87 wait(_w);
domkay97 2:f0ecd70c9ea2 88 lcd.setBrightness(0.0);
domkay97 2:f0ecd70c9ea2 89 wait(_w);
domkay97 2:f0ecd70c9ea2 90 }
domkay97 0:dd78eca4b004 91
domkay97 1:41a1c20a2056 92 }
domkay97 1:41a1c20a2056 93
domkay97 1:41a1c20a2056 94 void Display::Drawarc(N5110 &lcd, int a) {
domkay97 1:41a1c20a2056 95 x = 20;
domkay97 1:41a1c20a2056 96 y = 0;
domkay97 1:41a1c20a2056 97
domkay97 1:41a1c20a2056 98 int a1;
domkay97 1:41a1c20a2056 99 int b1;
domkay97 7:635883dd8c35 100 radiusMod = 1-x;
domkay97 1:41a1c20a2056 101 x0 = 42;
domkay97 1:41a1c20a2056 102 y0 = 24;
domkay97 0:dd78eca4b004 103
domkay97 1:41a1c20a2056 104 while(x >= y) {
domkay97 9:1e25dcab4927 105
domkay97 1:41a1c20a2056 106 switch(a) {
domkay97 1:41a1c20a2056 107 case 0 : {a1 = y;
domkay97 1:41a1c20a2056 108 b1 = x * -1;
domkay97 1:41a1c20a2056 109 break;
domkay97 1:41a1c20a2056 110 }
domkay97 1:41a1c20a2056 111 case 1 : {a1 = x;
domkay97 1:41a1c20a2056 112 b1 = y * -1;
domkay97 1:41a1c20a2056 113 break;
domkay97 1:41a1c20a2056 114 }
domkay97 1:41a1c20a2056 115 case 2 : {a1 = x;
domkay97 1:41a1c20a2056 116 b1 = y;
domkay97 1:41a1c20a2056 117 break;
domkay97 1:41a1c20a2056 118 }
domkay97 1:41a1c20a2056 119 case 3 : {a1 = y;
domkay97 1:41a1c20a2056 120 b1 = x;
domkay97 1:41a1c20a2056 121 break;
domkay97 1:41a1c20a2056 122 }
domkay97 1:41a1c20a2056 123 case 4 : {a1 = y * -1;
domkay97 1:41a1c20a2056 124 b1 = x;
domkay97 1:41a1c20a2056 125 break;
domkay97 1:41a1c20a2056 126 }
domkay97 1:41a1c20a2056 127 case 5 : {a1 = x * -1;
domkay97 1:41a1c20a2056 128 b1 = y;
domkay97 1:41a1c20a2056 129 break;
domkay97 1:41a1c20a2056 130 }
domkay97 1:41a1c20a2056 131 case 6 : {a1 = x * -1;
domkay97 1:41a1c20a2056 132 b1 = y * -1;
domkay97 1:41a1c20a2056 133 break;
domkay97 1:41a1c20a2056 134 }
domkay97 1:41a1c20a2056 135 case 7 : {a1 = y * -1;
domkay97 1:41a1c20a2056 136 b1 = x * -1;
domkay97 1:41a1c20a2056 137 break;
domkay97 1:41a1c20a2056 138 }
domkay97 1:41a1c20a2056 139 default : { a1 = x;
domkay97 1:41a1c20a2056 140 b1 = y * -1;
domkay97 1:41a1c20a2056 141 break;
domkay97 1:41a1c20a2056 142 }
domkay97 1:41a1c20a2056 143 }
domkay97 7:635883dd8c35 144
domkay97 1:41a1c20a2056 145
domkay97 1:41a1c20a2056 146 lcd.setPixel( a1 + x0, b1 + y0);
domkay97 1:41a1c20a2056 147
domkay97 1:41a1c20a2056 148 y++;
domkay97 1:41a1c20a2056 149
domkay97 1:41a1c20a2056 150
domkay97 7:635883dd8c35 151 if (radiusMod<0) {
domkay97 7:635883dd8c35 152 radiusMod += 2*y+1;
domkay97 1:41a1c20a2056 153 } else {
domkay97 1:41a1c20a2056 154 x--;
domkay97 7:635883dd8c35 155 radiusMod += 2*(y-x)+1;
domkay97 1:41a1c20a2056 156 }
domkay97 1:41a1c20a2056 157
domkay97 1:41a1c20a2056 158 }
domkay97 1:41a1c20a2056 159 }