Plays WAV file

Dependencies:   mbed Gamepad2

main.cpp

Committer:
eencae
Date:
2016-01-05
Revision:
0:44597d36d45c
Child:
1:39d8765b574d

File content as of revision 0:44597d36d45c:

/* 

2645_Ticker

Sample code from ELEC2645 Week 15 Lab

Demonstrates how to use a ticker to generate a periodic timer interrupt

(c) Craig A. Evans, University of Leeds, Jan 2016

*/ 

#include "mbed.h"

// Create objects for ticker and red LED
Ticker ticker;
DigitalOut red_led(LED_RED);

// flag - must be volatile as changes within ISR
volatile int timer_flag = 0;

// function prototypes
void timer_isr();

int main()
{
    // set-up the ticker so that the ISR it is called every 0.5 seconds
    ticker.attach(&timer_isr,0.5);
    // the on-board RGB LED is a common anode - writing a 1 to the pin will turn the LED OFF
    red_led = 1;

    while (1) {

        // check if flag is set i.e. interrupt has occured
        if (timer_flag) {
            timer_flag = 0;  // if it has, clear the flag

            // DO TASK HERE
    
        }

        // put the MCU to sleep until an interrupt wakes it up
        sleep();

    }
}

// time-triggered interrupt
void timer_isr()
{
    timer_flag = 1;   // set flag in ISR
}