Random terror phrases

Dependencies:   EFM32_CapSenseSlider EFM32_SegmentLCD mbed

Fork of EMF32-Segment-Touch-Demo by Max Scordamaglia

main.cpp

Committer:
MaxScorda
Date:
2015-06-26
Revision:
1:611525c0aa76
Parent:
0:cb2d0eb1f49e
Child:
2:9c22b1264236

File content as of revision 1:611525c0aa76:

#include "EFM32_SegmentLCD.h"
#include "EFM32_CapSenseSlider.h"

/******************** Define I/O *****************************/
InterruptIn in0(PB9);
InterruptIn in1(PB10);

silabs::EFM32_SegmentLCD segmentDisplay;
silabs::EFM32_CapSenseSlider capSlider;

DigitalOut myled1(LED1);
DigitalOut myled0(LED0);

/******************** Define Timers *****************************/
// devo separare i timers. Non so il perche'
LowPowerTicker refreshTicker;
LowPowerTicker ledTicker0;
LowPowerTicker ledTicker1;

/***************** Define global variables **********************/
#define INIT_SECONDS		17600
#define TEST_DURATION		10

volatile uint32_t seconds = INIT_SECONDS;
int count = -1;


/***************** Define callback handlers *********************/
void tickerCallback(void);
void in0_handler();
void in1_handler();
void touchCallback(void);
void slideCallback(void);

/**
 * Callback for pushbutton interrupt
 */

void symbolGest()
{
    if (count==7) {
        segmentDisplay.Symbol(LCD_SYMBOL_GECKO, true);
        segmentDisplay.Write("GeckoOn");
    } else {
        segmentDisplay.Symbol(LCD_SYMBOL_GECKO, false);
        if (count%2==0) segmentDisplay.Write("Scorda");
        else  segmentDisplay.Write("TataGek");
    }

}

void in0_handler()
{
    count++;
    if (count>7) count=7;
    else segmentDisplay.ARing(count, true);
    symbolGest() ;

}

void in1_handler()
{
    segmentDisplay.ARing(count, false);
    count--;
    if (count<0) count=-1;
    symbolGest() ;

}


/**
 * Callback for 1 second timebase
 */
void tickerCallback(void)
{
    seconds++;
    uint32_t clockValue = ((seconds / 60) % 60) * 100 + (seconds % 60);
    segmentDisplay.Number(clockValue);
    segmentDisplay.Symbol(LCD_SYMBOL_COL10, seconds & 0x1);
}

/**
 * Callback for touching/untouching the cap slider
 */
void touchCallback(void)
{
    segmentDisplay.Symbol(LCD_SYMBOL_EFM32, capSlider.isTouched());

    if(!capSlider.isTouched()) {
        segmentDisplay.Write("Scorda");
    }
}

/**
 * Callback for sliding the cap slider
 */
void slideCallback(void)
{
    segmentDisplay.LowerNumber(capSlider.get_position());
}

void ledToggler(void)
{
    myled1 = !myled1;
}

void ledTogglerGen(void)
{
    myled0 = !myled0;
}

/*************************** MAIN *******************************/
int main()
{
    // Initialize pushbutton handler
    in0.rise(NULL);
    in0.fall(in0_handler);

    in1.rise(NULL);
    in1.fall(in1_handler);

    // Enable the capacitive slider
    capSlider.start();
    capSlider.attach_touch(touchCallback);
    capSlider.attach_untouch(touchCallback);
    capSlider.attach_slide(-1, slideCallback);

    // Start generating the 1Hz timebase
    refreshTicker.attach(&tickerCallback, 1.0f);
    ledTicker1.attach(&ledToggler, 0.4f);
    ledTicker0.attach(&ledTogglerGen, 0.5f);

    printf("Initialization done! \n");
    wait(0.01f); //Need to delay slightly to give the serial transmission a chance to flush out its buffer
    segmentDisplay.Write("Scorda");


    // Go into sleeping mode
    while(1) {
        sleep();

        if(count >= 8) {
            /*
            	    // Go to 'completely dead' mode to show power consumption
            	    refreshTicker.detach();
            	    capSlider.stop();
            	    in.disable_irq();
            	    delete &segmentDisplay;

            	    */
        }

    }
}