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

Dependents:   200943412_QuickClick

Revision:
1:41a1c20a2056
Parent:
0:dd78eca4b004
Child:
2:f0ecd70c9ea2
--- a/Display.cpp	Sat Apr 08 15:01:45 2017 +0000
+++ b/Display.cpp	Mon Apr 10 20:10:26 2017 +0000
@@ -1,12 +1,19 @@
 #include "Display.h"
 #include "N5110.h"
+#include "Gamepad.h"
+#include <math.h>
 
 Display::Display()
 {
      _h = 0;
      _w = 0.1;
      _a = 0;
-     _A = 0;
+     _A = 0; 
+     _v = 0; 
+     x = 0;
+    y = 0; 
+    x0 = 0;
+    y0 = 0;
 }
 
 Display::~Display()
@@ -24,12 +31,18 @@
      _h = 0;
      _w = 0.1;
      _a = 0;
-     _A = 0;
+     _A = 0; 
+     _v = 0; 
+     x = 0; 
+     y = 0; 
+     x0 = 0;
+    y0 = 0;
 }
 
 void Display::drawCircle(N5110 &lcd)
-{ 
-while(1) {
+{  
+    Circle(lcd);
+    random_instruction(lcd);
     for( int _A = 0; _A < 84; _A++ ) {
         _a = _A;
  
@@ -43,20 +56,127 @@
     } 
         calculateWait(); 
         _h++; 
-        lcd.clear();
+        lcd.clear(); 
     } 
-}
 
 void Display::calculateWait() 
 {  
-    if (_h < 10) {
-            _w = _w - _w/10; } 
-    else if (_h < 20) { 
-            _w = _w - _w/20; } 
-    else if (_h < 30) { 
-            _w = _w - _w/30; } 
-    else 
-            { _w = _w - _w/40; }
-}
+   _w = 0.05*exp(-0.03465*_h);
+} 
+   // if (_h < 10) {
+     //       _w = _w - _w/10; } 
+    //else if (_h < 20) { 
+      //      _w = _w - _w/20; } 
+    //else if (_h < 30) { 
+      //      _w = _w - _w/30; } 
+    //else 
+      //      { _w = _w - _w/40; } 
+//} 
+void Display::random_instruction(N5110 &lcd) { 
+    _v = rand() % 4 + 1;  
+    if (_v == 1){
+        lcd.printChar('A',45,2); } 
+    else if (_v == 2){
+        lcd.printChar('X',45,2); }  
+    else if (_v == 3){
+        lcd.printChar('Y',45,2); }  
+    else {
+        lcd.printChar('B',45,2); }  
+    lcd.refresh(); 
+    } 
+       
+// function to draw circle
+void Display::Circle(N5110 &lcd)
+{
+    // from http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
+
+
+
+  for (int a = 0; a < 8; ++a)
+        {
+    Drawarc(lcd, a);
+
+    lcd.refresh();
+                 
+    
+    wait(1); }
  
+   }   
+    
+void Display::Drawarc(N5110 &lcd, int a) { 
+    x = 20;
+    y = 0;
+    
+    int a1;
+    int b1;
+    radiusError = 1-x; 
+    x0 = 42; 
+    y0 = 24;
 
+    while(x >= y) {
+    // if transparent, just draw outline
+    switch(a) {
+        case 0 : {a1 = y;
+                  b1 = x * -1;
+                  break;
+                }            
+        case 1 : {a1 = x;
+                  b1 = y * -1;
+                  break;
+                }           
+        case 2 : {a1 = x;
+                  b1 = y;
+                  break;
+                }                       
+        case 3 : {a1 = y;
+                  b1 = x;
+                  break;
+                }   
+        case 4 : {a1 = y * -1;
+                  b1 = x;
+                  break;
+                } 
+        case 5 : {a1 = x * -1;
+                  b1 = y;
+                  break;
+                }
+        case 6 : {a1 = x * -1;
+                  b1 = y * -1;
+                  break;
+                }                
+        case 7 : {a1 = y * -1;
+                  b1 = x * -1;
+                  break;
+                }               
+        default : { a1 = x;
+                b1 = y * -1;
+                break;
+                } 
+        }
+                
+                          
+                              
+            lcd.setPixel( a1 + x0,  b1 + y0);
+      
+                                           // lcd.setPixel(-x + x0,  y + y0);
+                                          //  lcd.setPixel( y + x0,  x + y0);
+                                          //  lcd.setPixel(-y + x0,  x + y0);
+                                           // lcd.setPixel(-y + x0, -x + y0);
+                                          //  lcd.setPixel( y + x0, -x + y0);
+                                           // lcd.setPixel( x + x0, -y + y0);
+                                           /// lcd.setPixel(-x + x0, -y + y0);
+  
+        
+        
+        y++;  
+ 
+   
+        if (radiusError<0) {
+            radiusError += 2 * y + 1;
+        } else {
+            x--;
+            radiusError += 2 * (y - x) + 1;
+        }
+
+    }
+}
\ No newline at end of file