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

Dependents:   200943412_QuickClick

Committer:
domkay97
Date:
Mon May 01 17:04:13 2017 +0000
Revision:
16:8d158d39d438
Parent:
15:c14c72342de7
Child:
17:1c52ff51c028
Tidying up ready for publication, tidying DOxygen Commenting

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 11:7ad2ea427784 8 _h = 0;
domkay97 16:8d158d39d438 9 _w = 0.2;
domkay97 11:7ad2ea427784 10 _a = 0;
domkay97 16:8d158d39d438 11 _x = 0;
domkay97 16:8d158d39d438 12 _y = 0;
domkay97 16:8d158d39d438 13 _x0 = 0;
domkay97 16:8d158d39d438 14 _y0 = 0;
domkay97 0:dd78eca4b004 15 }
domkay97 0:dd78eca4b004 16
domkay97 0:dd78eca4b004 17 Display::~Display()
domkay97 0:dd78eca4b004 18 {
domkay97 0:dd78eca4b004 19
domkay97 0:dd78eca4b004 20 }
domkay97 0:dd78eca4b004 21 void Display::init()
domkay97 0:dd78eca4b004 22 {
domkay97 0:dd78eca4b004 23
domkay97 11:7ad2ea427784 24 _h = 0;
domkay97 16:8d158d39d438 25 _w = 0.2;
domkay97 11:7ad2ea427784 26 _a = 0;
domkay97 16:8d158d39d438 27 _x = 0;
domkay97 16:8d158d39d438 28 _y = 0;
domkay97 16:8d158d39d438 29 _x0 = 0;
domkay97 16:8d158d39d438 30 _y0 = 0;
domkay97 0:dd78eca4b004 31 }
domkay97 0:dd78eca4b004 32
domkay97 9:1e25dcab4927 33 void Display::drawCircle(Controller &pad, N5110 &lcd)
domkay97 11:7ad2ea427784 34 {
domkay97 16:8d158d39d438 35 _arc_selector(pad, lcd);
domkay97 15:c14c72342de7 36 //printf("Prev Wait:- %3.2f\n",_w);
domkay97 16:8d158d39d438 37 _calculateWait();
domkay97 13:505b4fb28caf 38 _h++;
domkay97 15:c14c72342de7 39 //printf("Score:- %d\n",_h);
domkay97 11:7ad2ea427784 40 lcd.clear();
domkay97 2:f0ecd70c9ea2 41 lcd.refresh();
domkay97 11:7ad2ea427784 42 }
domkay97 0:dd78eca4b004 43
domkay97 16:8d158d39d438 44 void Display::_calculateWait()
domkay97 11:7ad2ea427784 45 {
domkay97 16:8d158d39d438 46 _w = 0.2*exp(-0.0231*_h); //this equation models how much time the user has
domkay97 16:8d158d39d438 47 //to complete action with larger amounts of iterations.
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 15:c14c72342de7 63 void Display::display_instruction(N5110 &lcd, int ran) { //printing a random instruction on the screen
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 15:c14c72342de7 86 //printf("Random Instruction int:- %d\n", ran);
domkay97 11:7ad2ea427784 87 lcd.refresh();
domkay97 11:7ad2ea427784 88 }
domkay97 11:7ad2ea427784 89
domkay97 1:41a1c20a2056 90 // function to draw circle
domkay97 16:8d158d39d438 91 void Display::_arc_selector(Controller &ctrl ,N5110 &lcd)
domkay97 1:41a1c20a2056 92 {
domkay97 16:8d158d39d438 93 for (int _a = 0; _a < 8; ++_a)
domkay97 11:7ad2ea427784 94 {
domkay97 15:c14c72342de7 95 //printf("for loop (a):- %d\n",a);
domkay97 16:8d158d39d438 96 _drawArc(lcd, _a);
domkay97 11:7ad2ea427784 97 lcd.refresh();
domkay97 15:c14c72342de7 98 float Brightness = ctrl.pot_value(); //set brightness to petentiometer value
domkay97 11:7ad2ea427784 99 lcd.setBrightness(0.0);
domkay97 15:c14c72342de7 100 //printf("Brightness:- %3.2f\n",Brightness);
domkay97 15:c14c72342de7 101 //printf("Wait used:- %3.2f\n",_w);
domkay97 11:7ad2ea427784 102 wait(_w);
domkay97 15:c14c72342de7 103 lcd.setBrightness(Brightness); //Variable brightness will change with petentiometer value
domkay97 11:7ad2ea427784 104 wait(_w);
domkay97 11:7ad2ea427784 105 }
domkay97 11:7ad2ea427784 106
domkay97 11:7ad2ea427784 107 }
domkay97 11:7ad2ea427784 108
domkay97 16:8d158d39d438 109 void Display::_drawArc(N5110 &lcd, int _a) {
domkay97 16:8d158d39d438 110 _x = 20;
domkay97 16:8d158d39d438 111 _y = 0;
domkay97 11:7ad2ea427784 112
domkay97 1:41a1c20a2056 113 int a1;
domkay97 1:41a1c20a2056 114 int b1;
domkay97 16:8d158d39d438 115 _radiusMod = 1-_x;
domkay97 16:8d158d39d438 116 _x0 = 42;
domkay97 16:8d158d39d438 117 _y0 = 24;
domkay97 0:dd78eca4b004 118
domkay97 16:8d158d39d438 119 while(_x >= _y) {
domkay97 13:505b4fb28caf 120
domkay97 16:8d158d39d438 121 switch(_a) {
domkay97 13:505b4fb28caf 122
domkay97 16:8d158d39d438 123 case 0 : {a1 = _y; //each case statement draws a single octant by setting a1 and b1 accordingly
domkay97 16:8d158d39d438 124 b1 = _x * -1;
domkay97 11:7ad2ea427784 125 break;
domkay97 11:7ad2ea427784 126 }
domkay97 16:8d158d39d438 127 case 1 : {a1 = _x;
domkay97 16:8d158d39d438 128 b1 = _y * -1;
domkay97 11:7ad2ea427784 129 break;
domkay97 11:7ad2ea427784 130 }
domkay97 16:8d158d39d438 131 case 2 : {a1 = _x;
domkay97 16:8d158d39d438 132 b1 = _y;
domkay97 11:7ad2ea427784 133 break;
domkay97 11:7ad2ea427784 134 }
domkay97 16:8d158d39d438 135 case 3 : {a1 = _y;
domkay97 16:8d158d39d438 136 b1 = _x;
domkay97 11:7ad2ea427784 137 break;
domkay97 11:7ad2ea427784 138 }
domkay97 16:8d158d39d438 139 case 4 : {a1 = _y * -1;
domkay97 16:8d158d39d438 140 b1 = _x;
domkay97 11:7ad2ea427784 141 break;
domkay97 11:7ad2ea427784 142 }
domkay97 16:8d158d39d438 143 case 5 : {a1 = _x * -1;
domkay97 16:8d158d39d438 144 b1 = _y;
domkay97 11:7ad2ea427784 145 break;
domkay97 11:7ad2ea427784 146 }
domkay97 16:8d158d39d438 147 case 6 : {a1 = _x * -1;
domkay97 16:8d158d39d438 148 b1 = _y * -1;
domkay97 11:7ad2ea427784 149 break;
domkay97 11:7ad2ea427784 150 }
domkay97 16:8d158d39d438 151 case 7 : {a1 = _y * -1;
domkay97 16:8d158d39d438 152 b1 = _x * -1;
domkay97 11:7ad2ea427784 153 break;
domkay97 11:7ad2ea427784 154 }
domkay97 16:8d158d39d438 155 default : { a1 = _x;
domkay97 16:8d158d39d438 156 b1 = _y * -1;
domkay97 10:6f5a88c24a07 157 break;
domkay97 11:7ad2ea427784 158 }
domkay97 1:41a1c20a2056 159 }
domkay97 11:7ad2ea427784 160
domkay97 11:7ad2ea427784 161
domkay97 16:8d158d39d438 162 lcd.setPixel( a1 + _x0, b1 + _y0); //draws octant depending on a1 and b1
domkay97 11:7ad2ea427784 163
domkay97 16:8d158d39d438 164 _y++;
domkay97 15:c14c72342de7 165
domkay97 11:7ad2ea427784 166
domkay97 16:8d158d39d438 167 if (_radiusMod<0) {
domkay97 16:8d158d39d438 168 _radiusMod += 2*_y+1;
domkay97 1:41a1c20a2056 169 } else {
domkay97 16:8d158d39d438 170 _x--;
domkay97 16:8d158d39d438 171 _radiusMod += 2*(_y-_x)+1;
domkay97 1:41a1c20a2056 172 }
domkay97 16:8d158d39d438 173 //printf("_a1:- %d\n", _a1);
domkay97 16:8d158d39d438 174 //printf("_b1:- %d\n", _b1);
domkay97 16:8d158d39d438 175 //printf("_x:- %d\n", _x);
domkay97 16:8d158d39d438 176 //printf("_y:- %d\n", _y);
domkay97 16:8d158d39d438 177 //printf("_radiusMod:- %d\n",_radiusMod);
domkay97 1:41a1c20a2056 178 }
domkay97 16:8d158d39d438 179 }