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

Dependents:   200943412_QuickClick

Committer:
domkay97
Date:
Sun Apr 16 19:37:09 2017 +0000
Revision:
11:7ad2ea427784
Parent:
10:6f5a88c24a07
Child:
12:41e9ba6d65d3
Improved waiting timing equation.

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 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 11:7ad2ea427784 49
domkay97 11:7ad2ea427784 50 void Display::display_instruction(N5110 &lcd, int ran) {
domkay97 6:8840d7e48ce7 51 lcd.clear();
domkay97 11:7ad2ea427784 52 if (ran == 1){
domkay97 7:635883dd8c35 53 lcd.printString("PRESS",28,2);
domkay97 11:7ad2ea427784 54 lcd.printChar('A',40,3); }
domkay97 11:7ad2ea427784 55 else if (ran == 2){
domkay97 7:635883dd8c35 56 lcd.printString("PRESS",28,2);
domkay97 11:7ad2ea427784 57 lcd.printChar('B',40,3); }
domkay97 11:7ad2ea427784 58 else if (ran == 3){
domkay97 7:635883dd8c35 59 lcd.printString("PRESS",28,2);
domkay97 11:7ad2ea427784 60 lcd.printChar('X',40,3); }
domkay97 11:7ad2ea427784 61 else if (ran == 4){
domkay97 7:635883dd8c35 62 lcd.printString("PRESS",28,2);
domkay97 11:7ad2ea427784 63 lcd.printChar('Y',40,3); }
domkay97 11:7ad2ea427784 64 else if (ran == 5){
domkay97 7:635883dd8c35 65 lcd.printString("FLICK",28,2);
domkay97 11:7ad2ea427784 66 lcd.printChar('L',40,3); }
domkay97 11:7ad2ea427784 67 else if (ran == 6){
domkay97 7:635883dd8c35 68 lcd.printString("FLICK",28,2);
domkay97 11:7ad2ea427784 69 lcd.printChar('R',40,3); }
domkay97 11:7ad2ea427784 70 else {
domkay97 7:635883dd8c35 71 lcd.printString("PRESS",28,2);
domkay97 11:7ad2ea427784 72 lcd.printString("STICK",28,3); }
domkay97 11:7ad2ea427784 73 lcd.refresh();
domkay97 11:7ad2ea427784 74 }
domkay97 11:7ad2ea427784 75
domkay97 1:41a1c20a2056 76 // function to draw circle
domkay97 11:7ad2ea427784 77 void Display::Circle(Controller &ctrl ,N5110 &lcd)
domkay97 1:41a1c20a2056 78 {
domkay97 11:7ad2ea427784 79 for (int a = 0; a < 8; ++a)
domkay97 11:7ad2ea427784 80 {
domkay97 11:7ad2ea427784 81 Drawarc(lcd, a);
domkay97 11:7ad2ea427784 82 lcd.refresh();
domkay97 11:7ad2ea427784 83 float Brightness = ctrl.pot_value();
domkay97 11:7ad2ea427784 84 lcd.setBrightness(0.0);
domkay97 11:7ad2ea427784 85 wait(_w);
domkay97 11:7ad2ea427784 86 lcd.setBrightness(Brightness);
domkay97 11:7ad2ea427784 87 wait(_w);
domkay97 11:7ad2ea427784 88 }
domkay97 11:7ad2ea427784 89
domkay97 11:7ad2ea427784 90 }
domkay97 11:7ad2ea427784 91
domkay97 11:7ad2ea427784 92 void Display::Drawarc(N5110 &lcd, int a) {
domkay97 1:41a1c20a2056 93 x = 20;
domkay97 1:41a1c20a2056 94 y = 0;
domkay97 11:7ad2ea427784 95
domkay97 1:41a1c20a2056 96 int a1;
domkay97 1:41a1c20a2056 97 int b1;
domkay97 11:7ad2ea427784 98 radiusMod = 1-x;
domkay97 11:7ad2ea427784 99 x0 = 42;
domkay97 1:41a1c20a2056 100 y0 = 24;
domkay97 0:dd78eca4b004 101
domkay97 1:41a1c20a2056 102 while(x >= y) {
domkay97 11:7ad2ea427784 103
domkay97 11:7ad2ea427784 104 switch(a) {
domkay97 11:7ad2ea427784 105 case 0 : {a1 = y;
domkay97 11:7ad2ea427784 106 b1 = x * -1;
domkay97 11:7ad2ea427784 107 break;
domkay97 11:7ad2ea427784 108 }
domkay97 11:7ad2ea427784 109 case 1 : {a1 = x;
domkay97 11:7ad2ea427784 110 b1 = y * -1;
domkay97 11:7ad2ea427784 111 break;
domkay97 11:7ad2ea427784 112 }
domkay97 11:7ad2ea427784 113 case 2 : {a1 = x;
domkay97 11:7ad2ea427784 114 b1 = y;
domkay97 11:7ad2ea427784 115 break;
domkay97 11:7ad2ea427784 116 }
domkay97 11:7ad2ea427784 117 case 3 : {a1 = y;
domkay97 11:7ad2ea427784 118 b1 = x;
domkay97 11:7ad2ea427784 119 break;
domkay97 11:7ad2ea427784 120 }
domkay97 11:7ad2ea427784 121 case 4 : {a1 = y * -1;
domkay97 11:7ad2ea427784 122 b1 = x;
domkay97 11:7ad2ea427784 123 break;
domkay97 11:7ad2ea427784 124 }
domkay97 11:7ad2ea427784 125 case 5 : {a1 = x * -1;
domkay97 11:7ad2ea427784 126 b1 = y;
domkay97 11:7ad2ea427784 127 break;
domkay97 11:7ad2ea427784 128 }
domkay97 11:7ad2ea427784 129 case 6 : {a1 = x * -1;
domkay97 11:7ad2ea427784 130 b1 = y * -1;
domkay97 11:7ad2ea427784 131 break;
domkay97 11:7ad2ea427784 132 }
domkay97 11:7ad2ea427784 133 case 7 : {a1 = y * -1;
domkay97 11:7ad2ea427784 134 b1 = x * -1;
domkay97 11:7ad2ea427784 135 break;
domkay97 11:7ad2ea427784 136 }
domkay97 11:7ad2ea427784 137 default : { a1 = x;
domkay97 11:7ad2ea427784 138 b1 = y * -1;
domkay97 10:6f5a88c24a07 139 break;
domkay97 11:7ad2ea427784 140 }
domkay97 1:41a1c20a2056 141 }
domkay97 11:7ad2ea427784 142
domkay97 11:7ad2ea427784 143
domkay97 11:7ad2ea427784 144 lcd.setPixel( a1 + x0, b1 + y0);
domkay97 11:7ad2ea427784 145
domkay97 11:7ad2ea427784 146 y++;
domkay97 11:7ad2ea427784 147
domkay97 11:7ad2ea427784 148
domkay97 7:635883dd8c35 149 if (radiusMod<0) {
domkay97 7:635883dd8c35 150 radiusMod += 2*y+1;
domkay97 1:41a1c20a2056 151 } else {
domkay97 1:41a1c20a2056 152 x--;
domkay97 7:635883dd8c35 153 radiusMod += 2*(y-x)+1;
domkay97 1:41a1c20a2056 154 }
domkay97 11:7ad2ea427784 155
domkay97 1:41a1c20a2056 156 }
domkay97 1:41a1c20a2056 157 }