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
Diff: main.cpp
- Revision:
- 9:65c52c1f4a57
- Parent:
- 6:3c9569087274
- Child:
- 10:ac36f9a204dd
--- a/main.cpp Mon Oct 08 08:16:05 2018 +0000 +++ b/main.cpp Mon Oct 08 10:30:19 2018 +0000 @@ -7,13 +7,48 @@ AnalogIn pot1(A1); AnalogIn pot2(A2); +InterruptIn button2(SW2); +InterruptIn button3(SW3); + +FastPWM pin3(D3); // Motor 3 pwm +DigitalOut pin2(D2); // Motor 3 direction FastPWM pin5(D5); // Motor 2 pwm DigitalOut pin4(D4); // Motor 2 direction FastPWM pin6(D6); // Motor 1 pwm DigitalOut pin7(D7); // Motor 1 direction //float u1 = pot1; -void draai(){ +float b; + +void draaisnel() + { if(button2 == 1) + { //Hier maak ik een interrupt voor meer snelheid + b = 0.4; //In stapjes van 0.1 + pin3 = fabs(b); + } + } +void draailangzaam() + { if(button3 == 1) + { //Interrupt voor minder snelheid + b = -0.4; + pin3 = fabs(b); + } + } + +void draai() +{ if (b>0) + { pin2 = true; + b = b+0.1; + } + else if(b<0) + { pin2 = false; + b = b-0.1; + } + else + { pin3 = 0; + } + pin3 = fabs(b); + float u1 = 2.0*(pot1 - 0.5); if (u1>0) { pin4 = true; @@ -33,6 +68,13 @@ pin6 = fabs(u2); } int main(){ + + pin5.period(1.0/10000); + button2.rise(&draaisnel); // interrupt koppelen + button3.rise(&draailangzaam); + + pin3.period_us(50); + motor.attach(draai, 0.001); pin5.period_us(50); motor.attach(draai, 0.001);