mbed_example
/
LowPowerTicker_HelloWorld
Hello world for the LowPowerTicker class
LED flip example with the help of LowPowerTicker
main.cpp@0:3ef1e3fe0d3b, 2017-12-04 (annotated)
- Committer:
- c1728p9
- Date:
- Mon Dec 04 00:53:19 2017 +0000
- Revision:
- 0:3ef1e3fe0d3b
Initial Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
c1728p9 | 0:3ef1e3fe0d3b | 1 | /* mbed Example Program |
c1728p9 | 0:3ef1e3fe0d3b | 2 | * Copyright (c) 2017-2017 ARM Limited |
c1728p9 | 0:3ef1e3fe0d3b | 3 | * |
c1728p9 | 0:3ef1e3fe0d3b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
c1728p9 | 0:3ef1e3fe0d3b | 5 | * you may not use this file except in compliance with the License. |
c1728p9 | 0:3ef1e3fe0d3b | 6 | * You may obtain a copy of the License at |
c1728p9 | 0:3ef1e3fe0d3b | 7 | * |
c1728p9 | 0:3ef1e3fe0d3b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
c1728p9 | 0:3ef1e3fe0d3b | 9 | * |
c1728p9 | 0:3ef1e3fe0d3b | 10 | * Unless required by applicable law or agreed to in writing, software |
c1728p9 | 0:3ef1e3fe0d3b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
c1728p9 | 0:3ef1e3fe0d3b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
c1728p9 | 0:3ef1e3fe0d3b | 13 | * See the License for the specific language governing permissions and |
c1728p9 | 0:3ef1e3fe0d3b | 14 | * limitations under the License. |
c1728p9 | 0:3ef1e3fe0d3b | 15 | */ |
c1728p9 | 0:3ef1e3fe0d3b | 16 | #include "mbed.h" |
c1728p9 | 0:3ef1e3fe0d3b | 17 | |
c1728p9 | 0:3ef1e3fe0d3b | 18 | LowPowerTicker flipper; |
c1728p9 | 0:3ef1e3fe0d3b | 19 | DigitalOut led1(LED1); |
c1728p9 | 0:3ef1e3fe0d3b | 20 | |
c1728p9 | 0:3ef1e3fe0d3b | 21 | void flip() { |
c1728p9 | 0:3ef1e3fe0d3b | 22 | led1 = !led1; |
c1728p9 | 0:3ef1e3fe0d3b | 23 | } |
c1728p9 | 0:3ef1e3fe0d3b | 24 | |
c1728p9 | 0:3ef1e3fe0d3b | 25 | int main() { |
c1728p9 | 0:3ef1e3fe0d3b | 26 | led1 = 1; |
c1728p9 | 0:3ef1e3fe0d3b | 27 | flipper.attach(&flip, 2.0); // the address of the function to be attached (flip) and the interval (2 seconds) |
c1728p9 | 0:3ef1e3fe0d3b | 28 | |
c1728p9 | 0:3ef1e3fe0d3b | 29 | while(1) { |
c1728p9 | 0:3ef1e3fe0d3b | 30 | wait(0.2); |
c1728p9 | 0:3ef1e3fe0d3b | 31 | } |
c1728p9 | 0:3ef1e3fe0d3b | 32 | } |