Dean Fraj
/
DC_motor_2
Program for controlling speed and rotation of motor
main.cpp@0:669350f3c18d, 2017-12-18 (annotated)
- Committer:
- dfraj
- Date:
- Mon Dec 18 14:00:18 2017 +0000
- Revision:
- 0:669350f3c18d
Program for controlling speed and direction of motor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dfraj | 0:669350f3c18d | 1 | #include "mbed.h" |
dfraj | 0:669350f3c18d | 2 | |
dfraj | 0:669350f3c18d | 3 | PwmOut smjer1(p21); |
dfraj | 0:669350f3c18d | 4 | PwmOut smjer2(p22); |
dfraj | 0:669350f3c18d | 5 | PwmOut ledica1(LED1); |
dfraj | 0:669350f3c18d | 6 | PwmOut ledica2(LED2); |
dfraj | 0:669350f3c18d | 7 | AnalogIn pot(p20); |
dfraj | 0:669350f3c18d | 8 | |
dfraj | 0:669350f3c18d | 9 | int main(){ |
dfraj | 0:669350f3c18d | 10 | smjer1.period(0.00004); |
dfraj | 0:669350f3c18d | 11 | while(true){ |
dfraj | 0:669350f3c18d | 12 | if(pot >= 0 && pot < 0.5){ |
dfraj | 0:669350f3c18d | 13 | smjer1 = (-2 * pot) + 1; |
dfraj | 0:669350f3c18d | 14 | ledica1 = (-2 * pot) + 1; |
dfraj | 0:669350f3c18d | 15 | smjer2 = 0; |
dfraj | 0:669350f3c18d | 16 | } else if(pot > 0.5 && pot <= 1){ |
dfraj | 0:669350f3c18d | 17 | smjer1 = 0; |
dfraj | 0:669350f3c18d | 18 | smjer2 = (pot - 0.5) * 2; |
dfraj | 0:669350f3c18d | 19 | ledica2 = (pot - 0.5) * 2; |
dfraj | 0:669350f3c18d | 20 | } else{ |
dfraj | 0:669350f3c18d | 21 | smjer1 = 0; |
dfraj | 0:669350f3c18d | 22 | smjer2 = 0; |
dfraj | 0:669350f3c18d | 23 | } |
dfraj | 0:669350f3c18d | 24 | } |
dfraj | 0:669350f3c18d | 25 | } |