![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Programming Milestone Group 7 BMT M9
Dependencies: FastPWM MODSERIAL mbed
main.cpp@0:1e216b50d323, 2018-09-25 (annotated)
- Committer:
- MAHCSnijders
- Date:
- Tue Sep 25 10:36:50 2018 +0000
- Revision:
- 0:1e216b50d323
- Child:
- 1:67b19c59b8c9
First try, error.;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MAHCSnijders | 0:1e216b50d323 | 1 | #include "mbed.h" |
MAHCSnijders | 0:1e216b50d323 | 2 | |
MAHCSnijders | 0:1e216b50d323 | 3 | PwmOut pwmpin(); |
MAHCSnijders | 0:1e216b50d323 | 4 | DigitalOut directionpin(); |
MAHCSnijders | 0:1e216b50d323 | 5 | pwmpin.period_us(60); //60 microseconds PWM period, 16.7 kHz |
MAHCSnijders | 0:1e216b50d323 | 6 | AnalogIn potmeter(); // Analoge input van potmeter |
MAHCSnijders | 0:1e216b50d323 | 7 | |
MAHCSnijders | 0:1e216b50d323 | 8 | int main() |
MAHCSnijders | 0:1e216b50d323 | 9 | { |
MAHCSnijders | 0:1e216b50d323 | 10 | while (true) { |
MAHCSnijders | 0:1e216b50d323 | 11 | float u = -0.3f; //determine useful value, -0.3f is just an example |
MAHCSnijders | 0:1e216b50d323 | 12 | directionpin = u > 0.0f; //either true or false |
MAHCSnijders | 0:1e216b50d323 | 13 | pwmpin = fabs(u); //pwm duty cycle can only be positive, floating point absolute value |
MAHCSnijders | 0:1e216b50d323 | 14 | float pot = potmeter.read(); |
MAHCSnijders | 0:1e216b50d323 | 15 | } |
MAHCSnijders | 0:1e216b50d323 | 16 | } |