Mahlet Shimellis Assegahegne / Mbed 2 deprecated ObstacleDetectionDevice

Dependencies:   N5110 SRF02 beep mbed

Files at this revision

API Documentation at this revision

Comitter:
MahletShimellis
Date:
Mon May 11 22:30:17 2015 +0000
Parent:
0:fd19182020c8
Commit message:
Echolocation using Obstacle Detection with Ultrasonic Distance Sensor SRF02

Changed in this revision

main.cpp Show diff for this revision Revisions of this file
main.h Show diff for this revision Revisions of this file
obstacle.cpp Show annotated file Show diff for this revision Revisions of this file
obstacle.h Show annotated file Show diff for this revision Revisions of this file
diff -r fd19182020c8 -r 37d0985c814e main.cpp
--- a/main.cpp	Mon May 11 02:46:35 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,523 +0,0 @@
-
-#include "mbed.h"
-#include "SRF02.h"
-#include "N5110.h"
-#include "beep.h"
-#include "main.h"
-
-
-
-/*PART 1 - Setting up*/
-
-
-void error(int code)
-{
-    while(1) {
-        leds = 0;
-        wait(0.25);
-        leds = code;
-        wait(0.25);
-    }
-}
-/*
-void initTMP102()
-{
-    tmp102.frequency(400000); // set bus speed to 400 kHz
-    int ack; // used to store acknowledgement bit
-    char data[2]; // array for data
-    char reg = CONFIG_REG; // register address
-//////// Read current status of configuration register ///////
-
-    ack = tmp102.write(TMP102_W_ADD,&reg,1); // send the slave write address and the configuration register address
-    if (ack)
-        error(1); // if we don't receive acknowledgement, flash error message
-    ack = tmp102.read(TMP102_R_ADD,data,2); // read default 2 bytes from configuration register and store in buffer
-    if (ack)
-        error(2); // if we don't receive acknowledgement, flash error message
-///////// Configure the register //////////
-// set conversion rate to 1 Hz
-    data[1] |= (1 << 6); // set bit 6
-    data[1] &= ~(1 << 7); // clear bit 7
-
-//////// Send the configured register to the slave ////////////
-
-    ack = tmp102.write(TMP102_W_ADD,&reg,1); // send the slave write address and the configuration register address
-    if (ack)
-        error(3); // if we don't receive acknowledgement, flash error message
-    ack = tmp102.write(TMP102_W_ADD,data,2); // send 2 data bytes to the configuration register
-    if (ack)
-        error(4); // if we don't receive acknowledgement, flash error message
-
-}
-
-float getTemperature()
-{
-    int ack; // used to store acknowledgement bit
-    char data[2]; // array for data
-    char reg = TEMP_REG; // temperature register address
-    ack = tmp102.write(TMP102_W_ADD,&reg,1); // send temperature register address
-    if (ack)
-        error(5); // if we don't receive acknowledgement, flash error message
-    ack = tmp102.read(TMP102_R_ADD,data,2); // read 2 bytes from temperature register and store in array
-    if (ack)
-        error(6); // if we don't receive acknowledgement, flash error message
-    temperature = (data[0] << 4) | (data[1] >> 4);
-    return temperature*0.0625;
-}
-
-float calcSoundSpeed(float temperature)
-{
-    return soundSpeed = temperature*0.6 + 331.3;
-}
-
-float calcSoundTimeDelay (int distance, float soundSpeed)
-{
-    return soundTimeDelay = distance/soundSpeed;
-}
-
-*/
-void measureExpired()
-{
-    measureFlag =1;
-}
-
-////////*PART 2 - Distance Upadate and Speed *///////////
-
-
-void updateExpired()
-{
-    updateFlag=1;
-}
-
-void update_distance_new()
-{
-    lastDistance = newDistance; ///updates the lastDistance variable by storing into it the previous distacne measurement
-    newDistance = srf.getDistanceCm();///updates the newDistance variable by adding to it the new distance measurement
-}
-
-
-/////////*PART 3 - Distance Range Alert*/////////////
-
-void rangeExpired()
-{
-    rangeFlag =1;
-}
-
-struct State {
-    float bOutput; // buzzer output value
-    int nextState[5]; // array of next states
-};
-typedef const struct State STyp;
-
-STyp fsm[5] = {
-    {8000,{0,1,2,3,4}}, // State 0 - person stops, stop sound from buzzer output ideally for 5 seconds to detect the area
-    {2000,{0,1,2,3,4}}, // 1 - turn/rotate sound that advices the person to rotate by 180 degress to better detect the area and obstacle locations
-    {1000,{0,1,2,3,4}}, // 2 - turn right sound- for obstacle located on the left
-    {500,{0,1,2,3,4}}, // 3 - turn right and move forward sound as long as a new obstacle is not detected then stop
-    {200,{0,1,2,3,4}}, // 4 - turn left sound - for obstacle located on the right
-
-};
-
-void updateState()
-{
-    //  int rangeState;
-    if(distance<=20) rangeState=0;
-    else if((distance>20)&&(distance<=65))rangeState=1;
-    else if ((distance>65)&&(distance<=110))rangeState=2;
-    else if ((distance>110)&&(distance<=155))rangeState=3;
-    else if ((distance>155)&&(distance<=200))rangeState=4;
-
-    currentState = fsm[currentState].nextState[rangeState];
-}
-
-///////*PART 4 - Beam Pattern hard */////
-
-
-
-
-
-
-
-///////*PART 5 - the Wall Follower Simulation *//////
-
-void wallExpired()
-{
-    wallFlag=1;
-}
-
-
-void moveForward()
-{
-// sets pixel to move forward
-    // k++;
-    //if (k>=22) k=0;
-    for(int k=0; k<=22; k++) {
-        lcd.setPixel(16,k);  // x,y,radius,black fill
-        wait(0.2);
-        pix++;
-        lcd.refresh();
-    }
-    //lcd.refresh();
-}
-
-void turnLeftForward_one()
-{
-// turn left forward
-    //l++;
-    //if (l>=64) l=0;
-    for(int l=0; l<=64; l++) {
-        lcd.setPixel(l+16,22);  // x,y,radius,black fill
-        wait(0.2);
-        pix=pix+1;
-        lcd.refresh();
-    }
-    //lcd.refresh();
-}
-
-void turnLeftForward_two()
-{
-//turn right forward one
-    //m++;
-    //if (m>=16) m=0;
-    for (int m=0; m<=16; m++) {
-        lcd.setPixel(80,m+22);  // x,y,radius,black fill
-        wait(0.2);
-        pix=pix+1;
-        lcd.refresh();
-    }
-    //lcd.refresh();
-}
-
-void turnRightForward()
-{
-//turn right forward two
-    //n++;
-    //if (n>=78) n=0;
-    for(int n=0; n<=78; n++) {
-        lcd.setPixel(80-n,38);
-        wait(0.2);
-        pix=pix+1;
-        lcd.refresh();
-    }
-    //lcd.refresh();
-}
-
-
-//intial beep zero move forward
-void beep_zero()
-{
-    int sound_zero = 200;
-    float time_zero = 0.22; //rectangle two width + 2 pixels
-    buzzer.beep(sound_zero,time_zero); //fix time ***
-
-}
-
-//turns on beep one Turn Left
-void beep_one()
-{
-    int sound_one = 600;
-    float time_one = 0.2;
-    buzzer.beep(sound_one,time_one); //fix time ***
-}
-
-//waits two seconds and turns on beep two Trun Left and move Forward (2= 1+0)
-void beep_two()
-{
-    int sound_two = 800;
-    float time_two = 0.23; //2+19+2
-    buzzer.beep(sound_two,time_two); //fix time ***
-}
-
-//turns on beep three Turn Right
-void beep_three()
-{
-    int sound_three = 1600;
-    float time_three = 0.2;
-    buzzer.beep(sound_three,time_three); //fix time ***
-}
-
-//waits two seconds and turns on beep four Turn Right and move Forward (4= 3+0)
-void beep_four()
-{
-    int sound_four = 2000;
-    float time_four = 0.14; //2+10+2
-    buzzer.beep(sound_four,time_four); //fix time ***
-}
-
-//waits 40ms and turns on beep five Stop Dead End
-void beep_five()
-{
-    int sound_five = 2600;
-    float time_five = 0.6;
-    buzzer.beep(sound_five,time_five); //fix time ***
-}
-
-void toggle_red()
-{
-    red=!red;
-}
-void toggle_yellow()
-{
-    yellow=!yellow;
-}
-void toggle_green()
-{
-    green=!green;
-}
-void move()
-{
-
-    if (pix<=22) {
-        lcd.printString(" Forward ",32,0);
-        beep_ticker_zero.attach(&beep_zero, 0.61); //move forward
-        toggle_green_ticker.attach(&toggle_green, 0.61);
-        moveForward();
-
-
-    }
-    beep_ticker_zero.detach();
-    beep_ticker_one.attach(&beep_one, 0.2);//turn left
-    lcd.printString(" T Left ",32,0);
-    toggle_green_ticker.detach();
-    toggle_red_ticker.attach(&toggle_red,0.1);
-    wait(0.5);
-    beep_ticker_one.detach();
-    //  toggle_red_ticker.detach();
-    if (22<pix && pix<86) {
-        toggle_red_ticker.detach();
-        lcd.printString(" Forward ",32,0);
-        beep_ticker_two.attach(&beep_two, 0.66); //turn left and move forward
-        toggle_green_ticker.attach(&toggle_green, 0.66);
-        turnLeftForward_one();
-    }
-    beep_ticker_two.detach();
-    beep_ticker_three.attach(&beep_three,0.2);//turn right
-    lcd.printString(" T Right ",32,0);
-    toggle_green_ticker.detach();
-    toggle_red_ticker.attach(&toggle_red,0.1);
-    wait(0.5);
-    beep_ticker_three.detach();
-    //toggle_red_ticker.detach();
-    if(86<pix && pix<102) {
-        toggle_red_ticker.detach();
-        lcd.printString(" Forward ",32,0);
-        toggle_green_ticker.attach(&toggle_green, 0.76);
-        beep_ticker_four.attach(&beep_four, 0.76);//turn right and move forward
-        turnLeftForward_two();
-
-    }
-    beep_ticker_four.detach();
-    beep_ticker_three.attach(&beep_three,0.2);//turn right
-    lcd.printString(" T Right ",32,0);
-    toggle_red_ticker.attach(&toggle_red,0.1);
-    wait(0.5);
-    beep_ticker_three.detach();
-    //toggle_red_ticker.detach();
-    if (102<pix) {
-        toggle_red_ticker.detach();
-        beep_ticker_four.attach(&beep_four,0.8);//turn right and move forward
-        toggle_green_ticker.attach(&toggle_green, 0.76);
-        lcd.printString(" Forward ",32,0);
-        turnRightForward();
-
-    }
-    beep_ticker_four.detach();
-    toggle_green_ticker.detach();
-    lcd.printString("  STOP!! ",32,0);
-    toggle_red_ticker.attach(&toggle_red,0.1);
-    beep_ticker_five.attach(&beep_five,0.8);//stop dead end
-}
-
-void drawMaze() // draws rectangle one bottom left
-{
-    lcd.drawRect(0,0,12,25,1);  // filled black rectangle
-    //draws rectangle two bottom right
-    lcd.drawRect(20,0,10,20,1);
-    lcd.drawRect(30,10,52,10,1);
-    // draws rectangle three top left
-    lcd.drawRect(0,25,76,10,1);
-    //draws rectangle four top final
-    lcd.drawRect(0,40,80,1,1);
-    //draws small rectangle top end
-    lcd.drawRect(0,36,1,4,1);
-    lcd.refresh();
-}
-/*
-InterruptIn button(p16);
-int buttonCounter = 0;
-
-void manageScreen()
-{
-    if ( buttonCounter > 4) {
-
-        buttonCounter = 0;
-
-    }
-
-
-    if ( buttonCounter == 0) {
-
-        measureFlag = !measureFlag;
-
-
-
-    } else if ( buttonCounter == 1) {
-
-        buttonFlag = !buttonFlag;
-
-
-
-    } else if ( buttonCounter == 2) {
-
-        updateFlag = !updateFlag;
-
-
-    } else if ( buttonCounter == 3) {
-
-        rangeFlag = !rangeFlag;
-
-
-
-    } else if ( buttonCounter == 4) {
-
-        beamFlag = !beamFlag;
-
-
-
-
-    } else {
-
-        wallFlag = !wallFlag;
-
-
-
-    }
-
-
-    if(measureFlag == 1) {
-
-    } else {
-
-    }
-
-    if(buttonFlag == 1) {
-
-    } else {
-
-    }
-
-    if(updateFlag == 1) {
-        update_ticker.attach(&updateExpired,1.0);
-    } else {
-        update_ticker.detach();     // detach ticker
-    }
-
-    if(rangeFlag == 1) {
-
-    } else {
-
-    }
-
-
-    if(beamFlag == 1) {
-
-    } else {
-
-    }
-
-    if(wallFlag == 1) {
-
-    } else {
-
-    }
-
-
-
-    buttonCounter++;
-}
-*/
-int main()
-{
-    lcd.init();
-
-// these are default settings so not strictly needed
-    lcd.normalMode();      /// normal colour mode
-    lcd.setBrightness(0.5); /// put LED backlight on 50%
-
-    measure.attach(&measureExpired,0.5);
-    update_ticker.attach(&updateExpired,1.0);
-    while(1) {
-        if(measureFlag) {
-            lcd.clear();
-            measureFlag =0;
-
-            char buffer[14];
-
-            distance = srf.getDistanceCm();  /// same idea with floats
-            int length = sprintf(buffer,"D = %d cm",distance);
-            if (length <= 14)
-                lcd.printString(buffer,0,4);
-
-            /*   temperature = getTemperature();
-               int lengthT = sprintf(buffer,"T = %.2f C",temperature); /// print formatted data to buffer
-               if (lengthT <= 14)  /// if string will fit on display
-                   lcd.printString(buffer,0,5);
-
-               soundSpeed = calcSoundSpeed(temperature);
-               soundTimeDelay = calcSoundTimeDelay(distance, soundSpeed); */
-        }
-        lcd.refresh();
-
-
-        if(updateFlag) {
-            lcd.clear();
-            updateFlag=0;
-            char bufferOne[14]; ///character array that stores the values of the newDistance variable
-            char bufferTwo[14];///character array that stores the values of the lastDistance variable
-
-
-            int lengthN = sprintf(bufferOne,"Dn = %d cm",newDistance);
-            if (lengthN <= 14)
-                lcd.printString(bufferOne,0,4);
-
-            int lengthL = sprintf(bufferTwo,"Dl = %d cm",lastDistance);
-            if (lengthL <= 14)
-                lcd.printString(bufferTwo,0,5);
-        }
-        lcd.refresh();
-
-        if (rangeFlag) {
-            lcd.clear();
-            rangeFlag=0;
-            char buffer[14];
-
-            distance = srf.getDistanceCm();  // same idea with floats
-            int length = sprintf(buffer," %d cm",distance);
-            if (length <= 14) {
-                lcd.printString(buffer,11,2);
-            }
-
-            buzzerFrequency=fsm[currentState].bOutput;
-            buzzer.beep(buzzerFrequency,1);
-            int lengthB = sprintf(buffer," %.2f hz",buzzerFrequency);
-            if (lengthB <= 14) {
-                lcd.printString(buffer,11,4);
-            }
-
-            lcd.refresh();
-
-        }
-
-        if (beamFlag) {
-
-        }
-
-        if (wallFlag) {
-
-        }
-
-    }
-}
-
-
-/*PART 2 - Distance Upadate and Speed */
\ No newline at end of file
diff -r fd19182020c8 -r 37d0985c814e main.h
--- a/main.h	Mon May 11 02:46:35 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,377 +0,0 @@
-
-
-
-
-/*PART 1 - Setting up*/
-//define temperature registers
-
-//variables distance, temperature, time delay, speed of sound
-
-//distance measurement setting functions
-
-//temperature measurement setting functions
-
-//speed of sound measurement setting fucntions
-
-//
-
-/**
-@file main.h
-@brief header file containing function prototypes, defines and variables
-@brief shows the different applications of the ultrasonic distance sensor combined with a temperature sensor
-@brief Last Revision combining all of the previous trials
-@author Mahlet Shimellis
-@date April-March 2015
-*/
-
-#ifndef MAIN_H
-#define MAIN_H
-
-/**
-@brief Below is the list of temperature sensor register adresses used
-@brief the first two are read and write adresses when ADD0 is connected to GROUND
-@brief the last two are common temerature registers
-*/
-
-#define TMP102_R_ADD 0x91
-#define TMP102_W_ADD 0x90
-#define TEMP_REG 0x00
-#define CONFIG_REG 0x01
-
-#include "mbed.h"
-
-/**
-@namespace leds
-@brief This defines the mbed leds taht will be useful to detect error messages
-*/
-BusOut leds(LED4,LED3,LED2,LED1);
-
-/**
-@namespace lcd
-@brief  LCD dispaly pin connections to the mbed
-@brief Format used N5110(PinName pwrPin, PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin, PinName ledPin)
-*/
-N5110 lcd(p5,p6,p7,p8,p11,p13,p21);
-
-/**
-@namespace buzzer
-@brief Buzzer connection to mbed
-*/
-Beep buzzer(p26);
-
-/**
-@namespace srf
-@brief SRF02 ultrasonic distance sensor I2C connection to mbed
-@brief Format srf(SDA pin, SCL pin)
-*/
-SRF02 srf(p28, p27);
-
-/**
-@namespace tmp102
-@brief TMP102 temperature sensor I2C connection to mbed
-@brief format tmp102(SDA pin, SCL pin)
-*/
-///I2C tmp102(p9,p10);
-
-/**
-@namespace red
-@brief Red  LED PwmOut connection to mbed
-*/
-PwmOut red(p24);
-
-/**
-@namespace yellow
-@brief Yellow LED PwmOut connection to mbed
-*/
-PwmOut yellow(p23);
-
-/**
-@namespace green
-@brief Green LED PwmOut connection to mbed
-*/
-PwmOut green(p22);
-Ticker measure;
-int measureFlag=0; /*!< measure flag set in ISR for intial temperature and distance measurements  ??? ticker timer */
-int distance=0; /*!< distance value updated from SRF02 measurements */
-float temperature; /*!<temperature value updated from TMP102 measurements*/
-int soundSpeed;
-int soundTimeDelay;
-
-/**
-@brief defines the high flag state for the measurement flag
-*/
-void measureExpired ();
-
-/**
-@brief sets the error signaling for the mbed connections mainly I2C when the acknowlegment bit is not received
-@param code - integer to classify error type
-*/
-void error(int code);
-
-
-
-
-/**
-@brief this function initialises the temperature sensor
-*/
-void initTMP102();
-
-/**
-@brief this function performs the temperature measurement
-@returns the temperature value with a 0.0625 resolution
-*/
-float getTemperature();
-
-
-/**
-@brief this funciton calculates the speed of sound from the measured temperature
-@param temperature - float measured temperature value
-@returns the value of the speed of sound for each specific temeprature value
-*/
- float calcSoundSpeed (float temperature);
-
-
-/**
-@brief this function calculates the delay between transmission and emission of the sound from the ultrasonic distance sensor
-@param distance - integer measured distance value
-@param soundSpeed - float calculated speed of sound value
-@returns timeDelay - float delay between transmission and reception of the sound after reflecting on the object for which the distance has been measured
-*/
-float calcSoundTimeDelay (int distance, float soundSpeed);
-
-
-
-/*PART 2 - Distance Upadate and Speed */
-
-//variables**
-
-//ticker variable
-
-//timer expired function   TIMER ONE*****
-
-//distance update and storage function
-
-//mostly main
-
-
-Ticker update_ticker;
-Timer update;
-int updateFlag=0;
-int u=0;
-int newDistance=0; /*!< new distance value updated from SRF02 measurements after each timer delay */
-int lastDistance=0;/*!< for eaxh new distance value updated from SRF02 measurements after each timer delay, this is the stored previous distance value */
-float updateDelay=0; /*!< time delay between each distance value update */
-
-
-///Ticker update_ticker;
-//Ticker timer;
-
-/**
-@brief defines the high flag state for the distance measurement update flag
-*/
-void upadteExpired();
-
-/**
-@brief this function stores the previous distance in the lastDistance variable and updates the newDistance variable
-@returns the lastDistance value of the previous measurement
-@returns the newDistance value from the new measurement
-*/
-void update_distance_new();
-
-
-/*PART 3 - Distance Range Alert*/
-
-//define min, max, maxState
-
-//define variables
-
-//define structure
-
-//update input function
-
-//buzzer frequency function returns float
-
-//main and while
-
-#define MAX 200
-#define MIN 20
-#define maxState 4
-
-/**
-@brief Timing elements for the range differentiation module of the distance sensor
-*/
-Ticker range_ticker; 
-Timer range;
-int rangeFlag =0; /*!< range flag set in ISR */
-
-int currentState =0; /*!<integer from 0 to 4 that defines the current state of the FSM*/
-int rangeState =0; /*!<integer from 0 to 4 that defines the range to which belongs the measured distance between MIN and MAX*/
-
-float buzzerFrequency =0; /*!<float that defines the frequency of the buzzer depending on the distance range. higher frequencies as we get closer to the object. output of the FSM structure*/
-
-/**
-@brief defines the high flag state for the measurement flag
-*/
-void rangeExpired();
-
-/**
-@brief function that defines the input of the FSM depending on the distance range from MAX to MIN
-@param distance - integer measured value by the SRF02 sensor and to be classified as part of a set of five ranges from MAX to MIN
-@returns rangeState - integer from 0 to 4. defined depending on the distance range in whcih the measured distance belongs
-@returns currentState - integer from 0 to 4. depending on the value of the rangeState, the actual current state and the FSM nextState from the structure definition
-*/
-void updateState();
-
-
-/*PART 4 - Beam Pattern hard */
-//introduce angle array
-
-//convert degrees function
-
-//drawLine
-
-//drawRadius
-
-//add string-- 'please wait, ranging'
-
-
-int beamFlag=0;
-void beamExpired();
-
-
-
-/*PART 5 - the Wall Follower Simulation */
-//tickers for buzzer
-
-//tickers for LEDs
-
-//variables for sound
-
-//variables for counters
-
-//timer expired funcion  -not used actually- TIMER TWO
-
-//buzzer funcitons
-
-//movement functions
-
-//LED functions
-
-//main draw rect import from nokia library
-
-
-int wallFlag=0;
-Timer wall_timer;
-Ticker wall_ticker;
-void wallExpired();
-
-/**
-@brief set of buzzer tickers depending on the direction of movement and signal given 
-@brief zero move forward
-@brief one turn left
-@brief two turn left and move forward
-@brief three turn right
-@brief four turn right and move forward
-@brief five stop, dead end
-*/
-Ticker beep_ticker_zero;
-Ticker beep_ticker_one;
-Ticker beep_ticker_two;
-Ticker beep_ticker_three;
-Ticker beep_ticker_four;
-Ticker beep_ticker_five;
-
-
-/**
-@brief set of LED tickers
-*/
-Ticker toggle_green_ticker;
-Ticker toggle_yellow_ticker;
-Ticker toggle_red_ticker;
-
-
-/**
-@brief set of integer pixel counters to define and kepp track of the movement along the maze
-*/
-int k=0; /*!<integer for stage 0 move forward k from 0 to 22 pixel points*/
-int l=0;/*!<integer for stage 1 turn left and move forward one l from 0 to 64 pixel points*/
-int m=0;/*!<integer for stage 2 turn left and move forward two m from 0 to 16 pixel points*/
-int n=0;/*!<integer for stage 3 turn right and move forward n from 0 to 78 pixel points*/
-int pix=0;/*!<integer that keeps track of the sum of all the counter integers as the pixel moves along the maze. helps keep track of the location of the pixel */
-
-void moveForward();
-
-void turnLeftForward_one();
-
-void turnLeftForward_two();
-
-void turnRightForward();
-
-/**
-@brief function that controls intial beep zero move forward
-*/
-void beep_zero();
-
-/**
-@brief function that turns on beep one Turn Left
-*/
-void beep_one();
-
-/**
-@brief function that turns on beep two Trun Left and move Forward 
-*/
-void beep_two();
-/**
-@brief function that turns on beep three Turn Right
-*/
-void beep_three();
-
-/**
-@brief function that turns on beep four Trun Right and move Forward 
-*/
-void beep_four();
-
-/**
-@brief function that turns on beep five Stop Dead End
-*/
-void beep_five();
-
-
-/**
-@brief funciton that toggles Red LED
-@brief controls PwmOut pin
-*/
-void toggle_red();
-
-/**
-@brief funciton that toggles Yellow LED
-@brief controls PwmOut pin
-*/
-void toggle_yellow();
-
-/**
-@brief funciton that toggles Green LED
-@brief controls PwmOut pin
-*/
-void toggle_green();
-
-/**
-@brief function that controls the pixel movement along the maze
-@brief combines all of the different stages/sub-movements
-@brief combines the buzzer and led tickers for appropriate and timely signaling
-@param pix - integer that sums the movement cnouters and gives an idea of the location of the pixel
-@returns buzzer sound - output sound signal with frequency depending on the location
-@returns LED light - output light signal with color dependent on message/location (go forward, stop etc.)
-*/
-void move();
-
-/**
-@brief function that draws the sample structure of the maze to reflect the wall follower movement technique
-@brief combines drawRect functions with pre-set dimensions
-@param origin, width, height
-*/
-void drawMaze();
-
-
-
-#endif
diff -r fd19182020c8 -r 37d0985c814e obstacle.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/obstacle.cpp	Mon May 11 22:30:17 2015 +0000
@@ -0,0 +1,578 @@
+/**
+@file obstacle.cpp
+@brief Program Implementation
+*/
+
+#include "mbed.h"
+#include "SRF02.h"
+#include "N5110.h"
+#include "beep.h"
+#include "obstacle.h"
+
+
+//////////////////////////PART 1 - SETTING UP THE MEASUREMENTS//////////////////////////////
+
+int timerFlag=0;
+void timerExpired()
+{
+    timerFlag =1;
+}
+
+void error(int code)
+{
+    while(1) {
+        leds = 0;
+        wait(0.25);
+        leds = code;
+        wait(0.25);
+    }
+}
+
+void measureExpired()
+{
+    measureFlag =1;
+}
+
+
+/*
+void initTMP102()
+{
+    tmp102.frequency(400000); // set bus speed to 400 kHz
+    int ack; // used to store acknowledgement bit
+    char data[2]; // array for data
+    char reg = CONFIG_REG; // register address
+//////// Read current status of configuration register ///////
+
+    ack = tmp102.write(TMP102_W_ADD,&reg,1); // send the slave write address and the configuration register address
+    if (ack)
+        error(1); // if we don't receive acknowledgement, flash error message
+    ack = tmp102.read(TMP102_R_ADD,data,2); // read default 2 bytes from configuration register and store in buffer
+    if (ack)
+        error(2); // if we don't receive acknowledgement, flash error message
+///////// Configure the register //////////
+// set conversion rate to 1 Hz
+    data[1] |= (1 << 6); // set bit 6
+    data[1] &= ~(1 << 7); // clear bit 7
+
+//////// Send the configured register to the slave ////////////
+
+    ack = tmp102.write(TMP102_W_ADD,&reg,1); // send the slave write address and the configuration register address
+    if (ack)
+        error(3); // if we don't receive acknowledgement, flash error message
+    ack = tmp102.write(TMP102_W_ADD,data,2); // send 2 data bytes to the configuration register
+    if (ack)
+        error(4); // if we don't receive acknowledgement, flash error message
+
+}
+
+float getTemperature()
+{
+    int ack; // used to store acknowledgement bit
+    char data[2]; // array for data
+    char reg = TEMP_REG; // temperature register address
+    ack = tmp102.write(TMP102_W_ADD,&reg,1); // send temperature register address
+    if (ack)
+        error(5); // if we don't receive acknowledgement, flash error message
+    ack = tmp102.read(TMP102_R_ADD,data,2); // read 2 bytes from temperature register and store in array
+    if (ack)
+        error(6); // if we don't receive acknowledgement, flash error message
+    temperature = (data[0] << 4) | (data[1] >> 4);
+    return temperature*0.0625;
+}
+
+float calcSoundSpeed(float temperature)
+{
+    return soundSpeed = temperature*0.6 + 331.3;
+}
+
+float calcSoundTimeDelay (int distance, float soundSpeed)
+{   distance =srf.getDistanceCm();
+    return soundTimeDelay = distance/soundSpeed;
+}
+*/
+
+
+///////////////////PART 2 - Distance Upadate and Speed //////////////////////
+
+
+void updateExpired()
+{
+    updateFlag=1;    ///
+}
+
+void update_distance_new()
+{
+    lastDistance = newDistance; ///updates the lastDistance variable by storing into it the previous distance measurement
+    newDistance = srf.getDistanceCm();///updates the newDistance variable by adding to it the new distance measurement
+}
+
+
+///////////////////PART 3 - Distance Range Alert//////////////////////////////
+
+void rangeExpired()
+{
+    rangeFlag =1;
+}
+
+struct State {
+    float bOutput; /// buzzer output value
+    int nextState[5]; /// array of next states
+};
+typedef const struct State STyp;
+
+STyp fsm[5] = {
+    {8000,{0,1,2,3,4}}, // State 0 - object at less than 20 cm away
+    {2000,{0,1,2,3,4}}, // 1 - object in the 20-65cm range from the person
+    {1000,{0,1,2,3,4}}, // 2 - object in the 65-110cm range from the person
+    {500,{0,1,2,3,4}}, // 3 - object in the 110-155cm range from the person
+    {200,{0,1,2,3,4}}, // 4 - object in the 155-200cm range from the person
+
+};
+
+void updateState()
+{
+
+    distance = srf.getDistanceCm();
+    if(distance<=20) rangeState=0;
+    else if((distance>20)&&(distance<=65))rangeState=1;
+    else if ((distance>65)&&(distance<=110))rangeState=2;
+    else if ((distance>110)&&(distance<=155))rangeState=3;
+    else if ((distance>155)&&(distance<=200))rangeState=4;
+
+
+    currentState = fsm[currentState].nextState[rangeState];
+}
+
+///////////////////PART 4 - Beam Pattern ///////////////////////////////////
+
+double angleArray[5]= {0,10,20,30,40}; /*!<array of angles from the center of the sensor*/
+
+
+void beamExpired()
+{
+    beamFlag=1;
+}
+
+double convertDegrees(double angleDegrees)
+{
+     ///uses equivalence of 2pi and 180 degrees
+    return angleDegrees*3.16/180;     
+}
+
+void drawSemiCircle()
+{
+//draws a semi circle on the screen of radius equal to the distance from the object
+    int radius = srf.getDistanceCm(); /// int radius = ((30*srf.getDistanceCm())/20); other possibility
+    lcd.drawCircle(WIDTH/2,1,radius,0);  /// x,y,radius,transparent with outline
+    lcd.drawLine(WIDTH/2,1,WIDTH/2,radius,2); ///draws one diameter
+    lcd.refresh();
+}
+
+void drawBeamLines()
+{
+///draws a beam line for each calcualted value
+    lcd.drawLine(WIDTH/2,1,WIDTH/2+l,h,2);
+    lcd.drawLine(WIDTH/2,1,WIDTH/2-l,h,2);
+    lcd.refresh();
+}
+
+double lat(double a, double d)
+{
+    return (tan(a) *d);
+}
+
+double hyp(double a, double d)
+{
+    return ((tan(a) *d)/sin(a));
+}
+
+/////////////////////////PART 5 - the Wall Follower Simulation //////////////////////
+
+void wallExpired()
+{
+    wallFlag=1;
+}
+
+void moveForward()
+{
+/// sets pixel to move forward
+
+    for(int k=0; k<=22; k++) {
+        lcd.setPixel(16,k);  /// (x,y) starting point of the pixel - here fixed x coordinate - vertical movement
+        wait(0.2);  ///can be considered as the "speed of the movement" because it defines the rate if change of pixel - delay between two k values
+        pix++;  ///increments the pix vlaue for each increase in k
+        lcd.refresh();
+    }
+}
+
+void turnLeftForward_one()
+{
+///sets the pixel to turn left forward
+
+    for(int l=0; l<=64; l++) {
+        lcd.setPixel(l+16,22);  /// (x,22) starting point of the pixel - here fixed y coordinate - horizontal movement
+        wait(0.2);
+        pix=pix+1; ///increments the pix vlaue for each increase in l
+        lcd.refresh();
+    }
+
+}
+
+void turnLeftForward_two()
+{
+///sets the pixel to turn right forward -one
+
+    for (int m=0; m<=16; m++) {
+        lcd.setPixel(80,m+22);  /// (80,y) starting point of the pixel - here fixed x coordinate - vertical movement
+        wait(0.2);
+        pix=pix+1; ///increments the pix vlaue for each increase in m
+        lcd.refresh();
+    }
+
+}
+
+void turnRightForward()
+{
+///sets the pixel to turn right forward -two
+
+    for(int n=0; n<=78; n++) {
+        lcd.setPixel(80-n,38);  /// (x,38) starting point of the pixel - here fixed y coordinate - horizontal movement- x=80-n because counting down from the end x=80 to he beginning x=2 of the screen
+        wait(0.2);
+        pix=pix+1; ///increments the pix vlaue for each increase in n
+        lcd.refresh();
+    }
+    //lcd.refresh();
+}
+
+
+///intial beep zero move forward
+void beep_zero()
+{
+    int sound_zero = 200; /// local varaible integer gives specific frequency value for the buzzer
+    float time_zero = 0.22; /// local varaible integer gives specific time for the buzzer
+    buzzer.beep(sound_zero,time_zero);
+
+}
+
+///turns on beep one Turn Left
+void beep_one()
+{
+    int sound_one = 600;
+    float time_one = 0.2;
+    buzzer.beep(sound_one,time_one);
+}
+
+/// turns on beep two Trun Left and move Forward
+void beep_two()
+{
+    int sound_two = 800;
+    float time_two = 0.23;
+    buzzer.beep(sound_two,time_two);
+}
+
+//turns on beep three Turn Right
+void beep_three()
+{
+    int sound_three = 1600;
+    float time_three = 0.2;
+    buzzer.beep(sound_three,time_three);
+}
+
+/// turns on beep four Turn Right and move Forward
+void beep_four()
+{
+    int sound_four = 2000;
+    float time_four = 0.14;
+    buzzer.beep(sound_four,time_four);
+}
+
+/// turns on beep five Stop Dead End
+void beep_five()
+{
+    int sound_five = 2600;
+    float time_five = 0.6;
+    buzzer.beep(sound_five,time_five);
+}
+
+void toggle_red()
+{
+    red=!red; ///toggle red led
+}
+void toggle_yellow()
+{
+    yellow=!yellow;  ///toggles yellow led
+}
+void toggle_green()
+{
+    green=!green;  ///toggles green led
+}
+
+
+
+void move()
+{
+    if (pix<=22) {
+        lcd.printString(" Forward ",32,0);
+        beep_ticker_zero.attach(&beep_zero, 0.61); //move forward
+        toggle_green_ticker.attach(&toggle_green, 0.61);
+        moveForward();
+    }
+
+    beep_ticker_zero.detach();
+    beep_ticker_one.attach(&beep_one, 0.2);//turn left
+    lcd.printString(" T Left ",32,0);
+    toggle_green_ticker.detach();
+    toggle_red_ticker.attach(&toggle_red,0.1);
+    wait(0.5);
+    beep_ticker_one.detach();
+   
+
+    if (22<pix && pix<86) {
+        toggle_red_ticker.detach();
+        lcd.printString(" Forward ",32,0);
+        beep_ticker_two.attach(&beep_two, 0.66); //turn left and move forward
+        toggle_green_ticker.attach(&toggle_green, 0.66);
+        turnLeftForward_one();
+    }
+
+    beep_ticker_two.detach();
+    beep_ticker_three.attach(&beep_three,0.2);//turn right
+    lcd.printString(" T Right ",32,0);
+    toggle_green_ticker.detach();
+    toggle_red_ticker.attach(&toggle_red,0.1);
+    wait(0.5);
+    beep_ticker_three.detach();
+    
+
+    if(86<pix && pix<102) {
+        toggle_red_ticker.detach();
+        lcd.printString(" Forward ",32,0);
+        toggle_green_ticker.attach(&toggle_green, 0.76);
+        beep_ticker_four.attach(&beep_four, 0.76);//turn right and move forward
+        turnLeftForward_two();
+    }
+
+    beep_ticker_four.detach();
+    beep_ticker_three.attach(&beep_three,0.2);//turn right
+    lcd.printString(" T Right ",32,0);
+    toggle_red_ticker.attach(&toggle_red,0.1);
+    wait(0.5);
+    beep_ticker_three.detach();
+   
+
+    if (102<pix) {
+        toggle_red_ticker.detach();
+        beep_ticker_four.attach(&beep_four,0.8);///turn right and move forward- function called every 0.8s
+        toggle_green_ticker.attach(&toggle_green, 0.76); /// toggle green led function called every 0.76s
+        lcd.printString(" Forward ",32,0);
+        turnRightForward();
+    }
+
+    beep_ticker_four.detach();
+    toggle_green_ticker.detach();
+    lcd.printString("  STOP!! ",32,0);
+    toggle_red_ticker.attach(&toggle_red,0.1);
+    beep_ticker_five.attach(&beep_five,0.8);//stop dead end
+}
+
+void drawMaze()
+{
+    lcd.drawRect(0,0,12,25,1);  /// top left filled rectangle-green on report
+    lcd.drawRect(20,0,10,20,1); /// top middle filled rectangle-orange on report
+    lcd.drawRect(30,10,52,10,1); /// top right filled rectangle-pink on report
+    lcd.drawRect(0,25,76,10,1); /// middle filled rectangle-purple on report
+    lcd.drawRect(0,40,80,1,1); /// bottom filled rectangle-red on report
+    lcd.drawRect(0,36,1,4,1); /// dead end small filled rectangle-black on report
+    lcd.refresh();
+}
+
+///////////////////////////////Transitions/User interface (button) selection and event order elements//////////////////////////////////
+
+void buttonPressed()
+{
+    buttonFlag++;  ///increments and keepd the value of the buttonFlag counter for every button press
+    if ( buttonFlag > 4) {  /// sets the limit value of the buttonFlag before going back to zero => five different flag states to be used for the five different modules
+        buttonFlag = 0;
+    }
+}
+
+
+void manageScreen()
+{
+    if ( buttonFlag== 0) {
+        measureFlag = !measureFlag; /// toggles measureFlag - if the flag is intially low then it goes high for buttonFlag = 0 - first screen view
+    }
+    if ( buttonFlag == 1) {
+        updateFlag = !updateFlag; /// toggles updateFlag - if the flag is intially low then it goes high for buttonFlag = 1 - first button press - second screen view
+    }
+    if ( buttonFlag == 2) {
+
+        rangeFlag = !rangeFlag;  /// toggles rangeFlag - if the flag is intially low then it goes high for buttonFlag = 2 - second button press - third screen view
+    }
+    if ( buttonFlag == 3) {
+        beamFlag = !beamFlag;  /// toggles beamFlag - if the flag is intially low then it goes high for buttonFlag = 3 - third button press - fourth screen view
+    }
+    if ( buttonFlag == 4) {
+        wallFlag = !wallFlag;  /// toggles wallFlag - if the flag is intially low then it goes high for buttonFlag = 4 - fourth button press - fifth screen view
+    }
+
+    if(measureFlag == 1) {
+        measure_ticker.attach(&update_distance_new,1.0);
+        //  temperature_ticker.attach(&getTemperature,1.0);
+    } else {
+        measure_ticker.detach();
+    }
+
+    if(updateFlag == 1) {
+
+        update_ticker.attach(&updateExpired,2.0);
+
+    } else {
+        update_ticker.detach();     // detach ticker
+    }
+
+    if(rangeFlag == 1) {
+        range_ticker.attach(&rangeExpired,3.0);
+    } else {
+        range_ticker.detach();
+    }
+
+    if(beamFlag == 1) {
+        beam_ticker.attach(&beamExpired,1.0);
+    } else {
+        beam_ticker.detach();
+    }
+
+    if(wallFlag == 1) {
+        wall_ticker.attach(&wallExpired, 4.0);
+    } else {
+        wall_ticker.detach();
+    }
+}
+
+
+
+
+
+int main()
+{
+    lcd.init(); //initializes the LCD display
+///  initTMP102();
+
+    lcd.normalMode();      /// normal colour mode
+    lcd.setBrightness(0.5); /// put LED backlight on 50%
+    button.rise(&buttonPressed); /// indicates that the button has been pressed. button flag rises when button pressed
+
+    measure_ticker.attach(&measureExpired,1.0);
+    update_ticker.attach(&updateExpired,2.0);
+    beam_ticker.attach(&beamExpired,3.0);
+    //  update_ticker_two.attach(&update_distance_new,2.0);
+    range_ticker.attach(&rangeExpired,4.0);
+    wall_ticker.attach(&wallExpired, 5.0);
+
+
+    while(1) {
+        // distance = srf.getDistanceCm();
+
+        manageScreen();
+        if (timerFlag) {
+            timerFlag=0;   ///reset flag
+
+
+            if(measureFlag) {
+                lcd.clear();
+                measureFlag =0;  ///reset flag
+
+                char buffer[14];
+
+                distance = srf.getDistanceCm();  /// same idea with floats
+                float length = sprintf(buffer,"D = %.2f cm",distance);
+                if (length <= 14)
+                    lcd.printString(buffer,0,4);
+
+            /*    temperature = getTemperature();
+                     int lengthT = sprintf(buffer,"T = %.2f C",temperature); /// print formatted data to buffer
+                     if (lengthT <= 14)  /// if string will fit on display
+                         lcd.printString(buffer,0,5);
+               
+                soundSpeed = calcSoundSpeed(temperature);
+                soundTimeDelay = calcSoundTimeDelay(distance, soundSpeed);
+                */
+            }
+            lcd.refresh();
+
+
+            if(updateFlag) {
+                lcd.clear();
+                updateFlag=0;  ///reset flag
+                char bufferOne[14]; ///character array that stores the values of the newDistance variable
+                char bufferTwo[14];///character array that stores the values of the lastDistance variable
+
+
+
+                float lengthN = sprintf(bufferOne,"Dn = %.2f cm",distance);
+                if (lengthN <= 14)
+                    lcd.printString(bufferTwo,0,4);
+
+                float lengthL = sprintf(bufferTwo,"Dl = %.2f cm",lastDistance);
+                if (lengthL <= 14)
+                    lcd.printString(bufferTwo,0,5);
+            }
+            lcd.refresh();
+
+
+            if (rangeFlag) {
+                lcd.clear();
+                rangeFlag=0;  ///reset  flag
+                char buffer[14];
+
+                //   distance = srf.getDistanceCm();  // same idea with floats
+                float length = sprintf(buffer," %.2f cm",distance);
+                if (length <= 14) {
+                    lcd.printString(buffer,11,2);
+                }
+
+                buzzerFrequency=fsm[currentState].bOutput;  /// retrieves the buzzer frequency associated to the currentState from the FSM definition
+                buzzer.beep(buzzerFrequency,1);
+                float lengthB = sprintf(buffer," %.2f hz",buzzerFrequency);
+                if (lengthB <= 14) {
+                    lcd.printString(buffer,11,4);
+                }
+                lcd.refresh();
+            }
+
+
+            if (beamFlag) {
+                lcd.clear();
+                beamFlag =0;
+
+                z++;
+                if (z>=5) z=0;
+                angleDegrees = angleArray[z];
+                angleRadians=convertDegrees(angleDegrees);
+                a=angleRadians;
+
+                drawSemiCircle();
+                d =srf.getDistanceCm();
+//simply assigns the function results under conditions (a,d) to the distance variable values. calls the pointers defined previously
+                lateralDistance = 2*lat(a,d);
+                h = hyp(a,d);
+
+                drawBeamLines();
+
+            }
+            lcd.refresh();
+
+
+            if (wallFlag) {
+                lcd.clear();
+                wallFlag=0; ///reset flag
+                drawMaze();  ///draws the screen backgroung structure
+                move();    ///controls the movement and associated signals for the moving pixel point
+            }
+
+        }
+    }
+}
+
+
diff -r fd19182020c8 -r 37d0985c814e obstacle.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/obstacle.h	Mon May 11 22:30:17 2015 +0000
@@ -0,0 +1,451 @@
+
+/**
+@file main.h
+@brief header file containing function prototypes, defines and variables
+@brief shows the different applications of the ultrasonic distance sensor combined with a temperature sensor
+@brief Last Revision combining all of the previous trials
+@author Mahlet Shimellis
+@date April-March 2015
+*/
+
+#ifndef MAIN_H
+#define MAIN_H
+
+/**
+@brief Below is the list of temperature sensor register adresses used
+@brief the first two are read and write adresses when ADD0 is connected to GROUND
+@brief the last two are common temerature registers
+*/
+
+#define TMP102_R_ADD 0x91
+#define TMP102_W_ADD 0x90
+#define TEMP_REG 0x00
+#define CONFIG_REG 0x01
+
+#include "mbed.h"
+
+/**
+@namespace leds
+@brief This defines the mbed leds taht will be useful to detect error messages
+*/
+BusOut leds(LED4,LED3,LED2,LED1);
+
+/**
+@namespace lcd
+@brief  LCD dispaly pin connections to the mbed
+@brief Format used N5110(PinName pwrPin, PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin, PinName ledPin)
+*/
+N5110 lcd(p5,p6,p7,p8,p11,p13,p21);
+
+/**
+@namespace buzzer
+@brief Buzzer connection to mbed
+*/
+Beep buzzer(p26);
+
+/**
+@namespace button
+@brief anolog input to the mbed
+*/
+InterruptIn button(p16);
+
+/**
+@namespace srf
+@brief SRF02 ultrasonic distance sensor I2C connection to mbed
+@brief Format srf(SDA pin, SCL pin)
+*/
+SRF02 srf(p28, p27);
+
+/**
+@namespace tmp102
+@brief TMP102 temperature sensor I2C connection to mbed
+@brief format tmp102(SDA pin, SCL pin)
+*/
+//I2C tmp102(p9,p10);
+
+/**
+@namespace red
+@brief Red  LED PwmOut connection to mbed
+*/
+PwmOut red(p22);
+
+/**
+@namespace yellow
+@brief Yellow LED PwmOut connection to mbed
+*/
+PwmOut yellow(p23);
+
+/**
+@namespace green
+@brief Green LED PwmOut connection to mbed
+*/
+PwmOut green(p24);
+
+
+
+Ticker timer; ///global timer
+Ticker measure_ticker;
+Timer measure;
+int measureFlag=0; /*!< measure flag set in ISR for intial temperature and distance measurements  ??? ticker timer */
+double distance; /*!< distance value updated from SRF02 measurements */
+float temperature; /*!<temperature value updated from TMP102 measurements*/
+float soundSpeed; /*!<float for speed of sound */
+float soundTimeDelay; /*!<float time delay value for sending and receiving sound signal */
+Ticker temperature_ticker;
+
+/**
+@brief defines the high flag state for the measurement flag
+*/
+void measureExpired ();
+
+/**
+@bSets the error signaling for the mbed connections mainly I2C when the acknowlegment bit is not received
+@param code - integer to classify error type
+*/
+void error(int code);
+
+
+
+
+/**
+Initialises the temperature sensor
+*/
+void initTMP102();
+
+/**
+Performs the temperature measurement
+@returns the temperature value with a 0.0625 resolution
+*/
+float getTemperature();
+
+
+/**
+Calculates the speed of sound from the measured temperature
+@param temperature - float measured temperature value
+@returns the value of the speed of sound for each specific temeprature value
+*/
+ float calcSoundSpeed (float temperature);
+
+
+/**
+Calculates the delay between transmission and emission of the sound from the ultrasonic distance sensor
+@param distance - integer measured distance value
+@param soundSpeed - float calculated speed of sound value
+@returns timeDelay - float delay between transmission and reception of the sound after reflecting on the object for which the distance has been measured
+*/
+float calcSoundTimeDelay (int distance, float soundSpeed);
+
+
+
+/**
+////////////////////PART 2 - Distance Update and Speed ///////////////////////////////////
+@brief in this section
+@ brief variables
+@brief ticker variable
+@brief timer expired function   
+@brief distance update and storage function
+*/
+
+
+Ticker update_ticker;
+Ticker update_ticker_two;
+int updateFlag=0;
+int r=0;
+float newDistance; /*!< new distance value updated from SRF02 measurements after each timer delay */
+float lastDistance;/*!< for eaxh new distance value updated from SRF02 measurements after each timer delay, this is the stored previous distance value */
+float updateDelay=0; /*!< time delay between each distance value update */
+
+///Ticker update_ticker;
+//Ticker timer;
+
+/**
+Defines the high flag state for the distance measurement update flag
+*/
+void upadteExpired();
+
+/**
+Stores the previous distance in the lastDistance variable and updates the newDistance variable
+@returns the lastDistance value of the previous measurement
+@returns the newDistance value from the new measurement
+*/
+void update_distance_new();
+
+
+
+/**
+/////////////////////////////////////////PART 3 - Distance Range Alert///////////////////////////////////////////
+@brief in this section
+@brief define min, max, maxState
+@brief define variables (state variables, buzzerFrequency)
+@brief define updateState function protoype
+*/
+
+#define MAX 200
+#define MIN 20
+#define maxState 4
+
+/**
+@brief Timing elements for the range differentiation module of the distance sensor
+*/
+Ticker range_ticker; 
+Timer range;
+int rangeFlag =0; /*!< range flag set in ISR */
+
+int currentState =0; /*!<integer from 0 to 4 that defines the current state of the FSM*/
+int rangeState =0; /*!<integer from 0 to 4 that defines the range to which belongs the measured distance between MIN and MAX*/
+
+float buzzerFrequency =0; /*!<float that defines the frequency of the buzzer depending on the distance range. higher frequencies as we get closer to the object. output of the FSM structure*/
+
+/**
+@brief defines the high flag state for the measurement flag
+*/
+void rangeExpired();
+
+/**
+ function that defines the input of the FSM depending on the distance range from MAX to MIN
+@param distance - integer measured value by the SRF02 sensor and to be classified as part of a set of five ranges from MAX to MIN
+@returns rangeState - integer from 0 to 4. defined depending on the distance range in whcih the measured distance belongs
+@returns currentState - integer from 0 to 4. depending on the value of the rangeState, the actual current state and the FSM nextState from the structure definition
+*/
+void updateState();
+
+
+
+/**
+@brief PART 4 - Beam Pattern hard
+@brief in this section
+@brief define variables (angle related variables, counter, distance related variables)
+@brief define trigonometric function protoptypes
+@brief define drawing function prototypes
+ */
+
+Ticker beam_ticker;
+Timer beam;
+int beamFlag=0;
+
+/**
+@brief defines the high flag state for the beam flag
+*/
+void beamExpired();
+
+int radius =0;
+
+double angleDegrees =0; /*!<initial angles in degrees*/
+double angleRadians=0; /*!<angles in radians after conversion*/
+double a=0;
+int z=0; ///counter
+double d=0;
+float lateralDistance=0;
+float h=0; ///hypothenuse
+
+
+/**
+@brief function that converts angle units 
+@param angleDegrees - double
+@returns angleRadians
+*/
+double convertDegrees (double angleDegrees);
+
+/**
+ function that draws a semi-circle depending on the distance measured
+@param radius - equal to the disance measured
+@brief center at (WIDTH/2,1) on the LCD 
+*/
+void drawSemiCircle();
+
+/**
+ function that shifts through angles of the beam pattern
+@param l- lateral distance for angle a
+@param h - hypothenuse distance for angle a
+*/
+void drawBeamLines(float lateralDistance, float h);
+
+/**
+ function that calculates the lateral distance between the sensor center and object at angle a
+@param a - double angle between center if sensor and object detected
+@param d - double shortest right angle distance between center of center and object detected. this is the distance measured directly in front of the sensor
+@returns - value of the lateral distance between sensor center line and beam at angle a from center
+*/
+double lat(double a, double d);
+
+/**
+@brief function that calculates the hypothenuse distance between the sensor center and object at angle a - this is the longest distance
+@param a - double angle between center if sensor and object detected
+@param d - double shortest right angle distance between center of center and object detected. this is the distance measured directly in front of the sensor
+@returns - value of the hypothenuse between sensor center line and beam at angle a from center
+*/
+double hyp(double a, double d);
+
+
+
+/**
+///////////////////////////////// PART 5 - the Wall Follower Simulation///////////////////////////
+@brief in this section
+@brief buzzer and led tickers
+@brief buzzer functions prototype
+@brief led functions prototype
+@brief counter integer variables
+@breif movemetn and drawing functions prototype
+*/
+
+
+int wallFlag=0;
+Timer wall_timer;
+Ticker wall_ticker;
+/**
+Defines the high flag state for the beam flag
+*/
+void wallExpired();
+
+/**
+@brief set of buzzer tickers depending on the direction of movement and signal given 
+@brief zero move forward
+@brief one turn left
+@brief two turn left and move forward
+@brief three turn right
+@brief four turn right and move forward
+@brief five stop, dead end
+*/
+Ticker beep_ticker_zero;
+Ticker beep_ticker_one;
+Ticker beep_ticker_two;
+Ticker beep_ticker_three;
+Ticker beep_ticker_four;
+Ticker beep_ticker_five;
+
+
+/**
+@brief set of LED tickers
+*/
+Ticker toggle_green_ticker;
+Ticker toggle_yellow_ticker;
+Ticker toggle_red_ticker;
+
+
+/**
+@brief Set of integer pixel counters to define and kepp track of the movement along the maze
+*/
+int k=0; /*!<integer for stage 0 move forward k from 0 to 22 pixel points*/
+int l=0;/*!<integer for stage 1 turn left and move forward one l from 0 to 64 pixel points*/
+int m=0;/*!<integer for stage 2 turn left and move forward two m from 0 to 16 pixel points*/
+int n=0;/*!<integer for stage 3 turn right and move forward n from 0 to 78 pixel points*/
+int pix=0;/*!<integer that keeps track of the sum of all the counter integers as the pixel moves along the maze. helps keep track of the location of the pixel */
+
+
+int buttonCounter; /*!<integer 0 to 4 counts the number of times the button has been pressed*/
+int buttonFlag = 0;/*!<button flag set in ISR*/
+
+/**
+Manages the order of displays on the screen and synchronises it to the number of button presses
+*/
+void manageScreen();
+
+/**
+Counts the pixel step in the forward movement 
+@param k - integer counter from 0 to 22
+@returns pix - integer counter incremented stores values from 0 to k
+*/
+void moveForward();
+
+/**
+Counts the pixel step in the turnLeftForward_one movement 
+@param l - integer counter from 0 to 64
+@returns pix - integer counter incremented stores values from k to k+l
+*/
+void turnLeftForward_one();
+
+/**
+Counts the pixel step in the turnLeftForward_two movement 
+@param m - integer counter from 0 to 16
+@returns pix - integer counter incremented stores values from k+l to k+l+m
+*/
+void turnLeftForward_two();
+
+/**
+Counts the pixel step in the turnLeftForward_two movement 
+@param n - integer counter from 0 to 78
+@returns pix - integer counter incremented stores values from k+l+m to k+l+m+n
+*/
+void turnRightForward();
+
+/**
+Controls intial beep zero move forward
+@param sound_zero - integer set frequency value, introduced as local variable for function
+@param time_zero - float set time value for each buzz, introduced as local variable for function
+*/
+void beep_zero();
+
+/**
+Turns on beep one Turn Left
+@param sound_one - integer set frequency value , local variable for function
+@param time_one - float set time value for each buzz , local variable for function
+*/
+void beep_one();
+
+/**
+Turns on beep two Trun Left and move Forward 
+@param sound_two - integer set frequency value, local variable for function
+@param time_two - float set time value for each buzz, local variable for function
+*/
+void beep_two();
+
+/**
+Turns on beep three Turn Right
+@param sound_three - integer set frequency value, local variable for function
+@param time_three - float set time value for each buzz, local variable for function
+*/
+void beep_three();
+
+/**
+Turns on beep four Trun Right and move Forward 
+@param sound_four - integer set frequency value, local variable for function
+@param time_four - float set time value for each buzz, local variable for function
+*/
+void beep_four();
+
+/**
+Turns on beep five Stop Dead End
+@param sound_five - integer set frequency value, local variable for function
+@param time_five - float set time value for each buzz, local variable for function
+*/
+void beep_five();
+
+
+/**
+@brief funciton that toggles Red LED
+@brief controls PwmOut pin
+*/
+void toggle_red();
+
+/**
+@brief funciton that toggles Yellow LED
+@brief controls PwmOut pin
+*/
+void toggle_yellow();
+
+/**
+@brief funciton that toggles Green LED
+@brief controls PwmOut pin
+*/
+void toggle_green();
+
+/**
+Controls the pixel movement along the maze
+Combines all of the different stages/sub-movements
+Combines the buzzer and led tickers for appropriate and timely signaling
+@param pix - integer that sums the movement cnouters and gives an idea of the location of the pixel
+@returns buzzer sound - output sound signal with frequency depending on the location
+@returns LED light - output light signal with color dependent on message/location (go forward, stop etc.)
+*/
+void move();
+
+/**
+Draws the sample structure of the maze to reflect the wall follower movement technique
+Combines drawRect functions with pre-set dimensions
+@param x,y, width, height
+*/
+void drawMaze();
+
+
+
+#endif