Janus Bo Andersen / Mbed 2 deprecated PRO1_amp_test

Dependencies:   mbed m3pi

main.cpp

Committer:
janusboandersen
Date:
2018-11-30
Revision:
3:783382bcf2ec
Parent:
2:41af46339652

File content as of revision 3:783382bcf2ec:

/*
 * This program utilizes max power on the m3pi to measure current
 * Results: about 7-800 mA when no resistance on motors
 *          about 1000-1100 mA when physical resistance on motors (not stalling)
 */
#include "mbed.h"
#include "m3pi.h"

m3pi m3pi;


//Print to LCD (character, line) numbers are zero indexed
void print_battery() {
    
    //measure battery voltage
    float f = m3pi.battery();
    char text[8];
    m3pi.cls();
    m3pi.locate(0,0);
    
    //convert to a string
    sprintf(text, "%4.2f", f);
    m3pi.printf(text);
}


int main(void) {
    
    //user push button p21
    DigitalIn button(p21);
    button.mode(PullUp);

    //set the LEDs as objects    
    //on the m3pi
    DigitalOut redled8(p13);
    DigitalOut redled7(p14);
    DigitalOut redled6(p15);
    DigitalOut redled5(p16);
    DigitalOut redled4(p17);
    DigitalOut redled3(p18);
    DigitalOut redled2(p19);
    DigitalOut redled1(p20);
    
    //on the mbed
    DigitalOut myled1 (LED1);
    DigitalOut myled2 (LED2);
    DigitalOut myled3 (LED3);
    DigitalOut myled4 (LED4);
    
    
    // Set all LEDs to on
    redled1 = 1;
    redled2 = 1;
    redled3 = 1;
    redled4 = 1;
    redled5 = 1;
    redled6 = 1;
    redled7 = 1;
    redled8 = 1;
    myled1 = 1;
    myled2 = 1;
    myled3 = 1;
    myled4 = 1;
    
    
    //Initialize the car
    m3pi.sensor_auto_calibrate();   
    
    // Start the loop
    while (1) {
          
   // set full speed 
    m3pi.left_motor(1.0);
    m3pi.right_motor(1.0);
    
    //print voltage
    print_battery();
    }

}