Ken DelRaso / Mbed 2 deprecated interruptExample

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 // A class for flip()-ing a DigitalOut 
00004 class Flipper {
00005 public:
00006     Flipper(PinName pin) : _pin(pin) {
00007         _pin = 0;
00008     }
00009     void flip() {
00010         _pin = !_pin;
00011     }
00012 private:
00013     DigitalOut _pin;
00014 };
00015 
00016 DigitalOut led1(LED1);
00017 DigitalOut led3(LED3);
00018 
00019 Flipper f(LED2);
00020 Ticker t;
00021 
00022 int main() {
00023     t.attach_us(&f, &Flipper::flip, 25); // the address of the object, member function, and interval
00024                                             // 25 us = 40kHz
00025     led3 = 1;
00026 
00027     // spin in a main loop. flipper will interrupt it to call flip
00028     while(1) {
00029         led1 = !led1;
00030         wait(0.2);
00031     }
00032 }