Single direction, PWM control of a DC Motor
Dependencies: Motor mbed tsi_sensor
main.cpp
00001 #include "mbed.h" 00002 #include "tsi_sensor.h" 00003 00004 00005 TSIAnalogSlider tsi(PTB16, PTB17, 25); // Touch pad slider tied to touch pad pins, named tsi 00006 PwmOut mSpeed(PTB0); 00007 DigitalOut DirCon1(PTC1); 00008 Serial pc(USBTX, USBRX); // USB Serial Port 00009 00010 float readValue; 00011 float speed = 0; 00012 00013 int main() 00014 { 00015 mSpeed.period(0.001); 00016 00017 while(1) 00018 { 00019 pc.printf("\033[2J"); // Clear Screen and Home cursor 00020 pc.printf("\033[H"); 00021 readValue = tsi.readPercentage(); 00022 pc.printf("TSI = %0.2f\n\r", readValue); 00023 if ( readValue == 0 ) 00024 { 00025 mSpeed = 0; 00026 DirCon1 = 0; 00027 wait(0.2); 00028 } 00029 DirCon1 = 0; 00030 mSpeed = readValue; 00031 wait(0.2); 00032 } 00033 }
Generated on Wed Jul 27 2022 00:04:26 by 1.7.2