Alan Ffrench / Mbed 2 deprecated Experiment_2_3_1

Dependencies:   mbed

main.cpp

Committer:
alanffrench
Date:
2020-07-29
Revision:
0:08877fa55d02

File content as of revision 0:08877fa55d02:

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


InterruptIn joystickcenter(p14);
InterruptIn button(p9);
DigitalOut led(LED1);
DigitalOut flash(LED4);
C12832 lcd(p5, p7, p6, p8, p11);
Timer debounce;
int i = 0;

void flip()
{
    if( debounce.read_ms() > 100) // will accept next push button at least 100ms from last press, avoiding bouncing switch effect
    {
        led=!led;
        i = 1;
        debounce.reset();
    }
}


int main()
{
    joystickcenter.rise(&flip);
    button.mode(PullUp);
    button.rise(&flip);
    debounce.start();

    while (1) {
        flash = !flash;
        if(i==1) {
            lcd.printf("BANG!  "); //keep printf outside interrupt - better as the interrupt needs to be as short as possible
            i = 0;
        }
        wait(0.25);
    }
}