![](/media/cache/group/ep_LV4vK4D.webp.50x50_q85.jpg)
6.3 Motor mittels Tasten vor-, rückwärts, Stop laufen lassen und Poti benützen um die Geschwindigkeit einzustellen.
Dependencies: mbed
Fork of 06-08-Uebung by
main.cpp@2:48400c45778c, 2015-08-10 (annotated)
- Committer:
- stefan1691
- Date:
- Mon Aug 10 16:07:58 2015 +0000
- Revision:
- 2:48400c45778c
- Parent:
- 1:128f2b08a419
Verbessert - reagiert sofort auf Poti Aenderungen
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stefan1691 | 1:128f2b08a419 | 1 | /** 6.3 Motor mittels Tasten vor-, rückwärts, Stop laufen lassen und Poti benützen um die Geschwindigkeit einzustellen. |
marcel1691 | 0:5d64a3e741ec | 2 | */ |
marcel1691 | 0:5d64a3e741ec | 3 | |
marcel1691 | 0:5d64a3e741ec | 4 | #include "mbed.h" |
marcel1691 | 0:5d64a3e741ec | 5 | #include "Motor.h" |
marcel1691 | 0:5d64a3e741ec | 6 | |
marcel1691 | 0:5d64a3e741ec | 7 | // vor-/rueckwaerts - beide = Notstop |
stefan1691 | 1:128f2b08a419 | 8 | DigitalIn button1( A1 ); |
stefan1691 | 1:128f2b08a419 | 9 | DigitalIn button2( A2 ); |
marcel1691 | 0:5d64a3e741ec | 10 | |
marcel1691 | 0:5d64a3e741ec | 11 | // Geschwindigkeit |
marcel1691 | 0:5d64a3e741ec | 12 | AnalogIn poti ( A0 ); |
marcel1691 | 0:5d64a3e741ec | 13 | |
marcel1691 | 0:5d64a3e741ec | 14 | // Motor an M01 |
marcel1691 | 0:5d64a3e741ec | 15 | Motor m1(D3, D2, D4); // PWM, Vorwaerts, Rueckwarts |
stefan1691 | 2:48400c45778c | 16 | // Fahrrichtung 1 = vorwaerts, -1 = rueckwaerts |
stefan1691 | 2:48400c45778c | 17 | int dir = 1; |
marcel1691 | 0:5d64a3e741ec | 18 | |
marcel1691 | 0:5d64a3e741ec | 19 | int main() |
marcel1691 | 0:5d64a3e741ec | 20 | { |
marcel1691 | 0:5d64a3e741ec | 21 | while (true) |
marcel1691 | 0:5d64a3e741ec | 22 | { |
marcel1691 | 0:5d64a3e741ec | 23 | if ( button1 == 0 && button2 == 0 ) |
stefan1691 | 2:48400c45778c | 24 | dir = 0; |
marcel1691 | 0:5d64a3e741ec | 25 | else if ( button1 == 0 ) |
stefan1691 | 2:48400c45778c | 26 | dir = 1; |
marcel1691 | 0:5d64a3e741ec | 27 | else if ( button2 == 0 ) |
stefan1691 | 2:48400c45778c | 28 | dir = -1; |
stefan1691 | 2:48400c45778c | 29 | |
stefan1691 | 2:48400c45778c | 30 | m1.speed( poti * dir ); |
marcel1691 | 0:5d64a3e741ec | 31 | wait(0.2f); |
marcel1691 | 0:5d64a3e741ec | 32 | } |
marcel1691 | 0:5d64a3e741ec | 33 | } |