Generation 3 of the Harp project

Dependencies:   Servo TMP36 GZ buffered-serial1 chan_fatfs_sd nmea_parser watchdog mbed-rtos mbed

Fork of HARP2 by Tyler Weaver

main.cpp

Committer:
tylerjw
Date:
2012-12-11
Revision:
10:b13416bbb4cd
Parent:
9:4debfbc1fb3e
Child:
11:890a721158a5

File content as of revision 10:b13416bbb4cd:

#include "mbed.h"
#include "rtos.h"
#include "buffered_serial.h"

#define CELLS       3.0
#define LIPO_EMPTY  3.4
#define LIPO_FULL   4.2

const float BAT_MUL = 4.7;
const float BAT_FULL = (CELLS * LIPO_FULL);
const float BAT_EMPTY = (CELLS * LIPO_EMPTY);
const float BAT_RANGE = BAT_FULL - BAT_EMPTY;

Serial pc(USBTX, USBRX);
BufferedSerial gps(NC, p14);
AnalogIn gps_battery(p20);

void gps_thread(void const *args)
{
    char buffer[80];

    DigitalOut gps_led(LED4);

    gps.baud(4800);

    while(true) {
        gps.read_line(buffer);
        gps_led = !gps_led;
        //pc.puts(buffer);
    }
}

int main()
{
    pc.baud(9600);
    Thread thread(gps_thread, NULL, osPriorityHigh);

    while(true) {
        float sample = gps_battery.read();
        pc.printf("Sample: %f Volts\r\n", sample*3.3);
        float voltage = sample*BAT_MUL*3.3;
        pc.printf("Battery Voltage: %f Volts\r\n", voltage);
        float level = (voltage-BAT_EMPTY) / (BAT_RANGE);
        pc.printf("Battery Level: %f \r\n", level);
        
        Thread::wait(1000);
    }
}