Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FastPWM mbed QEI biquadFilter HIDScope MODSERIAL
main.cpp@7:7c005b3cf288, 2018-10-08 (annotated)
- Committer:
- efvanmarrewijk
- Date:
- Mon Oct 08 08:31:30 2018 +0000
- Revision:
- 7:7c005b3cf288
- Parent:
- 6:3c9569087274
- Child:
- 8:4f15670bc00b
2 werkende motoren, zonder if-else statements
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Ramonwaninge | 0:3ea1bbfbeaae | 1 | #include "mbed.h" |
Ramonwaninge | 0:3ea1bbfbeaae | 2 | #include "FastPWM.h" |
Ramonwaninge | 0:3ea1bbfbeaae | 3 | |
Ramonwaninge | 0:3ea1bbfbeaae | 4 | Ticker motor; |
Ramonwaninge | 0:3ea1bbfbeaae | 5 | |
Ramonwaninge | 4:0c27632b453a | 6 | AnalogIn pot1(A1); |
Ramonwaninge | 5:047db32db712 | 7 | AnalogIn pot2(A2); |
efvanmarrewijk | 6:3c9569087274 | 8 | FastPWM pin5(D5); // Motor 2 pwm |
efvanmarrewijk | 6:3c9569087274 | 9 | DigitalOut pin4(D4); // Motor 2 direction |
efvanmarrewijk | 6:3c9569087274 | 10 | FastPWM pin6(D6); // Motor 1 pwm |
efvanmarrewijk | 6:3c9569087274 | 11 | DigitalOut pin7(D7); // Motor 1 direction |
efvanmarrewijk | 6:3c9569087274 | 12 | //float u1 = pot1; |
Ramonwaninge | 2:d8a552d1d33a | 13 | |
Ramonwaninge | 3:d39285fdd103 | 14 | void draai(){ |
efvanmarrewijk | 7:7c005b3cf288 | 15 | float u1 = 2.0*(pot1 - 0.5); // Potmeter 1 connects to motor 1 |
efvanmarrewijk | 7:7c005b3cf288 | 16 | u1>0; // Determines direction of motor 1 |
efvanmarrewijk | 7:7c005b3cf288 | 17 | pin5 = fabs(u1); // Determines pwm of motor 1 |
efvanmarrewijk | 6:3c9569087274 | 18 | |
efvanmarrewijk | 7:7c005b3cf288 | 19 | float u2 = 2.0*(pot2 - 0.5); // Potmeter 2 connects to motor 2 |
efvanmarrewijk | 7:7c005b3cf288 | 20 | u2>0; // Determines direction of motor 2 |
efvanmarrewijk | 7:7c005b3cf288 | 21 | pin6 = fabs(u2); // Determines pwm of motor 2 |
Ramonwaninge | 3:d39285fdd103 | 22 | } |
Ramonwaninge | 1:e40e981acbf1 | 23 | int main(){ |
efvanmarrewijk | 6:3c9569087274 | 24 | pin5.period_us(50); |
efvanmarrewijk | 6:3c9569087274 | 25 | motor.attach(draai, 0.001); |
efvanmarrewijk | 6:3c9569087274 | 26 | pin6.period_us(50); |
efvanmarrewijk | 6:3c9569087274 | 27 | motor.attach(draai, 0.001); |
efvanmarrewijk | 7:7c005b3cf288 | 28 | while(true) |
efvanmarrewijk | 7:7c005b3cf288 | 29 | { |
efvanmarrewijk | 7:7c005b3cf288 | 30 | |
Ramonwaninge | 3:d39285fdd103 | 31 | } |
Ramonwaninge | 0:3ea1bbfbeaae | 32 | } |