
first commit
Diff: main.cpp
- Revision:
- 0:0a6756c7e3ed
- Child:
- 1:c324a2849500
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Sep 10 03:52:04 2021 +0000 @@ -0,0 +1,61 @@ +#include "mbed.h" +#include <iostream> +#define BLUETOOTHBAUDRATE 115200 //Communication rate of the micro-controller + //to the Bluetooth module +#define SERIALTXPORT PTE0 //Tx Pin (Sends information to serial device) +#define SERIALRXPORT PTE1 //Rx Pin (Receives information from serial + +Serial pc(USBTX, USBRX); // tx, rx +Serial bt(SERIALTXPORT, SERIALRXPORT); //(TX, RX) Serial declaration for new serial + +void btRecevie() +{ +string input = bt.getc(); + + +} + + + +AnalogIn pot1(PTB0); +PwmOut motorRight(PTB2); +PwmOut motorLeft(PTB1); +DigitalOut ledRed(LED1); + + +float freq = 20000; +float fullBatScalar = 0.5873; //batt at 12.6v +float pot1Voltage; +float dutyCycleLeft; +float dutyCycleRight; + +int main() { + bt.baud(BLUETOOTHBAUDRATE); + //Sets the communication rate of the micro-controller to the Bluetooth module. +pc.printf("Hello World!\n"); +bt.printf("Hello World!\n");' +bt.attach(&btReceive); + + //prints the string to the Tera-Term Console using the Bluetooth object ‘bt’. + while(1) { +pot1Voltage = pot1 * 3.3f; +//.printf("Pot1 Voltage: ", pot1Voltage); +bt.printf("Pot1 Voltage = %1.2f volts\n", pot1Voltage); +//at full batt (12.6v) max switching freq is 58.73% +//dutyCycleLeft = (pot1 * fullBatScalar); +//dutyCycleRight = (pot1 * fullBatScalar); + +dutyCycleLeft = (0.5f * fullBatScalar); +dutyCycleRight = (0.25f * fullBatScalar); +bt.printf("Duty Cycle = %1.2f \n", dutyCycleLeft); + + +motorLeft.period(1/freq); +motorRight.period(1/freq); +motorLeft.write(dutyCycleLeft); +motorRight.write(dutyCycleRight); + +wait(0.1); + + } +} \ No newline at end of file