Hello World for Timeout

Fork of Timeout_HelloWorld by Mbed

Use

The Timeout API is a countdown timer that triggers a callback function when the timer runs out. The Timeout interface can be though of as a one shot Ticker.

API

API reference.

Import librarymbed

No documentation found.
Committer:
mab5449
Date:
Thu Jan 19 11:23:06 2017 -0600
Revision:
3:46d33a0cb1b1
Parent:
2:50216cc75b4a
Ported mbed OS 2 to mbed OS 5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 2:50216cc75b4a 1 /* mbed Example Program
mbedAustin 2:50216cc75b4a 2 * Copyright (c) 2006-2014 ARM Limited
mbedAustin 2:50216cc75b4a 3 *
mbedAustin 2:50216cc75b4a 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbedAustin 2:50216cc75b4a 5 * you may not use this file except in compliance with the License.
mbedAustin 2:50216cc75b4a 6 * You may obtain a copy of the License at
mbedAustin 2:50216cc75b4a 7 *
mbedAustin 2:50216cc75b4a 8 * http://www.apache.org/licenses/LICENSE-2.0
mbedAustin 2:50216cc75b4a 9 *
mbedAustin 2:50216cc75b4a 10 * Unless required by applicable law or agreed to in writing, software
mbedAustin 2:50216cc75b4a 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbedAustin 2:50216cc75b4a 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbedAustin 2:50216cc75b4a 13 * See the License for the specific language governing permissions and
mbedAustin 2:50216cc75b4a 14 * limitations under the License.
mbedAustin 2:50216cc75b4a 15 */
mbed_official 0:8a555873b7d3 16 #include "mbed.h"
mbed_official 0:8a555873b7d3 17
mbed_official 0:8a555873b7d3 18 Timeout flipper;
mbed_official 0:8a555873b7d3 19 DigitalOut led1(LED1);
mbed_official 0:8a555873b7d3 20 DigitalOut led2(LED2);
mbed_official 0:8a555873b7d3 21
mbed_official 0:8a555873b7d3 22 void flip() {
mbed_official 0:8a555873b7d3 23 led2 = !led2;
mbed_official 0:8a555873b7d3 24 }
mbed_official 0:8a555873b7d3 25
mbed_official 0:8a555873b7d3 26 int main() {
mbed_official 0:8a555873b7d3 27 led2 = 1;
mbed_official 0:8a555873b7d3 28 flipper.attach(&flip, 2.0); // setup flipper to call flip after 2 seconds
mbed_official 0:8a555873b7d3 29
mbed_official 0:8a555873b7d3 30 // spin in a main loop. flipper will interrupt it to call flip
mbed_official 0:8a555873b7d3 31 while(1) {
mbed_official 0:8a555873b7d3 32 led1 = !led1;
mbed_official 0:8a555873b7d3 33 wait(0.2);
mbed_official 0:8a555873b7d3 34 }
mbed_official 0:8a555873b7d3 35 }