Ticker Example

Fork of Workshop-1-Example-2 by mbed Workshops

Committer:
sarahmarshy
Date:
Mon Sep 26 16:13:44 2016 +0000
Revision:
0:41a092c2e9d3
Child:
1:965926ce34a0
Initial commit. Ticker blinky.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sarahmarshy 0:41a092c2e9d3 1 #include "mbed.h"
sarahmarshy 0:41a092c2e9d3 2
sarahmarshy 0:41a092c2e9d3 3 Ticker flipper;
sarahmarshy 0:41a092c2e9d3 4 DigitalOut led1(LED1);
sarahmarshy 0:41a092c2e9d3 5 DigitalOut led2(LED2);
sarahmarshy 0:41a092c2e9d3 6
sarahmarshy 0:41a092c2e9d3 7 void flip() {
sarahmarshy 0:41a092c2e9d3 8 led2 = !led2;
sarahmarshy 0:41a092c2e9d3 9 }
sarahmarshy 0:41a092c2e9d3 10
sarahmarshy 0:41a092c2e9d3 11 int main() {
sarahmarshy 0:41a092c2e9d3 12 led2 = 1;
sarahmarshy 0:41a092c2e9d3 13 flipper.attach(&flip, 2.0); // call flip function every 2 seconds
sarahmarshy 0:41a092c2e9d3 14
sarahmarshy 0:41a092c2e9d3 15
sarahmarshy 0:41a092c2e9d3 16 // spin in a main loop. flipper will interrupt it to call flip
sarahmarshy 0:41a092c2e9d3 17 while(1) {
sarahmarshy 0:41a092c2e9d3 18 led1 = !led1;
sarahmarshy 0:41a092c2e9d3 19 wait(0.2);
sarahmarshy 0:41a092c2e9d3 20 }
sarahmarshy 0:41a092c2e9d3 21 }