![](/media/cache/profiles/23d3743ad75e4470e7ff7129351a9541.jpg.50x50_q85.jpg)
Single direction, PWM control of a DC Motor
Dependencies: Motor mbed tsi_sensor
main.cpp@0:a19ecb0b5364, 2015-11-30 (annotated)
- Committer:
- TheFella
- Date:
- Mon Nov 30 13:06:59 2015 +0000
- Revision:
- 0:a19ecb0b5364
Single direction, PWM control for a DC Motor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TheFella | 0:a19ecb0b5364 | 1 | #include "mbed.h" |
TheFella | 0:a19ecb0b5364 | 2 | #include "tsi_sensor.h" |
TheFella | 0:a19ecb0b5364 | 3 | |
TheFella | 0:a19ecb0b5364 | 4 | |
TheFella | 0:a19ecb0b5364 | 5 | TSIAnalogSlider tsi(PTB16, PTB17, 25); // Touch pad slider tied to touch pad pins, named tsi |
TheFella | 0:a19ecb0b5364 | 6 | PwmOut mSpeed(PTB0); |
TheFella | 0:a19ecb0b5364 | 7 | DigitalOut DirCon1(PTC1); |
TheFella | 0:a19ecb0b5364 | 8 | Serial pc(USBTX, USBRX); // USB Serial Port |
TheFella | 0:a19ecb0b5364 | 9 | |
TheFella | 0:a19ecb0b5364 | 10 | float readValue; |
TheFella | 0:a19ecb0b5364 | 11 | float speed = 0; |
TheFella | 0:a19ecb0b5364 | 12 | |
TheFella | 0:a19ecb0b5364 | 13 | int main() |
TheFella | 0:a19ecb0b5364 | 14 | { |
TheFella | 0:a19ecb0b5364 | 15 | mSpeed.period(0.001); |
TheFella | 0:a19ecb0b5364 | 16 | |
TheFella | 0:a19ecb0b5364 | 17 | while(1) |
TheFella | 0:a19ecb0b5364 | 18 | { |
TheFella | 0:a19ecb0b5364 | 19 | pc.printf("\033[2J"); // Clear Screen and Home cursor |
TheFella | 0:a19ecb0b5364 | 20 | pc.printf("\033[H"); |
TheFella | 0:a19ecb0b5364 | 21 | readValue = tsi.readPercentage(); |
TheFella | 0:a19ecb0b5364 | 22 | pc.printf("TSI = %0.2f\n\r", readValue); |
TheFella | 0:a19ecb0b5364 | 23 | if ( readValue == 0 ) |
TheFella | 0:a19ecb0b5364 | 24 | { |
TheFella | 0:a19ecb0b5364 | 25 | mSpeed = 0; |
TheFella | 0:a19ecb0b5364 | 26 | DirCon1 = 0; |
TheFella | 0:a19ecb0b5364 | 27 | wait(0.2); |
TheFella | 0:a19ecb0b5364 | 28 | } |
TheFella | 0:a19ecb0b5364 | 29 | DirCon1 = 0; |
TheFella | 0:a19ecb0b5364 | 30 | mSpeed = readValue; |
TheFella | 0:a19ecb0b5364 | 31 | wait(0.2); |
TheFella | 0:a19ecb0b5364 | 32 | } |
TheFella | 0:a19ecb0b5364 | 33 | } |