Philipp Kundegraber / Mbed 2 deprecated TINF_PE_20181025_STM_Schalter

Dependencies:   mbed C12832

main.cpp

Committer:
kunphil
Date:
2018-11-29
Revision:
3:b5c28432ee25
Parent:
2:7dafc3e72a72

File content as of revision 3:b5c28432ee25:

#include "mbed.h"
#include "C12832.h"
/*
DigitalOut Led1(LED1, 0);
DigitalOut Led2(LED2, 0);
DigitalOut Led3(LED3, 0);
DigitalOut Led4(LED4, 0);
*/
InterruptIn  SW1(p14);
InterruptIn  SW2(p15); 
InterruptIn  SW3(p12); 
InterruptIn  SW4(p16); 

//************* BusOut ******************
BusOut Leds (LED1, LED2, LED3, LED4);

//************** LCD ****************

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

//************* VARIABLEN ****************

enum State {ST_EIN=0, ST_AUS};
State state;

int LedWert = 3, btnCount = 0;

bool pressed = false;


//************* EREIGNISSE ****************
 
void rise(void)
{  
    wait_ms(50);
    pressed = true;
}

bool CheckFlag() 
{
    if (pressed) {
        pressed=false;
        return true;
        }
    return false;
}

//************* STATES ****************

void ST_Ein (void)
{
    //Status auf LCD und Serial
    lcd.cls();      // löscht lcd (clear screen)
    lcd.locate(0,0);   // x-position, y-position (x: 0-128; y: 0-32)
    lcd.printf("State: 1 (EIN)");
    printf("State: 1 (EIN)");
    // entry
    
    // do
    while(true) {
        Leds = LedWert;
    
        if(CheckFlag()) {
            btnCount++;
            if(btnCount >= 3){
                btnCount = 0;
                LedWert++;
                state = ST_AUS;
            
    // exit
                return;
            }
        }
    }
}

void ST_Aus (void)
{
    //Status auf LCD und Serial
    lcd.cls();      // löscht lcd (clear screen)
    lcd.locate(0,0);   // x-position, y-position (x: 0-128; y: 0-32)
    lcd.printf("State: 2 (AUS)");
    printf("State: 2 (AUS)");
    
    // entry
    
    // do
    while(true) {
        Leds = 0;
    
        if(CheckFlag()) {
            state = ST_EIN;
            
    // exit
            return;
            }
        }
}

void ST_Error (void)
{
    //Status auf LCD und Serial
    lcd.cls();      // löscht lcd (clear screen)
    lcd.locate(0,0);   // x-position, y-position (x: 0-128; y: 0-32)
    lcd.printf("State: ERROR!!!");
    printf("State: ERROR!!!");
    return;
}

void stateMachine()
{
    switch (state)
    {
    case ST_EIN: ST_Ein();
        break;
    case ST_AUS: ST_Aus();
        break;
    default: ST_Error();  // sollte nicht auftreten :-)
        break;
    }
}


 
int main()
{
    SW1.rise(&rise);      //.fall(&fall);
    
    Leds = 15;
    wait_ms(500);
    
    state = ST_EIN;
    while(true){
        stateMachine(); 
        }
}