Level 2 Project Range Device

Dependencies:   N5110 SDFileSystem SRF02 TMP102 mbed

Fork of Ranger by Philip Thompson

Revision:
0:0b180348c7e4
Child:
1:5b991c2302e1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Mar 18 15:04:05 2016 +0000
@@ -0,0 +1,107 @@
+/*
+Philip Thompsonn
+EL15PJT
+Embedded System Project
+EL2645
+ 
+ 
+ Have added the N5110 Libary and set up a a basic disply of the Range reading
+ as well as added LED indictors to range
+*/
+
+
+#include "mbed.h"
+#include "SRF02.h"
+#include "N5110.h"
+
+BusOut output(PTB2,PTB3,PTB10,PTB11,PTC11,PTC10);
+
+// Ranger object
+SRF02 srf02(I2C_SDA,I2C_SCL);
+
+// UART connection for PC
+Serial pc(USBTX,USBRX);
+
+//N5110 Object  VCC, SCE,RST, D/C, MOSI,SCLK, LED
+N5110           lcd(PTE26,PTA0,PTC4,PTD0,PTD2,PTD1,PTC3);
+
+// K64F on-board LEDs
+DigitalOut r_led(LED_RED);
+DigitalOut g_led(LED_GREEN);
+DigitalOut b_led(LED_BLUE);
+
+// K64F on-board switches
+InterruptIn sw2(SW2);
+InterruptIn sw3(SW3);
+
+int distance;
+int length;
+
+// setup serial port
+void init_serial();
+// set up board
+void init_K64F();
+
+char buffer[14];  // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
+
+int main()
+{
+    lcd.init();
+    init_serial();
+    init_K64F();
+    while(1) {
+
+        // read sensor distance in cm and print over serial port
+        int distance = srf02.getDistanceCm();
+        //serial link reading of range
+        pc.printf("Distance = %i Cm\n",distance);
+        // short delay before next measurement
+        wait(0.25);
+
+        length = sprintf(buffer,"D = %i Cm",distance);
+
+        if (length <= 14)
+
+            lcd.printString(buffer,0,2);
+        // need to refresh display after setting pixels
+        lcd.refresh();
+
+//LED range indicator runn of the bus out
+        if (distance >= 150) {
+            output = 3;
+        }
+
+        else if (100 <= distance  < 150) {
+            output = 15;
+        }
+
+        else if (distance <= 100) {
+            output = 67;
+        }
+
+        else {
+            output = 0
+
+        }
+    }
+}
+
+// Used to return a range readig thru a serial connection
+void init_serial()
+{
+    // set to highest baud - ensure terminal software matches
+    pc.baud(115200);
+}
+//Set up board switches and LEDS
+void init_K64F()
+{
+//on-board LEDs are active-low, so set pin high to turn them off.
+    r_led = 1;
+    g_led = 1;
+    b_led = 1;
+
+// since the on-board switches have external pull-ups, we should disable the internal pull-down
+// resistors that are enabled by default using InterruptIn
+    sw2.mode(PullNone);
+    sw3.mode(PullNone);
+}
\ No newline at end of file