First release.

Dependencies:   FXOS8700CQ SDFileSystem mbed

Final program

  • Controling a robot by Bluetooth, it is capable of making 90° turns and move pre-defined distances.

Code by:

  • Mayumi Hori
  • Sarahí Morán
  • Gerardo Carmona

my_libraries/ultrasonic.cpp

Committer:
gerardo_carmona
Date:
2014-11-07
Revision:
5:b384cf06de76
Parent:
4:c60636c95b80

File content as of revision 5:b384cf06de76:

// ----- Libraries ------------------------------------------------------------------
#include "mbed.h"
#include "ultrasonic.h"

// ----- Constants ------------------------------------------------------------------


// ----- I/O Pins -------------------------------------------------------------------
AnalogIn ultra_lef(A2);
AnalogIn ultra_rig(A3);

// ----- Others ---------------------------------------------------------------------


// ----- Variables ------------------------------------------------------------------
double read_sensor, cm;

// ----- Functions ------------------------------------------------------------------
float ultrasonicos(int sensor){
    double inch, volts;
    if (sensor == ULTRA_R) {
        read_sensor = ultra_rig;                 // read analog as a float         
    }else if (sensor == ULTRA_L) {
        read_sensor = ultra_lef;                 // read analog as a float    
    }
    // read_sensor * 3300mv / 6.4 mV/in * 2.54 in/cms
    volts = read_sensor * 3300;
    inch = volts / 6.4;
    cm = inch * 2.54;
    return cm;
}