![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Studienleistung 1 FINAL (BETA-5)
main.cpp@0:738510c1e7fe, 2013-05-14 (annotated)
- Committer:
- chrish
- Date:
- Tue May 14 08:09:04 2013 +0000
- Revision:
- 0:738510c1e7fe
Left-Right-Blink
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chrish | 0:738510c1e7fe | 1 | #include "mbed.h" |
chrish | 0:738510c1e7fe | 2 | Ticker systick; |
chrish | 0:738510c1e7fe | 3 | volatile char bstandby; |
chrish | 0:738510c1e7fe | 4 | DigitalOut spg(p21); // U versorgung schalter |
chrish | 0:738510c1e7fe | 5 | DigitalOut spg2(p22); // U versorgung schalter |
chrish | 0:738510c1e7fe | 6 | DigitalOut rightled(LED4); |
chrish | 0:738510c1e7fe | 7 | DigitalOut leftled(LED1); |
chrish | 0:738510c1e7fe | 8 | DigitalIn left(p8); |
chrish | 0:738510c1e7fe | 9 | DigitalIn right(p14); |
chrish | 0:738510c1e7fe | 10 | Serial pc(USBTX, USBRX); |
chrish | 0:738510c1e7fe | 11 | Timer l; // Plink Timmer links |
chrish | 0:738510c1e7fe | 12 | Timer r; // Blinktimmer Rechts |
chrish | 0:738510c1e7fe | 13 | Timer pl; //BRELLTIMER LINKS; brellen und timeverschiebung für zustand dauerhaft plinken |
chrish | 0:738510c1e7fe | 14 | Timer pr; // BRELLTIMER RECHTS; brellen und timeverschiebung für zustand dauerhaft Plinken |
chrish | 0:738510c1e7fe | 15 | int anzleft; |
chrish | 0:738510c1e7fe | 16 | int anzright; |
chrish | 0:738510c1e7fe | 17 | int auswahlleft; |
chrish | 0:738510c1e7fe | 18 | int auswahlright; |
chrish | 0:738510c1e7fe | 19 | //==================================================00 |
chrish | 0:738510c1e7fe | 20 | void vTimer(void){ |
chrish | 0:738510c1e7fe | 21 | bstandby =1; |
chrish | 0:738510c1e7fe | 22 | } |
chrish | 0:738510c1e7fe | 23 | //================================================ |
chrish | 0:738510c1e7fe | 24 | void blinkswitch(DigitalOut *led, int *anz, int *auswahl, Timer *tim){ // tim = l oder r |
chrish | 0:738510c1e7fe | 25 | switch(*auswahl){ |
chrish | 0:738510c1e7fe | 26 | case 0: *led =0; |
chrish | 0:738510c1e7fe | 27 | break; |
chrish | 0:738510c1e7fe | 28 | case 1:{ |
chrish | 0:738510c1e7fe | 29 | if(tim->read()>= 0.3 || *anz == 8){ *led =! *led; tim->reset() ; *anz -=1; pc.printf(" %d",*anz);} |
chrish | 0:738510c1e7fe | 30 | if(*anz == 0) *auswahl = 0;} |
chrish | 0:738510c1e7fe | 31 | break; |
chrish | 0:738510c1e7fe | 32 | case 2:{ |
chrish | 0:738510c1e7fe | 33 | if((*tim).read() >= 0.3){ *led =! *led ; (*tim).reset();pc.printf("BIN IN SEc 2 " );} |
chrish | 0:738510c1e7fe | 34 | |
chrish | 0:738510c1e7fe | 35 | } |
chrish | 0:738510c1e7fe | 36 | break; |
chrish | 0:738510c1e7fe | 37 | |
chrish | 0:738510c1e7fe | 38 | } |
chrish | 0:738510c1e7fe | 39 | } |
chrish | 0:738510c1e7fe | 40 | |
chrish | 0:738510c1e7fe | 41 | //=?======================================================000 |
chrish | 0:738510c1e7fe | 42 | |
chrish | 0:738510c1e7fe | 43 | int main() { |
chrish | 0:738510c1e7fe | 44 | spg = 1; // Spannungsversorgung der angeschloosenen schalter |
chrish | 0:738510c1e7fe | 45 | spg2 =1; // Spannungsversorgung der angeschlossenen schalter |
chrish | 0:738510c1e7fe | 46 | auswahlleft = 0; |
chrish | 0:738510c1e7fe | 47 | auswahlright = 0; |
chrish | 0:738510c1e7fe | 48 | |
chrish | 0:738510c1e7fe | 49 | while(1) { |
chrish | 0:738510c1e7fe | 50 | // systick.attach_us(&vTimer, 200); |
chrish | 0:738510c1e7fe | 51 | if(left == 1){ |
chrish | 0:738510c1e7fe | 52 | //pc.printf("LINKS LIEGHT AN \n\n"); |
chrish | 0:738510c1e7fe | 53 | if(auswahlleft == 0 && pl.read() >= 0.05){auswahlleft =1; anzleft =8; l.start();pl.reset();pl.start();} |
chrish | 0:738510c1e7fe | 54 | if(auswahlleft ==1 && pl.read()>= 0.5) {auswahlleft = 2;pl.stop();pl.reset();} |
chrish | 0:738510c1e7fe | 55 | }else { |
chrish | 0:738510c1e7fe | 56 | if(auswahlleft ==2)auswahlleft =0; |
chrish | 0:738510c1e7fe | 57 | pl.start();} |
chrish | 0:738510c1e7fe | 58 | blinkswitch(&leftled,&anzleft, &auswahlleft, &l); |
chrish | 0:738510c1e7fe | 59 | |
chrish | 0:738510c1e7fe | 60 | if(right ==1){ |
chrish | 0:738510c1e7fe | 61 | if(auswahlright ==0 && pr.read() >= 0.05) { auswahlright =1; anzright= 8; r.start () ; pr.reset(); pr.start();} |
chrish | 0:738510c1e7fe | 62 | if(auswahlright == 1 && pr.read() >=0.5 ) { auswahlright =2 ; pr.stop(); pr.reset();} |
chrish | 0:738510c1e7fe | 63 | }else { |
chrish | 0:738510c1e7fe | 64 | if(auswahlright == 2) auswahlright =0; |
chrish | 0:738510c1e7fe | 65 | pr.start();} |
chrish | 0:738510c1e7fe | 66 | blinkswitch(&rightled,&anzright, &auswahlright, &r); |
chrish | 0:738510c1e7fe | 67 | // while(bstandby == 0); |
chrish | 0:738510c1e7fe | 68 | // bstandby = 1; |
chrish | 0:738510c1e7fe | 69 | }; |
chrish | 0:738510c1e7fe | 70 | } |