Christopher H
/
studienleistung_2_beta3
PWM_Modulation LED
main.cpp@0:42f712bdf324, 2013-05-14 (annotated)
- Committer:
- chrish
- Date:
- Tue May 14 08:10:57 2013 +0000
- Revision:
- 0:42f712bdf324
Studienleistung2_beta
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chrish | 0:42f712bdf324 | 1 | #include "mbed.h" |
chrish | 0:42f712bdf324 | 2 | #include "TextLCD.h" |
chrish | 0:42f712bdf324 | 3 | //#include "pwmled.h" |
chrish | 0:42f712bdf324 | 4 | Ticker systick; |
chrish | 0:42f712bdf324 | 5 | Ticker resetrut; |
chrish | 0:42f712bdf324 | 6 | |
chrish | 0:42f712bdf324 | 7 | volatile char bstandby; |
chrish | 0:42f712bdf324 | 8 | PwmOut led(LED1); |
chrish | 0:42f712bdf324 | 9 | DigitalIn hell(p10); |
chrish | 0:42f712bdf324 | 10 | DigitalIn dunk(p11); |
chrish | 0:42f712bdf324 | 11 | TextLCD lcd(p15, p16, p17, p18, p19, p20); |
chrish | 0:42f712bdf324 | 12 | int zahler; |
chrish | 0:42f712bdf324 | 13 | int zahleroff; |
chrish | 0:42f712bdf324 | 14 | |
chrish | 0:42f712bdf324 | 15 | //==================================================00 |
chrish | 0:42f712bdf324 | 16 | void vTimer(void){ |
chrish | 0:42f712bdf324 | 17 | |
chrish | 0:42f712bdf324 | 18 | bstandby =1;} |
chrish | 0:42f712bdf324 | 19 | //==================================== |
chrish | 0:42f712bdf324 | 20 | void reset(void){ |
chrish | 0:42f712bdf324 | 21 | if(hell==0 || dunk==0){ zahler = 0; zahleroff = 0;} |
chrish | 0:42f712bdf324 | 22 | } |
chrish | 0:42f712bdf324 | 23 | //=================================================== |
chrish | 0:42f712bdf324 | 24 | int main() { |
chrish | 0:42f712bdf324 | 25 | float pulsw; |
chrish | 0:42f712bdf324 | 26 | //void (*p)(); |
chrish | 0:42f712bdf324 | 27 | pulsw = 0.5; |
chrish | 0:42f712bdf324 | 28 | zahler =0 ; // Zähler wieviel mal die systemzeit durchgelaufen ist. |
chrish | 0:42f712bdf324 | 29 | zahleroff =0; |
chrish | 0:42f712bdf324 | 30 | bool on=0; |
chrish | 0:42f712bdf324 | 31 | //led = pulsw; |
chrish | 0:42f712bdf324 | 32 | systick.attach(&vTimer, 0.037); |
chrish | 0:42f712bdf324 | 33 | resetrut.attach(&reset, 1); |
chrish | 0:42f712bdf324 | 34 | while(1) { |
chrish | 0:42f712bdf324 | 35 | //============================================0 |
chrish | 0:42f712bdf324 | 36 | if(hell){ |
chrish | 0:42f712bdf324 | 37 | |
chrish | 0:42f712bdf324 | 38 | if(on){ |
chrish | 0:42f712bdf324 | 39 | if(!dunk){ |
chrish | 0:42f712bdf324 | 40 | lcd.locate(0,0); |
chrish | 0:42f712bdf324 | 41 | lcd.printf("HELL PRESS"); |
chrish | 0:42f712bdf324 | 42 | if(pulsw <= 0.98){ |
chrish | 0:42f712bdf324 | 43 | pulsw+= 0.01; |
chrish | 0:42f712bdf324 | 44 | led = pulsw;} |
chrish | 0:42f712bdf324 | 45 | } |
chrish | 0:42f712bdf324 | 46 | }else{ // EINSCHALTRUTINE !!!!!! |
chrish | 0:42f712bdf324 | 47 | if(dunk){ |
chrish | 0:42f712bdf324 | 48 | if(zahler == 10){on = 1 ; led = pulsw; zahler = 0;} |
chrish | 0:42f712bdf324 | 49 | else zahler +=1; |
chrish | 0:42f712bdf324 | 50 | } |
chrish | 0:42f712bdf324 | 51 | } |
chrish | 0:42f712bdf324 | 52 | } |
chrish | 0:42f712bdf324 | 53 | //===============================================0 |
chrish | 0:42f712bdf324 | 54 | if(dunk){ |
chrish | 0:42f712bdf324 | 55 | if(on){ |
chrish | 0:42f712bdf324 | 56 | if(hell){ // ausschaltrutine !!!!! |
chrish | 0:42f712bdf324 | 57 | if(zahleroff == 10 ){ on = 0; led =0; zahleroff = 0;} |
chrish | 0:42f712bdf324 | 58 | else zahleroff +=1; |
chrish | 0:42f712bdf324 | 59 | }else{ |
chrish | 0:42f712bdf324 | 60 | lcd.locate(0,0); |
chrish | 0:42f712bdf324 | 61 | lcd.printf("DUNK PRESS"); |
chrish | 0:42f712bdf324 | 62 | if(pulsw >= 0.02){ |
chrish | 0:42f712bdf324 | 63 | pulsw -= 0.01; |
chrish | 0:42f712bdf324 | 64 | led = pulsw; |
chrish | 0:42f712bdf324 | 65 | } |
chrish | 0:42f712bdf324 | 66 | } |
chrish | 0:42f712bdf324 | 67 | } |
chrish | 0:42f712bdf324 | 68 | } |
chrish | 0:42f712bdf324 | 69 | //==================================================== |
chrish | 0:42f712bdf324 | 70 | // lcd.cls(); |
chrish | 0:42f712bdf324 | 71 | lcd.locate(0,1); |
chrish | 0:42f712bdf324 | 72 | lcd.printf("%f",pulsw); |
chrish | 0:42f712bdf324 | 73 | lcd.locate(9,1); |
chrish | 0:42f712bdf324 | 74 | lcd.printf("%d",zahler); |
chrish | 0:42f712bdf324 | 75 | lcd.locate(13,1); |
chrish | 0:42f712bdf324 | 76 | lcd.printf("%d",zahleroff); |
chrish | 0:42f712bdf324 | 77 | while(bstandby == 0) {}; |
chrish | 0:42f712bdf324 | 78 | bstandby = 0; |
chrish | 0:42f712bdf324 | 79 | } |
chrish | 0:42f712bdf324 | 80 | } |