4.7 LED mittels Tastendruck ein- und ausschalten. (if/else, AnalogIn) mit Berücksichtigung Poti (PWM)
Dependencies: mbed
Fork of 04-02-Uebung by
main.cpp@1:60535236bc87, 2015-02-20 (annotated)
- Committer:
- stefan1691
- Date:
- Fri Feb 20 20:00:45 2015 +0000
- Revision:
- 1:60535236bc87
- Parent:
- 0:03cf1f3b043c
4.7 LED mittels Tastendruck ein- und ausschalten. (if/else, AnalogIn) mit Ber?cksichtigung Poti (PWM)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stefan1691 | 1:60535236bc87 | 1 | /** 4.7 LED mittels Tastendruck ein- und ausschalten. (if/else, AnalogIn) mit Berücksichtigung Poti (PWM) |
stefan1691 | 0:03cf1f3b043c | 2 | */ |
stefan1691 | 0:03cf1f3b043c | 3 | #include "mbed.h" |
stefan1691 | 0:03cf1f3b043c | 4 | |
stefan1691 | 0:03cf1f3b043c | 5 | DigitalIn b1( PTC9, PullUp ); |
stefan1691 | 0:03cf1f3b043c | 6 | DigitalIn b2( PTC0, PullUp ); |
stefan1691 | 1:60535236bc87 | 7 | |
stefan1691 | 1:60535236bc87 | 8 | PwmOut led( D13 ); |
stefan1691 | 1:60535236bc87 | 9 | AnalogIn poti ( A0 ); |
stefan1691 | 1:60535236bc87 | 10 | |
stefan1691 | 1:60535236bc87 | 11 | int on = 0; // On/Off Merker |
stefan1691 | 0:03cf1f3b043c | 12 | |
stefan1691 | 0:03cf1f3b043c | 13 | int main() |
stefan1691 | 0:03cf1f3b043c | 14 | { |
stefan1691 | 0:03cf1f3b043c | 15 | while (true) |
stefan1691 | 0:03cf1f3b043c | 16 | { |
stefan1691 | 1:60535236bc87 | 17 | // On / Off Buttons |
stefan1691 | 0:03cf1f3b043c | 18 | if ( b1 == 0 ) |
stefan1691 | 1:60535236bc87 | 19 | on = 1; |
stefan1691 | 0:03cf1f3b043c | 20 | if ( b2 == 0 ) |
stefan1691 | 1:60535236bc87 | 21 | on = 0; |
stefan1691 | 1:60535236bc87 | 22 | |
stefan1691 | 1:60535236bc87 | 23 | // LED |
stefan1691 | 1:60535236bc87 | 24 | if ( on ) |
stefan1691 | 1:60535236bc87 | 25 | led = poti; |
stefan1691 | 1:60535236bc87 | 26 | else |
stefan1691 | 1:60535236bc87 | 27 | led = 0; |
stefan1691 | 1:60535236bc87 | 28 | |
stefan1691 | 1:60535236bc87 | 29 | wait( 0.2 ); // ohne wait laesst sich das Board nicht neu programmieren! |
stefan1691 | 0:03cf1f3b043c | 30 | } |
stefan1691 | 0:03cf1f3b043c | 31 | } |