Hello World for Ticker

Fork of Ticker_HelloWorld by Mbed

Use

Ticker is an interrupt driven time interrupt. A ticker works like a kitchen timer, you set it up to tick down from some value in seconds, when it reaches 0 it calls a callback function, then resets the ticker and starts the whole process over again. A ticker can be used to cause periodic events, like blinking an LED on and Off at a certain rate. A tickers maximum time it can handle is 30min, for anything greater consider using the real time clock functionality. In this example LED1 is controlled by the main while look, while LED2 is controlled by the Ticker callback function.

API

API reference.

Import librarymbed

No documentation found.
Committer:
mab5449
Date:
Fri Jan 13 21:08:14 2017 +0000
Revision:
3:5dc3a82c48f6
Parent:
2:87f26931d8d1
Updated to mbed OS 5

Who changed what in which revision?

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