bsp1
WIKI: https://os.mbed.com/users/robertbuc/code/Robert-Buch/wiki/Special:Allpages
A2_Lekt6_testbsp2_testteil.cpp@0:29997c4d194b, 2020-01-12 (annotated)
- Committer:
- robertbuc
- Date:
- Sun Jan 12 22:51:08 2020 +0000
- Revision:
- 0:29997c4d194b
bsp1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
robertbuc | 0:29997c4d194b | 1 | /* |
robertbuc | 0:29997c4d194b | 2 | Schreiben Sie ein Programm für einen mbed-Mikrocontroller in C nach folgenden Angaben: |
robertbuc | 0:29997c4d194b | 3 | |
robertbuc | 0:29997c4d194b | 4 | a) Nach dem Programmstart (Reset) wird ein Begrüßungstext auf einem Terminal-Programm |
robertbuc | 0:29997c4d194b | 5 | ausgeben: "Joystick Testprogram copyright Ihr Nachname" |
robertbuc | 0:29997c4d194b | 6 | |
robertbuc | 0:29997c4d194b | 7 | b) Mit Betätigung der Taste Joystick-Left werden die äußeren blauen LEDs für 10 sec |
robertbuc | 0:29997c4d194b | 8 | eingeschaltet. |
robertbuc | 0:29997c4d194b | 9 | |
robertbuc | 0:29997c4d194b | 10 | c) Eine Betätigung dieser Taste (Joystick-Left) innerhalb der 10 sec des Leuchtens |
robertbuc | 0:29997c4d194b | 11 | der beiden äußeren LEDs führt zu folgender Ausgabe am Terminal-Programm: |
robertbuc | 0:29997c4d194b | 12 | Der Tastendruck der Taste Joystick-Left wird ignoriert: |
robertbuc | 0:29997c4d194b | 13 | Die beiden äußeren LEDs leuchten. |
robertbuc | 0:29997c4d194b | 14 | |
robertbuc | 0:29997c4d194b | 15 | d) Nach Ablauf der 10 sec: LEDs werden gelöscht und weiter bei b) |
robertbuc | 0:29997c4d194b | 16 | */ |
robertbuc | 0:29997c4d194b | 17 | |
robertbuc | 0:29997c4d194b | 18 | #include "mbed.h" |
robertbuc | 0:29997c4d194b | 19 | |
robertbuc | 0:29997c4d194b | 20 | //BusOut leds(D0,D3,D6,D9); |
robertbuc | 0:29997c4d194b | 21 | |
robertbuc | 0:29997c4d194b | 22 | PwmOut led1(D0); |
robertbuc | 0:29997c4d194b | 23 | PwmOut led2(D3); |
robertbuc | 0:29997c4d194b | 24 | PwmOut led3(D6); |
robertbuc | 0:29997c4d194b | 25 | PwmOut led4(D9); |
robertbuc | 0:29997c4d194b | 26 | |
robertbuc | 0:29997c4d194b | 27 | AnalogIn y(A3); |
robertbuc | 0:29997c4d194b | 28 | AnalogIn x(A4); |
robertbuc | 0:29997c4d194b | 29 | DigitalIn joybtn(D10); |
robertbuc | 0:29997c4d194b | 30 | //Interrupt xisr(A4); //funktioniert nicht gemeinsam |
robertbuc | 0:29997c4d194b | 31 | |
robertbuc | 0:29997c4d194b | 32 | int main() |
robertbuc | 0:29997c4d194b | 33 | { |
robertbuc | 0:29997c4d194b | 34 | |
robertbuc | 0:29997c4d194b | 35 | printf("Joystick Testprogramm copyright Robert Buch\n"); |
robertbuc | 0:29997c4d194b | 36 | int i=0; |
robertbuc | 0:29997c4d194b | 37 | |
robertbuc | 0:29997c4d194b | 38 | while(1) |
robertbuc | 0:29997c4d194b | 39 | { |
robertbuc | 0:29997c4d194b | 40 | if(x.read()<=0.1) //links |
robertbuc | 0:29997c4d194b | 41 | { |
robertbuc | 0:29997c4d194b | 42 | i=1; |
robertbuc | 0:29997c4d194b | 43 | led1.period(11); |
robertbuc | 0:29997c4d194b | 44 | led1.pulsewidth(10); |
robertbuc | 0:29997c4d194b | 45 | |
robertbuc | 0:29997c4d194b | 46 | led4.period(11); |
robertbuc | 0:29997c4d194b | 47 | led4.pulsewidth(10); |
robertbuc | 0:29997c4d194b | 48 | } |
robertbuc | 0:29997c4d194b | 49 | else |
robertbuc | 0:29997c4d194b | 50 | { |
robertbuc | 0:29997c4d194b | 51 | led1=0; |
robertbuc | 0:29997c4d194b | 52 | led4=0; |
robertbuc | 0:29997c4d194b | 53 | i=0; |
robertbuc | 0:29997c4d194b | 54 | } |
robertbuc | 0:29997c4d194b | 55 | |
robertbuc | 0:29997c4d194b | 56 | if((x.read()<=0.1)&&(i==1)) //Problem: nicht "ENTPRELLT" |
robertbuc | 0:29997c4d194b | 57 | { |
robertbuc | 0:29997c4d194b | 58 | printf("Joyleft-Tastendruck wird ignoriert: Die beiden Außenleds leuchten\n"); |
robertbuc | 0:29997c4d194b | 59 | } |
robertbuc | 0:29997c4d194b | 60 | } |
robertbuc | 0:29997c4d194b | 61 | } |