Single direction, PWM control of a DC Motor
Dependencies: Motor mbed tsi_sensor
main.cpp
- Committer:
- TheFella
- Date:
- 2015-11-30
- Revision:
- 0:a19ecb0b5364
File content as of revision 0:a19ecb0b5364:
#include "mbed.h" #include "tsi_sensor.h" TSIAnalogSlider tsi(PTB16, PTB17, 25); // Touch pad slider tied to touch pad pins, named tsi PwmOut mSpeed(PTB0); DigitalOut DirCon1(PTC1); Serial pc(USBTX, USBRX); // USB Serial Port float readValue; float speed = 0; int main() { mSpeed.period(0.001); while(1) { pc.printf("\033[2J"); // Clear Screen and Home cursor pc.printf("\033[H"); readValue = tsi.readPercentage(); pc.printf("TSI = %0.2f\n\r", readValue); if ( readValue == 0 ) { mSpeed = 0; DirCon1 = 0; wait(0.2); } DirCon1 = 0; mSpeed = readValue; wait(0.2); } }