LCD demo

Dependencies:   N5110 mbed

Fork of 1620_App_Board_LDR by Craig Evans

Files at this revision

API Documentation at this revision

Comitter:
eencae
Date:
Wed Mar 15 09:59:04 2017 +0000
Parent:
3:ce5582846693
Commit message:
Initial commit

Changed in this revision

N5110.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r ce5582846693 -r 5d40f64a82c1 N5110.lib
--- a/N5110.lib	Sun Mar 05 20:12:32 2017 +0000
+++ b/N5110.lib	Wed Mar 15 09:59:04 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/eencae/code/N5110/#d80e568a2e18
+http://mbed.org/users/eencae/code/N5110/#6c046786be6c
diff -r ce5582846693 -r 5d40f64a82c1 main.cpp
--- a/main.cpp	Sun Mar 05 20:12:32 2017 +0000
+++ b/main.cpp	Wed Mar 15 09:59:04 2017 +0000
@@ -1,46 +1,65 @@
 /* ELEC1620 Application Board Example
 
-LDR
+LCD
 
-(c) Dr Craig A. Evans, University of Leeds, Feb 2017
+(c) Dr Craig A. Evans, University of Leeds, March 2017
 
 */
 
 #include "mbed.h"
 #include "N5110.h"
 
-// JP1 on board must be in 2-3 position
+// JP1 must be in 2/3 position
 N5110 lcd(p8,p9,p10,p11,p13,p21);
 
-// LDR connected to ADC pin
-AnalogIn ldr(p15);
+const int run[12][10] =   {
+    { 0,0,0,0,0,1,1,1,0,0 },
+    { 0,0,0,0,0,1,1,1,0,0 },
+    { 0,0,0,1,1,1,1,0,0,0 },
+    { 0,0,1,1,1,1,0,1,0,0 },
+    { 0,1,1,0,1,1,0,1,1,1 },
+    { 1,0,0,0,1,1,0,0,0,0 },
+    { 0,0,0,1,1,1,1,0,0,0 },
+    { 0,0,1,1,0,0,1,1,0,0 },
+    { 1,1,1,1,0,0,0,1,1,0 },
+    { 0,0,0,0,0,0,1,1,0,0 },
+    { 0,0,0,0,0,1,1,0,0,0 },
+    { 0,0,0,0,1,1,0,0,0,0 },
 
-int main() {
-    
-    lcd.init();  // need to initialise the LCD
+
+};
+
+int main()
+{
+
+    // need to initialise the lcd first, do this once outside of the loop
+    lcd.init();
     
+    int x = 0;  // starting position
+
     while(1) {
-        
-        // clear the display at the start of every new frame
+
+        // clear the display at the start of the loop
         lcd.clear();
-        
-        // lcd is 84 pixels wide x 48 pixels high
+
+        // print any text
+        lcd.printString("Run!",0,0);
+
+        // draw the required shapes
+        lcd.drawRect(0,40,84,8,FILL_BLACK);
+        lcd.drawCircle(70,10,5,FILL_TRANSPARENT);
+
+        // draw the sprite at the correct place
+        lcd.drawSprite(x,40-12,12,10,(int *)run);
         
-        //  x, y,  width, height, fill type
-        lcd.drawRect(12,20,60,8,FILL_TRANSPARENT);
-        
-        float value = ldr.read();  // read in the LDR value in range 0.0 to 1.0
-        
-        int width = int(value*60.0f); // convert to an int in the range 0.0 to 60.0
+        x+=2;  // increment x to move sprite across 2 pixels each loop
         
-        // draw a bar of the correct width
-        lcd.drawRect(12,20,width,8,FILL_BLACK); 
-        
-        // update the LCD
-        lcd.refresh(); 
-        // small delay between readings
-        wait(0.2);
-        
+        if (x>83) {  // if gone off screen then move back to left
+            x=0;    
+        }
+
+        lcd.refresh(); // refresh the LCD so the pixels appear
+        wait_ms(1000/10);  // this gives a refresh rate of 10 frames per second
     }
 }