Testcode for LVC Robot club

Dependencies:   mbed

Committer:
jonmarsh
Date:
Mon Apr 23 09:32:50 2012 +0000
Revision:
1:fe52aa73cd6a
Parent:
0:f4922a2a0292

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jonmarsh 0:f4922a2a0292 1 /**
jonmarsh 1:fe52aa73cd6a 2
jonmarsh 0:f4922a2a0292 3 Description:
jonmarsh 0:f4922a2a0292 4
jonmarsh 1:fe52aa73cd6a 5 This program uses a Sharp Digital Distance sensor (GP2Y0D810) attached to pin 30 and 11
jonmarsh 1:fe52aa73cd6a 6 (the two headers on the right and left of the board).
jonmarsh 0:f4922a2a0292 7
jonmarsh 0:f4922a2a0292 8
jonmarsh 0:f4922a2a0292 9 **/
jonmarsh 0:f4922a2a0292 10
jonmarsh 0:f4922a2a0292 11 #include "mbed.h"
jonmarsh 0:f4922a2a0292 12 #include "SharpDigiDist100.h"
jonmarsh 0:f4922a2a0292 13 #include "m3pi.h"
jonmarsh 0:f4922a2a0292 14
jonmarsh 0:f4922a2a0292 15 DigitalOut Left[2] = {LED1,LED2}; //Some indicator LEDs for the range finders
jonmarsh 0:f4922a2a0292 16 DigitalOut Right[2] = {LED4,LED3};
jonmarsh 0:f4922a2a0292 17
jonmarsh 0:f4922a2a0292 18 SharpDigiDist100 right(p30); // The range finder class initialisations
jonmarsh 0:f4922a2a0292 19 SharpDigiDist100 left(p11);
jonmarsh 0:f4922a2a0292 20
jonmarsh 0:f4922a2a0292 21 m3pi m3pi; // Initialise the m3pi
jonmarsh 0:f4922a2a0292 22
jonmarsh 0:f4922a2a0292 23
jonmarsh 0:f4922a2a0292 24 int main() {
jonmarsh 0:f4922a2a0292 25
jonmarsh 0:f4922a2a0292 26 m3pi.locate(0,0); // Write the name to the screen
jonmarsh 1:fe52aa73cd6a 27 m3pi.printf("Sonar");
jonmarsh 0:f4922a2a0292 28
jonmarsh 1:fe52aa73cd6a 29 // m3pi.get_white_levels(); // Saves the current levels of the sensors to know what is white
jonmarsh 0:f4922a2a0292 30
jonmarsh 0:f4922a2a0292 31 while (1) {
jonmarsh 1:fe52aa73cd6a 32
jonmarsh 1:fe52aa73cd6a 33 // This tells it what to do when it detects something on the right-hand sensor
jonmarsh 1:fe52aa73cd6a 34
jonmarsh 0:f4922a2a0292 35 switch (right.getDistance()) { // Sets up the distance indicator LEDs for the right side
jonmarsh 0:f4922a2a0292 36 case SharpDigiDist100::Far :
jonmarsh 0:f4922a2a0292 37 Right[0] = true;
jonmarsh 0:f4922a2a0292 38 Right[1] = false;
jonmarsh 0:f4922a2a0292 39 break;
jonmarsh 0:f4922a2a0292 40 case SharpDigiDist100::Near :
jonmarsh 0:f4922a2a0292 41 Right[1] = true;
jonmarsh 0:f4922a2a0292 42 Right[0] = false;
jonmarsh 0:f4922a2a0292 43 break;
jonmarsh 0:f4922a2a0292 44 case SharpDigiDist100::Mid :
jonmarsh 0:f4922a2a0292 45 Right[0] = true;
jonmarsh 0:f4922a2a0292 46 Right[1] = true;
jonmarsh 0:f4922a2a0292 47 break;
jonmarsh 0:f4922a2a0292 48 default:
jonmarsh 0:f4922a2a0292 49 break;
jonmarsh 0:f4922a2a0292 50 }
jonmarsh 1:fe52aa73cd6a 51
jonmarsh 1:fe52aa73cd6a 52 // This tells it what to do when it detects something on the left-hand sensor
jonmarsh 1:fe52aa73cd6a 53
jonmarsh 0:f4922a2a0292 54 switch (left.getDistance()) { // Sets up the distance indicator LEDs for the left side
jonmarsh 0:f4922a2a0292 55 case SharpDigiDist100::Far :
jonmarsh 0:f4922a2a0292 56 Left[0] = true;
jonmarsh 0:f4922a2a0292 57 Left[1] = false;
jonmarsh 0:f4922a2a0292 58 break;
jonmarsh 0:f4922a2a0292 59 case SharpDigiDist100::Near :
jonmarsh 0:f4922a2a0292 60 Left[1] = true;
jonmarsh 0:f4922a2a0292 61 Left[0] = false;
jonmarsh 0:f4922a2a0292 62 break;
jonmarsh 0:f4922a2a0292 63 case SharpDigiDist100::Mid :
jonmarsh 0:f4922a2a0292 64 Left[0] = true;
jonmarsh 0:f4922a2a0292 65 Left[1] = true;
jonmarsh 0:f4922a2a0292 66 break;
jonmarsh 0:f4922a2a0292 67 default:
jonmarsh 0:f4922a2a0292 68 break;
jonmarsh 0:f4922a2a0292 69 }
jonmarsh 0:f4922a2a0292 70
jonmarsh 0:f4922a2a0292 71 }
jonmarsh 0:f4922a2a0292 72 }