Alle DIC Uebungen bis 3D

Dependencies:   C12832 mbed

Fork of HelloWorld by Simon Ford

main.cpp

Committer:
Leitner
Date:
2017-11-28
Revision:
2:020d30f2e7b5
Parent:
0:fb6bbc10ffa0

File content as of revision 2:020d30f2e7b5:

#include "mbed.h"
#include "C12832.h"

#define EaaE 9
#define aEEa 6
#define Eaaa 8
#define EEaa 12
#define EEEa 14
#define EEEE 15
#define aEEE 7
#define aaEE 3
#define aaaE 1
#define aaaa 0
#define aEaa 4
#define aaEa 2

C12832 lcd(p5, p7, p6, p8, p11);

Serial fs(USBTX, USBRX);
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);

BusOut Leds(LED1, LED2, LED3, LED4);
BusOut RGBLed(p23, p24, p25);
//             R    G    B
// ÜBUNG 1: B
/*
void switchLeds(int led1, int led2, int led3, int led4, float time)
{
 myled1 = led1;
 myled2 = led2;
 myled3 = led3;
 myled4 = led4;   
 wait(time);
}


int main() {
    
        switchLeds(1,0,0,1, 2.0);
        switchLeds(0,1,1,0, 2.0);
        while(1)
        {
        switchLeds(1,0,0,0, 0.6);
        switchLeds(1,1,0,0, 0.6);
        switchLeds(1,1,1,0, 0.6);
        switchLeds(1,1,1,1, 0.6);
        switchLeds(0,1,1,1, 0.6);
        switchLeds(0,0,1,1, 0.6);
        switchLeds(0,0,0,1, 0.6);
        switchLeds(0,0,0,0, 0.6);
        }
        
        
        
    
}
*/
// ÜBUNG 1: C
/*
void switchLeds(char led1, char led2, char led3, char led4, float time)
{
 if(led1 == 'E') myled1 = 1;
 else            myled1 = 0;
 if(led2 == 'E') myled2 = 1;
 else            myled2 = 0;
 if(led3 == 'E') myled3 = 1;
 else            myled3 = 0;
 if(led4 == 'E') myled4 = 1;
 else            myled4 = 0;  
 wait(time);
}
int main() {
    
        switchLeds('E','a','a','E', 2.0);
        switchLeds('a','E','E','a', 2.0);
        while(1)
        {
        switchLeds('E','a','a','a', 0.6);
        switchLeds('E','E','a','a', 0.6);
        switchLeds('E','E','E','a', 0.6);
        switchLeds('E','E','E','E', 0.6);
        switchLeds('a','E','E','E', 0.6);
        switchLeds('a','a','E','E', 0.6);
        switchLeds('a','a','a','E', 0.6);
        switchLeds('a','a','a','a', 0.6);
        }
        
        
        
    
}
*/
// ÜBUNG 1: D
/*
int timefor = 5.0;

void switchLeds(char led1, char led2, char led3, char led4, float time)
{
 if(led1 == 'E') Leds = 0x01;
 else            Leds = 0x00;
 if(led2 == 'E') Leds = 0x02;
 else            Leds = 0x00;
 if(led3 == 'E') Leds = 0x04;
 else            Leds = 0x00;
 if(led4 == 'E') Leds = 0x08;
 else            Leds = 0x00;  
 wait(time);
 
}

int main() {
        for(int i = 0; i<5; i++)
        {
        Leds = 0x9;
        wait(timefor);
        Leds = 0x6;
        wait(timefor);
        timefor--;
        }
        Leds = 0x0;
        wait(1);
        while(1)
        {
        Leds = 0x8;
        wait(0.6);
        Leds = 0xC;
        wait(0.6);
        Leds = 0xE;
        wait(0.6);
        Leds = 0xF;
        wait(0.6);
        Leds = 0x7;
        wait(0.6);
        Leds = 0x3;
        wait(0.6);
        Leds = 0x1;
        wait(0.6);
        Leds = 0x0;
        wait(0.6);
        }
        
        
        
    
}
*/
// ÜBUNG 1: E
/*
void switchLeds(int Busvalue, double time)
{
 Leds = Busvalue;
 wait(time);
}
int timefor = 5.0;
int main ()
{
    for(int i = 0; i<5; i++)
        {
        switchLeds(EaaE, timefor);
        switchLeds(aEEa, timefor);
        
        timefor--;
        }
        
        switchLeds(aaaa, 1.0);
        
        while(1)
        {
        switchLeds(Eaaa, 0.6);
    
        switchLeds(EEaa, 0.6);
        
        switchLeds(EEEa, 0.6);
        
        switchLeds(EEEE, 0.6);
        
        switchLeds(aEEE, 0.6);
        
        switchLeds(aaEE, 0.6);
        
        switchLeds(aaaE, 0.6);
        
        switchLeds(aaaa, 0.6);
        }
}
*/
// ÜBUNG 2: A
/*
void switchLeds(int Busvalue, double time)
{
 Leds = Busvalue;
 wait(time);
}

int main ()
{
    
        switchLeds(EEEE, 2.0);
        switchLeds(aaaa, 2.0);
        
        
        while(1)
        {
        switchLeds(Eaaa, 0.5);
    
        switchLeds(aEaa, 0.5);
        
        switchLeds(aaEa, 0.5);
        
        switchLeds(aaaE, 0.5);
        }
}
*/
// ÜBUNG 2: B
/*
void switchLeds(int Busvalue, double time)
{
 Leds = Busvalue;
 wait(time);
}
char ledValue;
int main ()
{
    
        switchLeds(EEEE, 2.0);
        switchLeds(aaaa, 2.0);
        
        
        while(1)
        {
        for(int i=0; i<6; i++)
            {
            Leds = 0x8;
            wait(0.5);
            Leds = Leds >> 1;
            wait(0.5);
            Leds = Leds >> 1;
            wait(0.5);
            Leds = Leds >> 1;
            wait(0.5);
            }
        for(int i=0; i<4; i++)
        {
            Leds = 0x0;
            wait(0.5);
            Leds = 0x1;
            wait(0.5);
            Leds = Leds << 1;
            wait(0.5);
            Leds = Leds << 1;
            wait(0.5);
            Leds = Leds << 1;
            wait(0.5);
        }
        }
}
*/
// ÜBUNG 2: C
/*
void switchLeds(int Busvalue, double time)
{
 Leds = Busvalue;
 wait(time);
}
char ledValue;
int main ()
{
    
        switchLeds(EEEE, 2.0);
        switchLeds(aaaa, 2.0);
        
        
        while(1)
        {
        for(int i=0; i<6; i++)
            {
            Leds = 0x8;
            wait(0.5);
            Leds = 0xC;
            wait(0.5);
            Leds = Leds >> 1;
            wait(0.5);
            Leds = Leds >> 1;
            wait(0.5);
            Leds = Leds >> 1;
            wait(0.5);
            }
        for(int i=0; i<4; i++)
        {
            Leds = 0x0;
            wait(0.33);
            Leds = 0x1;
            wait(0.33);
            Leds = 0x3;
            wait(0.33);
            Leds = Leds << 1;
            wait(0.33);
            Leds = Leds << 1;
            wait(0.33);
            Leds = Leds << 1;
            wait(0.33);
        }
        }
}
*/
// ÜBUNG 2: D | E
/*
void switchLeds(int Busvalue, double time)
{
 Leds = Busvalue;
 wait(time);
}
char ledValue;
int main ()
{      
    RGBLed = 15;
        while(1)
        {
             RGBLed = 6;
             wait(20);
             RGBLed = 4;
             Leds = 0x6;
             wait(4);
             RGBLed = 5;
             wait(14);
            for(int i=0; i<4; i++)
            {
             RGBLed = 7;
             wait(0.5);
             RGBLed = 5;
             wait(0.5);
             }
             RGBLed = 4;
             Leds = 0x6;
             wait(5);
             
        }
}
*/
// ÜBUNG 2: F

/*
void tlRed(int msec)
{
    RGBLed = 6;
    wait_ms(msec);
}
void tlRedYellow(int msec, int addBlueLeds)
{
    RGBLed = 4;
    
    Leds = addBlueLeds;
    wait_ms(msec); 
    Leds = 0;
    
}    
void tlYellow(int msec)
{
    RGBLed = 4;
    wait_ms(msec);
}
void tlGreen(int msec)
{
    RGBLed = 5;
    wait_ms(msec);
}
void tlBlinkGreen(int howOften, int periodeMsec)
{
    for(int i=0; i<howOften; i++)
        {
             RGBLed = 7;
             wait_ms((periodeMsec / 2));
             RGBLed = 5;
             wait_ms((periodeMsec / 2));
        }
}
void tlClear()
{
    RGBLed = 7;
}
char ledValue;
int main ()
{      
    tlClear();
        while(1)
        {
             tlRed(20000);
             tlRedYellow(4000, 6);
             tlGreen(14000);
             tlBlinkGreen(4, 1000);
             tlYellow(5000);
             
             
        }
}
*/
// Übung 3: A
/*
int a = 0;
int i = 0;
int main ()
{      
    while(1)
    {
        while(a < 15)
        {
            a++;
            wait(1);
             fs.printf("Zaehlerstand = %i, Anzahl der Ueberlaufe = %i\n", a, i);
             
        }
        i++;
        a = 0;
    }
}
*/
// Übung 3: B
/*
int durchlaeufe = 0;
void tlRed(int msec)
{
    float sec = msec / 1000;
    RGBLed = 6;
    fs.printf("Phase: ROT, Dauer = %lfsec, Anzahl der Ampeldurchlaeufe = %i\n", sec, durchlaeufe);
    wait_ms(msec);
}
void tlRedYellow(int msec, int addBlueLeds)
{
    float sec = msec / 1000;
    RGBLed = 4;
    fs.printf("Phase: ROTGELB, Dauer = %lfsec, Anzahl der Ampeldurchlaeufe = %i\n", sec, durchlaeufe);
    Leds = addBlueLeds;
    wait_ms(msec); 
    Leds = 0;
    
}    
void tlYellow(int msec)
{
    float sec = msec / 1000;
    RGBLed = 4;
    fs.printf("Phase: GELB, Dauer = %lfsec, Anzahl der Ampeldurchlaeufe = %i\n", sec, durchlaeufe);
    wait_ms(msec);
}
void tlGreen(int msec)
{
    float sec = msec / 1000;
    RGBLed = 5;
    fs.printf("Phase: GRUEN, Dauer = %lfsec, Anzahl der Ampeldurchlaeufe = %i\n", sec, durchlaeufe);
    wait_ms(msec);
}
void tlBlinkGreen(int howOften, int periodeMsec)
{
    float sec = periodeMsec / 1000;
    fs.printf("Phase: GRUENBLINKEN, Dauer = %lfsec, Anzahl der Ampeldurchlaeufe = %i\n", sec, durchlaeufe);
    for(int i=0; i<howOften; i++)
        {
             RGBLed = 7;
             wait_ms((periodeMsec / 2));
             RGBLed = 5;
             wait_ms((periodeMsec / 2));
        }
}
void tlClear()
{
    RGBLed = 7;
}
char ledValue;
int main ()
{      
    tlClear();
        while(1)
        {
             tlRed(20000);
             tlRedYellow(4000, 6);
             tlGreen(14000);
             tlBlinkGreen(4, 1000);
             tlYellow(5000);
             durchlaeufe++;
             
             
        }
}
*/
// Übung 3: C
/*
int auf = 0;
int ab = 0;
int zaehlerstand = 0;
void switchLeds(char led1, char led2, char led3, char led4, float time)
{
 if(led1 == 'E') myled1 = 1;
 else            myled1 = 0;
 if(led2 == 'E') myled2 = 1;
 else            myled2 = 0;
 if(led3 == 'E') myled3 = 1;
 else            myled3 = 0;
 if(led4 == 'E') myled4 = 1;
 else            myled4 = 0;  
 wait(time);
}
void zaehlerAuf()
{
        auf++;
        RGBLed = 3;
        switchLeds('a','a','a','a', 0.5);
         zaehlerstand = 0;
        fs.printf("Zaehlerstand: %i ,Abwaertszyklen: %i ,Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','a','a','E', 0.5);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','a','E','a', 0.5);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','a','E','E', 0.5);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','E','a','a', 0.5);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','E','a','E', 0.5);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','E','E','a', 0.5);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','E','E','E', 0.5);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','a','a','a', 0.5);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','a','a','E', 0.5);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','a','E','a', 0.5);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','a','E','E', 0.5);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','E','a','a', 0.5);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','E','a','E', 0.5);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','E','E','a', 0.5);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','E','E','E', 0.5);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
      
}
void zaehlerAb()
{
        ab++; 
        RGBLed = 6;
        switchLeds('E','E','E','E', 0.5);
         zaehlerstand = 15;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','E','E','a', 0.5);
         zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','E','a','E', 0.5);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','E','a','a', 0.5);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','a','E','E', 0.5);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','a','E','a', 0.5);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','a','a','E', 0.5);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','a','a','a', 0.5);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','E','E','E', 0.5);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','E','E','a', 0.5);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','E','a','E', 0.5);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','E','a','a', 0.5);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','a','E','E', 0.5);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','a','E','a', 0.5);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','a','a','E', 0.5);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','a','a','a', 0.5);    
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        
        
}
int main ()
{      
    RGBLed = 7;
     while(1)
    {
        RGBLed = 4;
        switchLeds('a','a','a','a', 0.5); 
        fs.printf("Bitte eingeben ob der Zaehler auf [u] oder ab [d] zaehlen soll: \n");
        char richtung = fs.getc();
        if (richtung == 'u')
        {
            zaehlerAuf();
        }
        else if (richtung == 'd')
        {
            zaehlerAb();
        }
        else
        {
            fs.printf("Fehler\n");
        }
    }
}
*/
// Übung 3: D
/*
int auf = 0;
int ab = 0;
int zaehlerstand = 0;
float frequenz = 0;
int frequenzEingabe;
void switchLeds(char led1, char led2, char led3, char led4, float time)
{
 if(led1 == 'E') myled1 = 1;
 else            myled1 = 0;
 if(led2 == 'E') myled2 = 1;
 else            myled2 = 0;
 if(led3 == 'E') myled3 = 1;
 else            myled3 = 0;
 if(led4 == 'E') myled4 = 1;
 else            myled4 = 0;  
 wait(time);
}
void zaehlerAuf()
{
        auf++;
        RGBLed = 3;
        switchLeds('a','a','a','a', frequenz);
         zaehlerstand = 0;
        fs.printf("Zaehlerstand: %i ,Abwaertszyklen: %i ,Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','a','a','E', frequenz);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','a','E','a', frequenz);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','a','E','E', frequenz);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','E','a','a', frequenz);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','E','a','E', frequenz);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','E','E','a', frequenz);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','E','E','E', frequenz);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','a','a','a', frequenz);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','a','a','E', frequenz);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','a','E','a', frequenz);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','a','E','E', frequenz);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','E','a','a', frequenz);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','E','a','E', frequenz);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','E','E','a', frequenz);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','E','E','E', frequenz);
         zaehlerstand++;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
      
}
void zaehlerAb()
{
        ab++; 
        RGBLed = 6;
        switchLeds('E','E','E','E', frequenz);
         zaehlerstand = 15;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','E','E','a', frequenz);
         zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','E','a','E', frequenz);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','E','a','a', frequenz);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','a','E','E', frequenz);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','a','E','a', frequenz);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','a','a','E', frequenz);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('E','a','a','a', frequenz);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','E','E','E', frequenz);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','E','E','a', frequenz);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','E','a','E', frequenz);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','E','a','a', frequenz);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','a','E','E', frequenz);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','a','E','a', frequenz);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','a','a','E', frequenz);
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        switchLeds('a','a','a','a', frequenz);    
        zaehlerstand--;
        fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\n", zaehlerstand, ab, auf);
        
        
}
int main ()
{      
    RGBLed = 7;
     while(1)
    {
        RGBLed = 4;
        switchLeds('a','a','a','a', 0.5); 
        fs.printf("Bitte eingeben ob der Zaehler auf [u] oder ab [d] zaehlen soll: \n");
        char richtung = fs.getc();
        fs.printf("Bitte Frequenz eingeben mit der gezaehlt werden soll\n");
        fs.printf("[1] [2] [3] [4] Hz: \n");
        frequenzEingabe = (int) fs.getc();
        
        if (frequenzEingabe == 1)
        {
           frequenz = 1 / frequenzEingabe;
        }
        else if (frequenzEingabe == 2)
        {
           frequenz = 1 / frequenzEingabe;
        }
        else if (frequenzEingabe == 3)
        {
           frequenz = 1 / frequenzEingabe;
        }
        else if (frequenzEingabe == 4)
        {
           frequenz = 1 / frequenzEingabe;
        }
        else
        { 
        frequenz = 1 / 1.5;
        } 
        if (richtung == 'u')
        {
            zaehlerAuf();
        }
        else if (richtung == 'd')
        {
            zaehlerAb();
        }
        else
        {
            fs.printf("Fehler\n");
        }
    }
}
*/
// Übung 3: D / mit LCD / Basierend auf der Lösung
/*
#include "mbed.h"

#define rgbOFF 7
#define rgbRED 6
#define rgbBLUE 3
#define rgbYELLOW 4
// global vars and objects
BusOut blueLeds(LED1, LED2, LED3, LED4);
BusOut rgbLeds(p23, p24, p25);

// functions

int main() {
    int cnt=0;      // count var
    char countDirection;  // Eingabevariable von der seriellen Schnittstelle
    int auf = 0, ab = 0;
    rgbLeds.write(rgbOFF);
    printf("mbed Uebung 3C\r\n");
    
    while(1) {
        rgbLeds = rgbYELLOW;
        blueLeds = 0;
        lcd.cls();
        fs.printf("Bitte eingeben ob der Zaehler auf [u] oder ab [d] zaehlen soll:\r\n");
        countDirection = getchar();
        
        if (countDirection == 'u') {
            rgbLeds = rgbBLUE;
            auf++;
            for (cnt=0; cnt<=15; cnt++) 
            {
                fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\r\n", cnt, ab, auf);
                lcd.locate(25,10);
                lcd.printf("Zaehlerstand : %i",cnt);
                blueLeds = cnt; 
                wait(0.5);        
            }
        }
        else if (countDirection == 'd')  {
            ab++; 
            rgbLeds = rgbRED;        
            for (cnt=15; cnt>=0; cnt--) 
            {
                lcd.cls();
                fs.printf("Zaehlerstand: %i Abwaertszyklen: %i Aufwaertszyklen: %i\r\n", cnt, ab, auf);
                lcd.locate(25,10);
                lcd.printf("Zaehlerstand : %i",cnt);
                blueLeds = cnt; 
                wait(0.5);      
            }
        }
        else
            printf("\r\nFehler!\r\n");            
    }
}
*/
// Übung 4: A
#include "mbed.h"
// CENTER UP DOWN LEFT RIGHT
BusIn joy(p15,p12,p13,p16);
DigitalIn center(p14);

int cnt=0;

int main()
{
    while(1) 
    {
        lcd.cls();
        while (joy == 8)
        {
            lcd.locate(25,10);
                lcd.printf("right cnt: %i", cnt);
            cnt++;
            Leds = cnt;
            wait(0.5);
        }
        while (joy == 4)
        {
            lcd.locate(25,10);
                lcd.printf("left cnt: %i", cnt);
            cnt--;
            Leds = cnt;
            wait(0.5);
        }
        while (joy == 2)
        {
            lcd.locate(25,10);
                lcd.printf("down cnt: %i", cnt);
            cnt = cnt - 2;
            Leds = cnt;
            wait(0.5);
        }
        while (joy == 1)
        {
            lcd.locate(25,10);
                lcd.printf("up");
            cnt = cnt + 2;
            Leds = cnt;
            wait(0.5);
        }
        while (center)
        {
            lcd.locate(25,10);
                lcd.printf("center cnt: %i", cnt);
            cnt = 0;
            Leds = cnt;
            wait(0.5);
        }
    }
}