Cornfield Cruisers / Mbed 2 deprecated TurnPotMotorPWM

Dependencies:   mbed

Committer:
pridgejg
Date:
Wed Sep 11 20:04:16 2019 +0000
Revision:
0:a4f7be3d6847
Code for Turnpot w/ motor ;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pridgejg 0:a4f7be3d6847 1 #include "mbed.h"
pridgejg 0:a4f7be3d6847 2 #include <iostream>
pridgejg 0:a4f7be3d6847 3 #include <math.h>
pridgejg 0:a4f7be3d6847 4
pridgejg 0:a4f7be3d6847 5 //Serial bt(PTE0,PTE1);// Bluetooth
pridgejg 0:a4f7be3d6847 6 PwmOut duty(PTA5);// pwm output
pridgejg 0:a4f7be3d6847 7 AnalogIn pot(PTB0); // potentiometer to adjust motor speed
pridgejg 0:a4f7be3d6847 8 DigitalOut myled(LED1);
pridgejg 0:a4f7be3d6847 9
pridgejg 0:a4f7be3d6847 10 int main() {
pridgejg 0:a4f7be3d6847 11 duty.period(0.00005);
pridgejg 0:a4f7be3d6847 12 // bt.baud(115200);// setting the baud rate
pridgejg 0:a4f7be3d6847 13 // bt.printf("We runnin' boys \n\r");
pridgejg 0:a4f7be3d6847 14
pridgejg 0:a4f7be3d6847 15 while(true) {
pridgejg 0:a4f7be3d6847 16 int loopCounter = 1;
pridgejg 0:a4f7be3d6847 17 while(loopCounter<20000){
pridgejg 0:a4f7be3d6847 18
pridgejg 0:a4f7be3d6847 19 float potPercent = pot.read(); // takes value from potentiometer
pridgejg 0:a4f7be3d6847 20 duty.write(potPercent);
pridgejg 0:a4f7be3d6847 21
pridgejg 0:a4f7be3d6847 22 loopCounter++;
pridgejg 0:a4f7be3d6847 23 }
pridgejg 0:a4f7be3d6847 24 cout << "\r\n TurnPot IN:" << (pot) << endl;
pridgejg 0:a4f7be3d6847 25 cout << "\r\n PWM OUT:" << (duty) << endl;
pridgejg 0:a4f7be3d6847 26 }
pridgejg 0:a4f7be3d6847 27
pridgejg 0:a4f7be3d6847 28 }