Jon Marsh / Mbed 2 deprecated m3pi_sonar

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /**
00002 
00003 Description:
00004 
00005 This program uses a Sharp Digital Distance sensor (GP2Y0D810) attached to pin 30 and 11 
00006 (the two headers on the right and left of the board). 
00007 
00008 
00009 **/
00010 
00011 #include "mbed.h"
00012 #include "SharpDigiDist100.h"
00013 #include "m3pi.h"
00014 
00015 DigitalOut Left[2] = {LED1,LED2};           //Some indicator LEDs for the range finders
00016 DigitalOut Right[2] = {LED4,LED3};
00017 
00018 SharpDigiDist100 right(p30);                // The range finder class initialisations
00019 SharpDigiDist100 left(p11);
00020 
00021 m3pi m3pi;                                  // Initialise the m3pi
00022 
00023 
00024 int main() {
00025     
00026     m3pi.locate(0,0);                       // Write the name to the screen
00027     m3pi.printf("Sonar");                
00028     
00029     // m3pi.get_white_levels();                // Saves the current levels of the sensors to know what is white
00030     
00031     while (1) {
00032 
00033 // This tells it what to do when it detects something on the right-hand sensor
00034 
00035         switch (right.getDistance()) {      // Sets up the distance indicator LEDs for the right side
00036             case SharpDigiDist100::Far :
00037                 Right[0] = true;
00038                 Right[1] = false;
00039                 break;
00040             case SharpDigiDist100::Near :
00041                 Right[1] = true;
00042                 Right[0] = false;
00043                 break;
00044             case SharpDigiDist100::Mid :
00045                 Right[0] = true;
00046                 Right[1] = true;
00047                 break;
00048             default:
00049                 break;
00050         }
00051 
00052 // This tells it what to do when it detects something on the left-hand sensor
00053 
00054         switch (left.getDistance()) {       // Sets up the distance indicator LEDs for the left side
00055             case SharpDigiDist100::Far :
00056                 Left[0] = true;
00057                 Left[1] = false;
00058                 break;
00059             case SharpDigiDist100::Near :
00060                 Left[1] = true;
00061                 Left[0] = false;
00062                 break;
00063             case SharpDigiDist100::Mid :
00064                 Left[0] = true;
00065                 Left[1] = true;
00066                 break;
00067             default:
00068                 break;
00069         }
00070        
00071     }
00072 }