Craig Evans / m3pi

Dependents:   3pi_Example_2 3pi_Lab1_Task2_Example1 3pi_Lab2_Task1_Example1 3pi_Line_Follow ... more

Revision:
4:0abe81f5d9fd
Parent:
3:5015bc2d1cf8
Child:
5:847e6cbd458b
--- a/m3pi.cpp	Thu May 25 10:18:43 2017 +0000
+++ b/m3pi.cpp	Mon Jun 26 11:09:40 2017 +0000
@@ -8,6 +8,11 @@
     _serial = new Serial(p9,p10);
     _reset = new DigitalOut(p8);
     _last_line_position = 0.0;
+    
+    _bar_graph[0] = ' ';
+    for (int i = 0; i < 6; i++) {
+        _bar_graph[i+1] = i;    
+    }
 }
 
 m3pi::~m3pi()
@@ -276,17 +281,20 @@
 void m3pi::display_sensor_values(unsigned int values[],int y)
 {
     // initialise array to ASCII '0'
-    char bin[5]= {'0','0','0','0','0'};
-
-    // loop through and if above threshold then sent to ASCII '1'
-    for (int i=0; i<5; i++) {
-        if (values[i] > 500) {
-            bin[i] = '1';
-        }
-    }
-
-    lcd_goto_xy(2,y);
-    lcd_print(bin,5);
+    lcd_goto_xy(1,y);
+    
+    char sensor_values[5];
+    
+    // loop through sensor
+    for (int sensor = 0 ; sensor < 5 ; sensor++) {
+        // get the value and put it in the correct bin 
+        // (7 bins in the range 0 to 1000
+        char value = char(values[sensor]/(1000.0/7.0)); 
+        // use the bin to select the bar graph icon to display
+        sensor_values[sensor] = _bar_graph[value];
+    }  
+    
+    lcd_print(sensor_values,5);
 
 }