![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Završni rad Androić H most upravljan MBED-om
main.cpp@2:9500cf2f8f8b, 2015-05-12 (annotated)
- Committer:
- cvitas
- Date:
- Tue May 12 19:50:52 2015 +0000
- Revision:
- 2:9500cf2f8f8b
- Parent:
- 1:a09621d44b14
potenciometar upravlja DC motorom
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cvitas | 0:ce1da5b1e608 | 1 | #include "mbed.h" |
cvitas | 0:ce1da5b1e608 | 2 | |
cvitas | 2:9500cf2f8f8b | 3 | AnalogIn Ain(p20); |
cvitas | 2:9500cf2f8f8b | 4 | float ADCdata; |
cvitas | 2:9500cf2f8f8b | 5 | |
cvitas | 1:a09621d44b14 | 6 | PwmOut OUT_A(p21); |
cvitas | 1:a09621d44b14 | 7 | PwmOut OUT_B(p22); |
cvitas | 1:a09621d44b14 | 8 | |
cvitas | 0:ce1da5b1e608 | 9 | |
cvitas | 0:ce1da5b1e608 | 10 | int main() { |
cvitas | 1:a09621d44b14 | 11 | |
cvitas | 1:a09621d44b14 | 12 | OUT_A.period(0.010); // set PWM period to 10 ms |
cvitas | 1:a09621d44b14 | 13 | while(1) { |
cvitas | 2:9500cf2f8f8b | 14 | ADCdata=Ain; |
cvitas | 2:9500cf2f8f8b | 15 | if (ADCdata>0.5) |
cvitas | 2:9500cf2f8f8b | 16 | { |
cvitas | 2:9500cf2f8f8b | 17 | OUT_A=0.0; // set duty cycle to 0% |
cvitas | 2:9500cf2f8f8b | 18 | OUT_B= 2*(ADCdata-0.5); |
cvitas | 2:9500cf2f8f8b | 19 | } |
cvitas | 2:9500cf2f8f8b | 20 | else |
cvitas | 2:9500cf2f8f8b | 21 | { |
cvitas | 2:9500cf2f8f8b | 22 | OUT_B=0.0; // set duty cycle to 0% |
cvitas | 2:9500cf2f8f8b | 23 | OUT_A= 2*(-ADCdata+0.5); |
cvitas | 2:9500cf2f8f8b | 24 | } |
cvitas | 1:a09621d44b14 | 25 | |
cvitas | 1:a09621d44b14 | 26 | } |
cvitas | 1:a09621d44b14 | 27 | |
cvitas | 2:9500cf2f8f8b | 28 | |
cvitas | 0:ce1da5b1e608 | 29 | } |