Alle DIC Uebungen bis 3D

Dependencies:   C12832 mbed

Fork of HelloWorld by Simon Ford

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "C12832.h"
00003 
00004 #define EaaE 9
00005 #define aEEa 6
00006 #define Eaaa 8
00007 #define EEaa 12
00008 #define EEEa 14
00009 #define EEEE 15
00010 #define aEEE 7
00011 #define aaEE 3
00012 #define aaaE 1
00013 #define aaaa 0
00014 #define aEaa 4
00015 #define aaEa 2
00016 
00017 C12832 lcd(p5, p7, p6, p8, p11);
00018 
00019 Serial fs(USBTX, USBRX);
00020 DigitalOut myled1(LED1);
00021 DigitalOut myled2(LED2);
00022 DigitalOut myled3(LED3);
00023 DigitalOut myled4(LED4);
00024 
00025 BusOut Leds(LED1, LED2, LED3, LED4);
00026 BusOut RGBLed(p23, p24, p25);
00027 //             R    G    B
00028 // ÜBUNG 1: B
00029 /*
00030 void switchLeds(int led1, int led2, int led3, int led4, float time)
00031 {
00032  myled1 = led1;
00033  myled2 = led2;
00034  myled3 = led3;
00035  myled4 = led4;   
00036  wait(time);
00037 }
00038 
00039 
00040 int main() {
00041     
00042         switchLeds(1,0,0,1, 2.0);
00043         switchLeds(0,1,1,0, 2.0);
00044         while(1)
00045         {
00046         switchLeds(1,0,0,0, 0.6);
00047         switchLeds(1,1,0,0, 0.6);
00048         switchLeds(1,1,1,0, 0.6);
00049         switchLeds(1,1,1,1, 0.6);
00050         switchLeds(0,1,1,1, 0.6);
00051         switchLeds(0,0,1,1, 0.6);
00052         switchLeds(0,0,0,1, 0.6);
00053         switchLeds(0,0,0,0, 0.6);
00054         }
00055         
00056         
00057         
00058     
00059 }
00060 */
00061 // ÜBUNG 1: C
00062 /*
00063 void switchLeds(char led1, char led2, char led3, char led4, float time)
00064 {
00065  if(led1 == 'E') myled1 = 1;
00066  else            myled1 = 0;
00067  if(led2 == 'E') myled2 = 1;
00068  else            myled2 = 0;
00069  if(led3 == 'E') myled3 = 1;
00070  else            myled3 = 0;
00071  if(led4 == 'E') myled4 = 1;
00072  else            myled4 = 0;  
00073  wait(time);
00074 }
00075 int main() {
00076     
00077         switchLeds('E','a','a','E', 2.0);
00078         switchLeds('a','E','E','a', 2.0);
00079         while(1)
00080         {
00081         switchLeds('E','a','a','a', 0.6);
00082         switchLeds('E','E','a','a', 0.6);
00083         switchLeds('E','E','E','a', 0.6);
00084         switchLeds('E','E','E','E', 0.6);
00085         switchLeds('a','E','E','E', 0.6);
00086         switchLeds('a','a','E','E', 0.6);
00087         switchLeds('a','a','a','E', 0.6);
00088         switchLeds('a','a','a','a', 0.6);
00089         }
00090         
00091         
00092         
00093     
00094 }
00095 */
00096 // ÜBUNG 1: D
00097 /*
00098 int timefor = 5.0;
00099 
00100 void switchLeds(char led1, char led2, char led3, char led4, float time)
00101 {
00102  if(led1 == 'E') Leds = 0x01;
00103  else            Leds = 0x00;
00104  if(led2 == 'E') Leds = 0x02;
00105  else            Leds = 0x00;
00106  if(led3 == 'E') Leds = 0x04;
00107  else            Leds = 0x00;
00108  if(led4 == 'E') Leds = 0x08;
00109  else            Leds = 0x00;  
00110  wait(time);
00111  
00112 }
00113 
00114 int main() {
00115         for(int i = 0; i<5; i++)
00116         {
00117         Leds = 0x9;
00118         wait(timefor);
00119         Leds = 0x6;
00120         wait(timefor);
00121         timefor--;
00122         }
00123         Leds = 0x0;
00124         wait(1);
00125         while(1)
00126         {
00127         Leds = 0x8;
00128         wait(0.6);
00129         Leds = 0xC;
00130         wait(0.6);
00131         Leds = 0xE;
00132         wait(0.6);
00133         Leds = 0xF;
00134         wait(0.6);
00135         Leds = 0x7;
00136         wait(0.6);
00137         Leds = 0x3;
00138         wait(0.6);
00139         Leds = 0x1;
00140         wait(0.6);
00141         Leds = 0x0;
00142         wait(0.6);
00143         }
00144         
00145         
00146         
00147     
00148 }
00149 */
00150 // ÜBUNG 1: E
00151 /*
00152 void switchLeds(int Busvalue, double time)
00153 {
00154  Leds = Busvalue;
00155  wait(time);
00156 }
00157 int timefor = 5.0;
00158 int main ()
00159 {
00160     for(int i = 0; i<5; i++)
00161         {
00162         switchLeds(EaaE, timefor);
00163         switchLeds(aEEa, timefor);
00164         
00165         timefor--;
00166         }
00167         
00168         switchLeds(aaaa, 1.0);
00169         
00170         while(1)
00171         {
00172         switchLeds(Eaaa, 0.6);
00173     
00174         switchLeds(EEaa, 0.6);
00175         
00176         switchLeds(EEEa, 0.6);
00177         
00178         switchLeds(EEEE, 0.6);
00179         
00180         switchLeds(aEEE, 0.6);
00181         
00182         switchLeds(aaEE, 0.6);
00183         
00184         switchLeds(aaaE, 0.6);
00185         
00186         switchLeds(aaaa, 0.6);
00187         }
00188 }
00189 */
00190 // ÜBUNG 2: A
00191 /*
00192 void switchLeds(int Busvalue, double time)
00193 {
00194  Leds = Busvalue;
00195  wait(time);
00196 }
00197 
00198 int main ()
00199 {
00200     
00201         switchLeds(EEEE, 2.0);
00202         switchLeds(aaaa, 2.0);
00203         
00204         
00205         while(1)
00206         {
00207         switchLeds(Eaaa, 0.5);
00208     
00209         switchLeds(aEaa, 0.5);
00210         
00211         switchLeds(aaEa, 0.5);
00212         
00213         switchLeds(aaaE, 0.5);
00214         }
00215 }
00216 */
00217 // ÜBUNG 2: B
00218 /*
00219 void switchLeds(int Busvalue, double time)
00220 {
00221  Leds = Busvalue;
00222  wait(time);
00223 }
00224 char ledValue;
00225 int main ()
00226 {
00227     
00228         switchLeds(EEEE, 2.0);
00229         switchLeds(aaaa, 2.0);
00230         
00231         
00232         while(1)
00233         {
00234         for(int i=0; i<6; i++)
00235             {
00236             Leds = 0x8;
00237             wait(0.5);
00238             Leds = Leds >> 1;
00239             wait(0.5);
00240             Leds = Leds >> 1;
00241             wait(0.5);
00242             Leds = Leds >> 1;
00243             wait(0.5);
00244             }
00245         for(int i=0; i<4; i++)
00246         {
00247             Leds = 0x0;
00248             wait(0.5);
00249             Leds = 0x1;
00250             wait(0.5);
00251             Leds = Leds << 1;
00252             wait(0.5);
00253             Leds = Leds << 1;
00254             wait(0.5);
00255             Leds = Leds << 1;
00256             wait(0.5);
00257         }
00258         }
00259 }
00260 */
00261 // ÜBUNG 2: C
00262 /*
00263 void switchLeds(int Busvalue, double time)
00264 {
00265  Leds = Busvalue;
00266  wait(time);
00267 }
00268 char ledValue;
00269 int main ()
00270 {
00271     
00272         switchLeds(EEEE, 2.0);
00273         switchLeds(aaaa, 2.0);
00274         
00275         
00276         while(1)
00277         {
00278         for(int i=0; i<6; i++)
00279             {
00280             Leds = 0x8;
00281             wait(0.5);
00282             Leds = 0xC;
00283             wait(0.5);
00284             Leds = Leds >> 1;
00285             wait(0.5);
00286             Leds = Leds >> 1;
00287             wait(0.5);
00288             Leds = Leds >> 1;
00289             wait(0.5);
00290             }
00291         for(int i=0; i<4; i++)
00292         {
00293             Leds = 0x0;
00294             wait(0.33);
00295             Leds = 0x1;
00296             wait(0.33);
00297             Leds = 0x3;
00298             wait(0.33);
00299             Leds = Leds << 1;
00300             wait(0.33);
00301             Leds = Leds << 1;
00302             wait(0.33);
00303             Leds = Leds << 1;
00304             wait(0.33);
00305         }
00306         }
00307 }
00308 */
00309 // ÜBUNG 2: D | E
00310 /*
00311 void switchLeds(int Busvalue, double time)
00312 {
00313  Leds = Busvalue;
00314  wait(time);
00315 }
00316 char ledValue;
00317 int main ()
00318 {      
00319     RGBLed = 15;
00320         while(1)
00321         {
00322              RGBLed = 6;
00323              wait(20);
00324              RGBLed = 4;
00325              Leds = 0x6;
00326              wait(4);
00327              RGBLed = 5;
00328              wait(14);
00329             for(int i=0; i<4; i++)
00330             {
00331              RGBLed = 7;
00332              wait(0.5);
00333              RGBLed = 5;
00334              wait(0.5);
00335              }
00336              RGBLed = 4;
00337              Leds = 0x6;
00338              wait(5);
00339              
00340         }
00341 }
00342 */
00343 // ÜBUNG 2: F
00344 
00345 /*
00346 void tlRed(int msec)
00347 {
00348     RGBLed = 6;
00349     wait_ms(msec);
00350 }
00351 void tlRedYellow(int msec, int addBlueLeds)
00352 {
00353     RGBLed = 4;
00354     
00355     Leds = addBlueLeds;
00356     wait_ms(msec); 
00357     Leds = 0;
00358     
00359 }    
00360 void tlYellow(int msec)
00361 {
00362     RGBLed = 4;
00363     wait_ms(msec);
00364 }
00365 void tlGreen(int msec)
00366 {
00367     RGBLed = 5;
00368     wait_ms(msec);
00369 }
00370 void tlBlinkGreen(int howOften, int periodeMsec)
00371 {
00372     for(int i=0; i<howOften; i++)
00373         {
00374              RGBLed = 7;
00375              wait_ms((periodeMsec / 2));
00376              RGBLed = 5;
00377              wait_ms((periodeMsec / 2));
00378         }
00379 }
00380 void tlClear()
00381 {
00382     RGBLed = 7;
00383 }
00384 char ledValue;
00385 int main ()
00386 {      
00387     tlClear();
00388         while(1)
00389         {
00390              tlRed(20000);
00391              tlRedYellow(4000, 6);
00392              tlGreen(14000);
00393              tlBlinkGreen(4, 1000);
00394              tlYellow(5000);
00395              
00396              
00397         }
00398 }
00399 */
00400 // Übung 3: A
00401 /*
00402 int a = 0;
00403 int i = 0;
00404 int main ()
00405 {      
00406     while(1)
00407     {
00408         while(a < 15)
00409         {
00410             a++;
00411             wait(1);
00412              fs.printf("Zaehlerstand = %i, Anzahl der Ueberlaufe = %i\n", a, i);
00413              
00414         }
00415         i++;
00416         a = 0;
00417     }
00418 }
00419 */
00420 // Übung 3: B
00421 /*
00422 int durchlaeufe = 0;
00423 void tlRed(int msec)
00424 {
00425     float sec = msec / 1000;
00426     RGBLed = 6;
00427     fs.printf("Phase: ROT, Dauer = %lfsec, Anzahl der Ampeldurchlaeufe = %i\n", sec, durchlaeufe);
00428     wait_ms(msec);
00429 }
00430 void tlRedYellow(int msec, int addBlueLeds)
00431 {
00432     float sec = msec / 1000;
00433     RGBLed = 4;
00434     fs.printf("Phase: ROTGELB, Dauer = %lfsec, Anzahl der Ampeldurchlaeufe = %i\n", sec, durchlaeufe);
00435     Leds = addBlueLeds;
00436     wait_ms(msec); 
00437     Leds = 0;
00438     
00439 }    
00440 void tlYellow(int msec)
00441 {
00442     float sec = msec / 1000;
00443     RGBLed = 4;
00444     fs.printf("Phase: GELB, Dauer = %lfsec, Anzahl der Ampeldurchlaeufe = %i\n", sec, durchlaeufe);
00445     wait_ms(msec);
00446 }
00447 void tlGreen(int msec)
00448 {
00449     float sec = msec / 1000;
00450     RGBLed = 5;
00451     fs.printf("Phase: GRUEN, Dauer = %lfsec, Anzahl der Ampeldurchlaeufe = %i\n", sec, durchlaeufe);
00452     wait_ms(msec);
00453 }
00454 void tlBlinkGreen(int howOften, int periodeMsec)
00455 {
00456     float sec = periodeMsec / 1000;
00457     fs.printf("Phase: GRUENBLINKEN, Dauer = %lfsec, Anzahl der Ampeldurchlaeufe = %i\n", sec, durchlaeufe);
00458     for(int i=0; i<howOften; i++)
00459         {
00460              RGBLed = 7;
00461              wait_ms((periodeMsec / 2));
00462              RGBLed = 5;
00463              wait_ms((periodeMsec / 2));
00464         }
00465 }
00466 void tlClear()
00467 {
00468     RGBLed = 7;
00469 }
00470 char ledValue;
00471 int main ()
00472 {      
00473     tlClear();
00474         while(1)
00475         {
00476              tlRed(20000);
00477              tlRedYellow(4000, 6);
00478              tlGreen(14000);
00479              tlBlinkGreen(4, 1000);
00480              tlYellow(5000);
00481              durchlaeufe++;
00482              
00483              
00484         }
00485 }
00486 */
00487 // Übung 3: C
00488 /*
00489 int auf = 0;
00490 int ab = 0;
00491 int zaehlerstand = 0;
00492 void switchLeds(char led1, char led2, char led3, char led4, float time)
00493 {
00494  if(led1 == 'E') myled1 = 1;
00495  else            myled1 = 0;
00496  if(led2 == 'E') myled2 = 1;
00497  else            myled2 = 0;
00498  if(led3 == 'E') myled3 = 1;
00499  else            myled3 = 0;
00500  if(led4 == 'E') myled4 = 1;
00501  else            myled4 = 0;  
00502  wait(time);
00503 }
00504 void zaehlerAuf()
00505 {
00506         auf++;
00507         RGBLed = 3;
00508         switchLeds('a','a','a','a', 0.5);
00509          zaehlerstand = 0;
00510         fs.printf("Zaehlerstand: %i ,Abwaertszyklen: %i ,Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00511         switchLeds('a','a','a','E', 0.5);
00512          zaehlerstand++;
00513         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00514         switchLeds('a','a','E','a', 0.5);
00515          zaehlerstand++;
00516         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00517         switchLeds('a','a','E','E', 0.5);
00518          zaehlerstand++;
00519         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00520         switchLeds('a','E','a','a', 0.5);
00521          zaehlerstand++;
00522         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00523         switchLeds('a','E','a','E', 0.5);
00524          zaehlerstand++;
00525         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00526         switchLeds('a','E','E','a', 0.5);
00527          zaehlerstand++;
00528         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00529         switchLeds('a','E','E','E', 0.5);
00530          zaehlerstand++;
00531         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00532         switchLeds('E','a','a','a', 0.5);
00533          zaehlerstand++;
00534         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00535         switchLeds('E','a','a','E', 0.5);
00536          zaehlerstand++;
00537         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00538         switchLeds('E','a','E','a', 0.5);
00539          zaehlerstand++;
00540         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00541         switchLeds('E','a','E','E', 0.5);
00542          zaehlerstand++;
00543         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00544         switchLeds('E','E','a','a', 0.5);
00545          zaehlerstand++;
00546         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00547         switchLeds('E','E','a','E', 0.5);
00548          zaehlerstand++;
00549         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00550         switchLeds('E','E','E','a', 0.5);
00551          zaehlerstand++;
00552         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00553         switchLeds('E','E','E','E', 0.5);
00554          zaehlerstand++;
00555         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00556       
00557 }
00558 void zaehlerAb()
00559 {
00560         ab++; 
00561         RGBLed = 6;
00562         switchLeds('E','E','E','E', 0.5);
00563          zaehlerstand = 15;
00564         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00565         switchLeds('E','E','E','a', 0.5);
00566          zaehlerstand--;
00567         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00568         switchLeds('E','E','a','E', 0.5);
00569         zaehlerstand--;
00570         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00571         switchLeds('E','E','a','a', 0.5);
00572         zaehlerstand--;
00573         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00574         switchLeds('E','a','E','E', 0.5);
00575         zaehlerstand--;
00576         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00577         switchLeds('E','a','E','a', 0.5);
00578         zaehlerstand--;
00579         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00580         switchLeds('E','a','a','E', 0.5);
00581         zaehlerstand--;
00582         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00583         switchLeds('E','a','a','a', 0.5);
00584         zaehlerstand--;
00585         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00586         switchLeds('a','E','E','E', 0.5);
00587         zaehlerstand--;
00588         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00589         switchLeds('a','E','E','a', 0.5);
00590         zaehlerstand--;
00591         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00592         switchLeds('a','E','a','E', 0.5);
00593         zaehlerstand--;
00594         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00595         switchLeds('a','E','a','a', 0.5);
00596         zaehlerstand--;
00597         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00598         switchLeds('a','a','E','E', 0.5);
00599         zaehlerstand--;
00600         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00601         switchLeds('a','a','E','a', 0.5);
00602         zaehlerstand--;
00603         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00604         switchLeds('a','a','a','E', 0.5);
00605         zaehlerstand--;
00606         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00607         switchLeds('a','a','a','a', 0.5);    
00608         zaehlerstand--;
00609         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00610         
00611         
00612 }
00613 int main ()
00614 {      
00615     RGBLed = 7;
00616      while(1)
00617     {
00618         RGBLed = 4;
00619         switchLeds('a','a','a','a', 0.5); 
00620         fs.printf("Bitte eingeben ob der Zaehler auf [u] oder ab [d] zaehlen soll: \n");
00621         char richtung = fs.getc();
00622         if (richtung == 'u')
00623         {
00624             zaehlerAuf();
00625         }
00626         else if (richtung == 'd')
00627         {
00628             zaehlerAb();
00629         }
00630         else
00631         {
00632             fs.printf("Fehler\n");
00633         }
00634     }
00635 }
00636 */
00637 // Übung 3: D
00638 /*
00639 int auf = 0;
00640 int ab = 0;
00641 int zaehlerstand = 0;
00642 float frequenz = 0;
00643 int frequenzEingabe;
00644 void switchLeds(char led1, char led2, char led3, char led4, float time)
00645 {
00646  if(led1 == 'E') myled1 = 1;
00647  else            myled1 = 0;
00648  if(led2 == 'E') myled2 = 1;
00649  else            myled2 = 0;
00650  if(led3 == 'E') myled3 = 1;
00651  else            myled3 = 0;
00652  if(led4 == 'E') myled4 = 1;
00653  else            myled4 = 0;  
00654  wait(time);
00655 }
00656 void zaehlerAuf()
00657 {
00658         auf++;
00659         RGBLed = 3;
00660         switchLeds('a','a','a','a', frequenz);
00661          zaehlerstand = 0;
00662         fs.printf("Zaehlerstand: %i ,Abwaertszyklen: %i ,Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00663         switchLeds('a','a','a','E', frequenz);
00664          zaehlerstand++;
00665         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00666         switchLeds('a','a','E','a', frequenz);
00667          zaehlerstand++;
00668         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00669         switchLeds('a','a','E','E', frequenz);
00670          zaehlerstand++;
00671         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00672         switchLeds('a','E','a','a', frequenz);
00673          zaehlerstand++;
00674         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00675         switchLeds('a','E','a','E', frequenz);
00676          zaehlerstand++;
00677         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00678         switchLeds('a','E','E','a', frequenz);
00679          zaehlerstand++;
00680         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00681         switchLeds('a','E','E','E', frequenz);
00682          zaehlerstand++;
00683         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00684         switchLeds('E','a','a','a', frequenz);
00685          zaehlerstand++;
00686         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00687         switchLeds('E','a','a','E', frequenz);
00688          zaehlerstand++;
00689         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00690         switchLeds('E','a','E','a', frequenz);
00691          zaehlerstand++;
00692         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00693         switchLeds('E','a','E','E', frequenz);
00694          zaehlerstand++;
00695         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00696         switchLeds('E','E','a','a', frequenz);
00697          zaehlerstand++;
00698         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00699         switchLeds('E','E','a','E', frequenz);
00700          zaehlerstand++;
00701         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00702         switchLeds('E','E','E','a', frequenz);
00703          zaehlerstand++;
00704         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00705         switchLeds('E','E','E','E', frequenz);
00706          zaehlerstand++;
00707         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00708       
00709 }
00710 void zaehlerAb()
00711 {
00712         ab++; 
00713         RGBLed = 6;
00714         switchLeds('E','E','E','E', frequenz);
00715          zaehlerstand = 15;
00716         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00717         switchLeds('E','E','E','a', frequenz);
00718          zaehlerstand--;
00719         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00720         switchLeds('E','E','a','E', frequenz);
00721         zaehlerstand--;
00722         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00723         switchLeds('E','E','a','a', frequenz);
00724         zaehlerstand--;
00725         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00726         switchLeds('E','a','E','E', frequenz);
00727         zaehlerstand--;
00728         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00729         switchLeds('E','a','E','a', frequenz);
00730         zaehlerstand--;
00731         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00732         switchLeds('E','a','a','E', frequenz);
00733         zaehlerstand--;
00734         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00735         switchLeds('E','a','a','a', frequenz);
00736         zaehlerstand--;
00737         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00738         switchLeds('a','E','E','E', frequenz);
00739         zaehlerstand--;
00740         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00741         switchLeds('a','E','E','a', frequenz);
00742         zaehlerstand--;
00743         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00744         switchLeds('a','E','a','E', frequenz);
00745         zaehlerstand--;
00746         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00747         switchLeds('a','E','a','a', frequenz);
00748         zaehlerstand--;
00749         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00750         switchLeds('a','a','E','E', frequenz);
00751         zaehlerstand--;
00752         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00753         switchLeds('a','a','E','a', frequenz);
00754         zaehlerstand--;
00755         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00756         switchLeds('a','a','a','E', frequenz);
00757         zaehlerstand--;
00758         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00759         switchLeds('a','a','a','a', frequenz);    
00760         zaehlerstand--;
00761         fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
00762         
00763         
00764 }
00765 int main ()
00766 {      
00767     RGBLed = 7;
00768      while(1)
00769     {
00770         RGBLed = 4;
00771         switchLeds('a','a','a','a', 0.5); 
00772         fs.printf("Bitte eingeben ob der Zaehler auf [u] oder ab [d] zaehlen soll: \n");
00773         char richtung = fs.getc();
00774         fs.printf("Bitte Frequenz eingeben mit der gezaehlt werden soll\n");
00775         fs.printf("[1] [2] [3] [4] Hz: \n");
00776         frequenzEingabe = (int) fs.getc();
00777         
00778         if (frequenzEingabe == 1)
00779         {
00780            frequenz = 1 / frequenzEingabe;
00781         }
00782         else if (frequenzEingabe == 2)
00783         {
00784            frequenz = 1 / frequenzEingabe;
00785         }
00786         else if (frequenzEingabe == 3)
00787         {
00788            frequenz = 1 / frequenzEingabe;
00789         }
00790         else if (frequenzEingabe == 4)
00791         {
00792            frequenz = 1 / frequenzEingabe;
00793         }
00794         else
00795         { 
00796         frequenz = 1 / 1.5;
00797         } 
00798         if (richtung == 'u')
00799         {
00800             zaehlerAuf();
00801         }
00802         else if (richtung == 'd')
00803         {
00804             zaehlerAb();
00805         }
00806         else
00807         {
00808             fs.printf("Fehler\n");
00809         }
00810     }
00811 }
00812 */
00813 // Übung 3: D / mit LCD / Basierend auf der Lösung
00814 /*
00815 #include "mbed.h"
00816 
00817 #define rgbOFF 7
00818 #define rgbRED 6
00819 #define rgbBLUE 3
00820 #define rgbYELLOW 4
00821 // global vars and objects
00822 BusOut blueLeds(LED1, LED2, LED3, LED4);
00823 BusOut rgbLeds(p23, p24, p25);
00824 
00825 // functions
00826 
00827 int main() {
00828     int cnt=0;      // count var
00829     char countDirection;  // Eingabevariable von der seriellen Schnittstelle
00830     int auf = 0, ab = 0;
00831     rgbLeds.write(rgbOFF);
00832     printf("mbed Uebung 3C\r\n");
00833     
00834     while(1) {
00835         rgbLeds = rgbYELLOW;
00836         blueLeds = 0;
00837         lcd.cls();
00838         fs.printf("Bitte eingeben ob der Zaehler auf [u] oder ab [d] zaehlen soll:\r\n");
00839         countDirection = getchar();
00840         
00841         if (countDirection == 'u') {
00842             rgbLeds = rgbBLUE;
00843             auf++;
00844             for (cnt=0; cnt<=15; cnt++) 
00845             {
00846                 fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\r\n", cnt, ab, auf);
00847                 lcd.locate(25,10);
00848                 lcd.printf("Zaehlerstand : %i",cnt);
00849                 blueLeds = cnt; 
00850                 wait(0.5);        
00851             }
00852         }
00853         else if (countDirection == 'd')  {
00854             ab++; 
00855             rgbLeds = rgbRED;        
00856             for (cnt=15; cnt>=0; cnt--) 
00857             {
00858                 lcd.cls();
00859                 fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\r\n", cnt, ab, auf);
00860                 lcd.locate(25,10);
00861                 lcd.printf("Zaehlerstand : %i",cnt);
00862                 blueLeds = cnt; 
00863                 wait(0.5);      
00864             }
00865         }
00866         else
00867             printf("\r\nFehler!\r\n");            
00868     }
00869 }
00870 */
00871 // Übung 4: A
00872 #include "mbed.h"
00873 // CENTER UP DOWN LEFT RIGHT
00874 BusIn joy(p15,p12,p13,p16);
00875 DigitalIn center(p14);
00876 
00877 int cnt=0;
00878 
00879 int main()
00880 {
00881     while(1) 
00882     {
00883         lcd.cls();
00884         while (joy == 8)
00885         {
00886             lcd.locate(25,10);
00887                 lcd.printf("right cnt: %i", cnt);
00888             cnt++;
00889             Leds = cnt;
00890             wait(0.5);
00891         }
00892         while (joy == 4)
00893         {
00894             lcd.locate(25,10);
00895                 lcd.printf("left cnt: %i", cnt);
00896             cnt--;
00897             Leds = cnt;
00898             wait(0.5);
00899         }
00900         while (joy == 2)
00901         {
00902             lcd.locate(25,10);
00903                 lcd.printf("down cnt: %i", cnt);
00904             cnt = cnt - 2;
00905             Leds = cnt;
00906             wait(0.5);
00907         }
00908         while (joy == 1)
00909         {
00910             lcd.locate(25,10);
00911                 lcd.printf("up");
00912             cnt = cnt + 2;
00913             Leds = cnt;
00914             wait(0.5);
00915         }
00916         while (center)
00917         {
00918             lcd.locate(25,10);
00919                 lcd.printf("center cnt: %i", cnt);
00920             cnt = 0;
00921             Leds = cnt;
00922             wait(0.5);
00923         }
00924     }
00925 }