![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
lololololol
Dependencies: mbed QEI HIDScope biquadFilter MODSERIAL FastPWM
main.cpp@14:20f11bb58244, 2019-09-23 (annotated)
- Committer:
- Hendrikvg
- Date:
- Mon Sep 23 08:17:52 2019 +0000
- Revision:
- 14:20f11bb58244
- Parent:
- 9:12b9865e7373
- Child:
- 15:80b3ac2b8448
Motor 1 aan en uit zetten werkt, snelheid en richting aansturen nog niet.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Hendrikvg | 9:12b9865e7373 | 1 | #include "mbed.h" |
Hendrikvg | 14:20f11bb58244 | 2 | #include "FastPWM.h" |
Hendrikvg | 14:20f11bb58244 | 3 | |
Hendrikvg | 14:20f11bb58244 | 4 | // Motor 1 aan zetten en uit zetten dmv button 1 en 2 werkt. |
Hendrikvg | 14:20f11bb58244 | 5 | // Snelheid aansturen nog niet. |
Hendrikvg | 9:12b9865e7373 | 6 | |
Hendrikvg | 9:12b9865e7373 | 7 | Serial pc(USBTX,USBRX); |
Hendrikvg | 9:12b9865e7373 | 8 | InterruptIn BUT1(D1); |
Hendrikvg | 9:12b9865e7373 | 9 | InterruptIn BUT2(D0); |
Hendrikvg | 14:20f11bb58244 | 10 | FastPWM lichtje(D3); |
Hendrikvg | 9:12b9865e7373 | 11 | AnalogIn ain(A0); |
Hendrikvg | 14:20f11bb58244 | 12 | DigitalOut direction(D6); |
Hendrikvg | 14:20f11bb58244 | 13 | DigitalOut speed(D7); |
RobertoO | 0:67c50348f842 | 14 | |
Hendrikvg | 9:12b9865e7373 | 15 | float getal; |
Hendrikvg | 9:12b9865e7373 | 16 | int n=5; |
Hendrikvg | 2:d9b0ebf3fcca | 17 | |
Hendrikvg | 9:12b9865e7373 | 18 | void plus() |
Hendrikvg | 9:12b9865e7373 | 19 | { |
Hendrikvg | 9:12b9865e7373 | 20 | n++; // n=n+1 |
Hendrikvg | 14:20f11bb58244 | 21 | direction = 1; |
Hendrikvg | 9:12b9865e7373 | 22 | if (n>10){ |
Hendrikvg | 9:12b9865e7373 | 23 | n=10; |
Hendrikvg | 9:12b9865e7373 | 24 | } |
Hendrikvg | 9:12b9865e7373 | 25 | } |
Hendrikvg | 9:12b9865e7373 | 26 | |
Hendrikvg | 9:12b9865e7373 | 27 | void min() |
Hendrikvg | 8:d1794f225fff | 28 | { |
Hendrikvg | 9:12b9865e7373 | 29 | n--; |
Hendrikvg | 14:20f11bb58244 | 30 | direction = 0; |
Hendrikvg | 9:12b9865e7373 | 31 | if (n<0){ |
Hendrikvg | 9:12b9865e7373 | 32 | n=0; |
Hendrikvg | 9:12b9865e7373 | 33 | } |
Hendrikvg | 7:d307e31f7391 | 34 | } |
Hendrikvg | 7:d307e31f7391 | 35 | |
Hendrikvg | 9:12b9865e7373 | 36 | int main() { |
RobertoO | 0:67c50348f842 | 37 | pc.baud(115200); |
Hendrikvg | 9:12b9865e7373 | 38 | lichtje=1; |
Hendrikvg | 9:12b9865e7373 | 39 | BUT1.fall(plus); |
Hendrikvg | 9:12b9865e7373 | 40 | BUT2.fall(min); |
Hendrikvg | 9:12b9865e7373 | 41 | while(true) |
Hendrikvg | 9:12b9865e7373 | 42 | { |
Hendrikvg | 14:20f11bb58244 | 43 | getal = 0.1*n*ain.read(); |
Hendrikvg | 14:20f11bb58244 | 44 | speed = 0.1*n*ain.read(); |
Hendrikvg | 14:20f11bb58244 | 45 | lichtje.period_ms(20); // 4 second period |
Hendrikvg | 9:12b9865e7373 | 46 | lichtje.write(getal); // duty cycle |
Hendrikvg | 14:20f11bb58244 | 47 | speed.write(getal); |
Hendrikvg | 14:20f11bb58244 | 48 | pc.printf("%3.3f%\n\r", getal); |
Hendrikvg | 9:12b9865e7373 | 49 | |
Hendrikvg | 9:12b9865e7373 | 50 | } |
Hendrikvg | 2:d9b0ebf3fcca | 51 | } |