Muhaimin Mokhtar / Mbed 2 deprecated MuhaiminMokhtar

Dependencies:   N5110 PowerControl SRF02 beep mbed

Files at this revision

API Documentation at this revision

Comitter:
MuhaiminMokhtar
Date:
Mon May 11 22:12:11 2015 +0000
Commit message:
First commit.; ; All is working fine

Changed in this revision

N5110.lib Show annotated file Show diff for this revision Revisions of this file
PowerControl.lib Show annotated file Show diff for this revision Revisions of this file
SRF02.lib Show annotated file Show diff for this revision Revisions of this file
beep.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
main.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/N5110.lib	Mon May 11 22:12:11 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/eencae/code/N5110/#ba8addc061ea
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PowerControl.lib	Mon May 11 22:12:11 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/JST2011/code/PowerControl/#d0fa2aeb02a4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SRF02.lib	Mon May 11 22:12:11 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/eencae/code/SRF02/#8e6587d88773
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/beep.lib	Mon May 11 22:12:11 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/dreschpe/code/beep/#d8e14429a95f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon May 11 22:12:11 2015 +0000
@@ -0,0 +1,78 @@
+/** 
+@file main.cpp
+@brief program main and its implementation
+@brief call functions here need one
+*/
+
+ #include "main.h"
+
+int main()
+{
+    PHY_PowerDown();  ///power down to minimise power usage 
+    lcd.init();        ///nitialise lcd display
+    welcomeMessage();  //print welcome message 
+    lcd.clear();       //clear lcd
+    
+    button.rise(&buttonPressed);  //event generated on rising edge
+    
+    
+   set_time(1431359340);   ///set time using UNIX time
+
+    while(1) {
+        ///potentiometer to control the lcd backlight
+        if (potBrightness <= 0.1) {
+            lcd.turnOff();
+
+
+        }
+        if (potBrightness >= 0.1) {
+            lcd.init();
+            lcdBrightness=potBrightness;
+        }
+        
+        
+        lcd.clear();
+        getDistance();    ///sensor measure the distance
+        
+        ///print distance measure on the lcd 
+        char buffer [14];
+        int length = sprintf(buffer,"%d cm",distance);
+        if (length<=14)
+        lcd.printString(buffer, 22,1);  //print distance
+        lcd.drawRect(20,6,45,10,0);     //box for value of distance on lcd
+
+        
+        ///if button is pressed, read distance (print car and wall)
+        if (buttonFlag) { //if flag is set = 1
+
+            setTimeFlag = ~setTimeFlag;   //if button is pressed again, back to initial display
+            buttonFlag = 0;    //button flag is set to initial value
+        }
+
+        if (setTimeFlag) {
+             readDistance();  //draw car and obstacle
+            
+
+
+        } else {
+           
+            timeZone();  ///Display time & date to the user
+
+
+        }
+
+    }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.h	Mon May 11 22:12:11 2015 +0000
@@ -0,0 +1,327 @@
+/** 
+@file main.h
+@brief Header file containing functions prototypes, define and global variables
+@brief coding for embedded device (Project A - Reverse Sensor)
+@brief ELEC 2645
+@brief 200906557
+@author Muhammad Muhaimin Mokhtar
+@date May 2015
+*/
+
+//L I B R A R I E S
+#include "mbed.h"
+#include "N5110.h"//Imported from Dr. Craig A. Evans library
+#include "SRF02.h"//Imported from Dr. Craig A. Evans library
+#include "beep.h" //Imported from Peter Descher library, , Files at revision 4:d8e14429a95f
+#include "PowerControl/PowerControl.h" //Imported from Michael Wei's library
+#include "PowerControl/EthernetPowerControl.h"// Imported from Michael Wei's library
+
+//P I N S
+
+/** 
+@namespace N511o lcd
+@brief GPIO pins connected to LCD Display
+@brief (LCD_VCC,SCE,RST,DC,MOSI,SCK,BACKLIGHT)
+*/
+N5110 lcd(p7,p8,p9,p10,p11,p13,p26);
+/**
+@namespace sensor
+@brief GPIO pins for SRF02 sensor
+@brief (SDA,SCL)
+*/
+SRF02 sensor(p28,p27);
+/**
+@namespace red 
+@brief PWM pin for red led
+*/
+PwmOut red(p22);
+/**
+@namespace yellow
+@brief PWM pin for yellow led
+*/
+PwmOut yellow(p23);
+/**
+@namespace green
+@brief PWM pin for green led
+*/
+PwmOut green(p24);
+/**
+@namespace button
+@brief InterruptIn pin for button
+*/
+InterruptIn button(p15);
+/**
+@namespace buzzer 
+@brief PWM pin for buzzer
+*/
+Beep buzzer(p21);
+/** 
+@namespace lcdBrightness
+@brief AnalogIn pin for LCD backlight
+*/
+PwmOut lcdBrightness (p26);
+/**
+@namespace potBrightness
+@brief AnalogIn pin for potentiometer
+*/
+AnalogIn potBrightness (p20);
+
+//V A R I A B L E S
+int distance;              /*!<distance between sensor and obstacles*/     
+int buttonFlag =0;         /*!<print flag set in ISR (Interrupt Service Routine)*/
+int setTimeFlag = 0;       /*!<integer to display time on LCD*/
+int displayReading = 0;    /*!<integer to display measurement on LCD*/
+
+//F U N C T I O N S
+
+/** Print welcome message 
+    * @param message - print 'WELCOME'
+    * @param a - set the coordinate for charachter to be print
+    * @param super - print 'SUPER SENSOR'
+    * @param mokh - print 'M.MOKH'
+    * @param number - print '200906557'
+    */
+void welcomeMessage();
+
+/** measure distance between sensor and obstacle
+  * @param distance - SRF02 measure distance 
+  * @return value of measured distance in cm
+  */
+void getDistance();
+
+/** print car and obstacle figure
+  * @param lcd.drawRect - draw rectangle shape
+  * @param lcd.drawCircle - draw circle shape
+  * @param lcd.printString - print 'DANGER!!' in danger range
+  * @param lcd.refresh - refresh lcd display
+  * @param distanceGreen - green led on
+  * @param distanceYellow - yellow led on
+  * @param distanceRed - red led on
+  */
+void readDistance();
+
+/**
+  * distance measured in green range 
+  * only green led lights up
+  * @param buzzer.beep - buzzer beeping at 1kHz every 1 second
+  * @param buzzer.nobeep - stop the buzzer instantaneous
+  * @param wait - wait for 1.5 seconds
+  */ 
+void distanceGreen();
+
+/**
+  * distance measured in yellow range
+  * only yellow led lights up
+  * @param buzzer.beep - buzzer beeping at 1kHz every 1 second
+  * @param buzzer.nobeep - stop the buzzer instantaneous
+  * @param wait - wait for 1.0 second 
+  */ 
+void distanceYellow();
+
+/**
+  * distance measured in red range
+  * only red led lights up
+  * @param buzzer.beep - buzzer beeping at 1kHz every 1 second
+  * @param buzzer.nobeep - stop the buzzer instantaneous
+  * @param wait - wait for 0.5 second
+  */ 
+void distanceRed();
+
+/**
+  * distance measured in danger range
+  * only red led lights up
+  * @param buzzer.beep - buzzer beeping at 1kHz every 1 second
+  * @param buzzer.nobeep - stop the buzzer instantaneous
+  * @param wait - wait for 0.1 second
+  */ 
+void distanceDanger();
+
+/**
+  *interrupt service routine when button is pressed 
+  * @param buttonFlag - button flag will be set to 1 on rising edge
+  *
+  */
+void buttonPressed();
+
+/**
+  * set time and date display on the lcd 
+  * @param buffer - store current time
+  * @param date - store current date
+  * @param day - store current day
+  * @param lcd.printString - print date & time on lcd 
+  */
+void timeZone();
+
+//print welcome message
+
+void welcomeMessage()
+{
+    int a[12] = {0,6,12,18,24,30,36,42,48,54,60,66};      // coordinate of character to be printed on
+    const char message[7] = {'W','E','L','C','O','M','E'}; 
+    char super[12] = {'S','U','P','E','R',' ','S','E','N','S','O','R'};
+    char mokh[9] = {'M','.','M','O','K','H','T','A','R'};
+    char number[9] = {'2','0','0','9','0','6','5','5','7'};
+    int i;
+    for(i=0; i<7; i++) {
+        lcd.printChar(message[i],a[i],0);  // character is printed one at a time untill increment is satisfied
+        wait(0.1);
+    }
+    for(i=0; i<12; i++) {
+        lcd.printChar(super[i],a[i],2);
+        wait(0.1);                        // character is printed one at a time untill increment is satisfied
+    }
+    for(i=0; i<9; i++) {
+        lcd.printChar(mokh[i],a[i],4);     // character is printed one at a time untill increment is satisfied
+        wait(0.1);
+    }
+    for(i=0; i<9; i++) {
+        lcd.printChar(number[i],a[i],5);   // character is printed one at a time untill increment is satisfied
+        wait(0.1);
+    }
+    wait(4.0);
+}
+
+void getDistance()
+{
+    distance = sensor.getDistanceCm();
+    
+}
+
+void readDistance()
+{
+    if(distance>=240) {
+        lcd.drawRect(0,0,7,48,1); //obstacle (wall)
+        lcd.drawRect(58,30,20,10,1); //rectangle 1(x,y,width,height,blackfill)
+        lcd.drawRect(63,22,10,8,1); //rectangle 2
+        lcd.drawCircle(63,44,4,1); //circle 1
+        lcd.drawCircle(73,44,4,1); //circle 2(x,y,radius,black fill)
+        lcd.refresh();
+        distanceGreen();
+    } else if (distance >= 200 & distance <=239) {
+        lcd.drawRect(0,0,7,48,1);
+        lcd.drawRect(51,30,20,10,1);
+        lcd.drawRect(56,22,10,8,1);
+        lcd.drawCircle(56,44,4,1);
+        lcd.drawCircle(66,44,4,1);
+        lcd.refresh();
+        distanceGreen();
+
+    } else if (distance >=160 & distance <=199) {
+        lcd.drawRect(0,0,7,48,1);
+        lcd.drawRect(44,30,20,10,1);
+        lcd.drawRect(49,22,10,8,1);
+        lcd.drawCircle(49,44,4,1);
+        lcd.drawCircle(59,44,4,1);
+        lcd.refresh();
+        distanceGreen();
+    } else if (distance >=120 & distance <=159) {
+        lcd.drawRect(0,0,7,48,1);
+        lcd.drawRect(37,30,20,10,1);
+        lcd.drawRect(42,22,10,8,1);
+        lcd.drawCircle(42,44,4,1);
+        lcd.drawCircle(52,44,4,1);
+        lcd.refresh();
+        distanceYellow();
+    } else if (distance >=80 & distance <=119) {
+        lcd.drawRect(0,0,7,48,1);
+        lcd.drawRect(30,30,20,10,1);
+        lcd.drawRect(35,22,10,8,1);
+        lcd.drawCircle(35,44,4,1);
+        lcd.drawCircle(45,44,4,1);
+        lcd.refresh();
+        distanceYellow();
+    } else if (distance >=40 & distance <= 79) {
+        lcd.drawRect(0,0,7,48,1);
+        lcd.drawRect(23,30,20,10,1);
+        lcd.drawRect(28,22,10,8,1);
+        lcd.drawCircle(28,44,4,1);
+        lcd.drawCircle(38,44,4,1);
+        lcd.refresh();
+        distanceYellow();
+    } else if (distance >=25 & distance <=39) {
+        lcd.drawRect(0,0,7,48,1);
+        lcd.drawRect(16,30,20,10,1);
+        lcd.drawRect(21,22,10,8,1);
+        lcd.drawCircle(21,44,4,1);
+        lcd.drawCircle(31,44,4,1);
+        lcd.refresh();
+        distanceRed();
+    } else if (distance <=24) { 
+        lcd.drawRect(0,0,7,48,1);
+        lcd.drawRect(9,30,20,10,1);
+        lcd.drawRect(14,22,10,8,1);
+        lcd.drawCircle(14,44,4,1);
+        lcd.drawCircle(24,44,4,1);
+        lcd.printString("DANGER!!",32,5); //'DANGER!!' is printed at par with car figure
+        lcd.refresh();
+        distanceDanger();
+
+
+    }
+}
+
+       // car is in green range distance (safe)
+void distanceGreen()
+{
+    red = 0;
+    yellow = 0;
+    green = 1;          //only green led is lights up
+    buzzer.beep(1000,1);
+    wait (1.5);
+    buzzer.nobeep();
+}
+      //car is in yellow range distance (cautious)
+void distanceYellow()
+{
+    red = 0;
+    yellow = 1;       //only yellow led is lights up
+    green = 0;
+    buzzer.beep(1000,1);
+    wait (1.0);
+    buzzer.nobeep();
+}
+    //when car is in red ange distance (prepare to stop)
+void distanceRed()
+{
+    red = 1;     //only red led is lights up
+    yellow = 0;
+    green = 0;
+    buzzer.beep(1000,1);
+    wait (0.5);
+    buzzer.nobeep();
+}
+
+     //when car is in danger range distance (no longer safe to reverse)
+void distanceDanger()
+{
+    red = 1;    // only red led is lights up
+    yellow = 0;
+    green = 0;
+    buzzer.beep(1000,1);
+    wait (0.1);
+    buzzer.nobeep();
+}
+
+void buttonPressed()
+{
+    buttonFlag = 1; // interrupt service routine
+}
+//display and store time
+void timeZone()
+{
+    
+    time_t seconds = time(NULL); // get current time
+// format time into a string (time and date)
+    char buffer [30];
+    char date [30];
+    char day [30];
+    strftime(buffer, 30 , "%r ", localtime(&seconds));
+    strftime(date, 30, "%F", localtime(&seconds));
+    strftime (day, 30, "%A", localtime(&seconds));
+// print over serial
+    lcd.printString (buffer,10,3);
+    lcd.printString (date,15,4);
+    lcd.printString (day, 25, 5);
+    wait(1.0); // delay for a second
+    lcd.clear();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon May 11 22:12:11 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8ab26030e058
\ No newline at end of file