A simple 128x32 graphical LCD program to quickstart with LCD on ARM mbed IoT Starter Kit. This requires mbed Applciation Shield with FRDM-K64F platform.
mbed/Ticker.h@1:eb68c94a8ee5, 2015-04-12 (annotated)
- Committer:
- tushki7
- Date:
- Sun Apr 12 15:45:52 2015 +0000
- Revision:
- 1:eb68c94a8ee5
- Parent:
- 0:60d829a0353a
A simple 128x32 LCD program with ARM mbed IoT Starter Kit;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tushki7 | 0:60d829a0353a | 1 | /* mbed Microcontroller Library |
tushki7 | 0:60d829a0353a | 2 | * Copyright (c) 2006-2013 ARM Limited |
tushki7 | 0:60d829a0353a | 3 | * |
tushki7 | 0:60d829a0353a | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
tushki7 | 0:60d829a0353a | 5 | * you may not use this file except in compliance with the License. |
tushki7 | 0:60d829a0353a | 6 | * You may obtain a copy of the License at |
tushki7 | 0:60d829a0353a | 7 | * |
tushki7 | 0:60d829a0353a | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
tushki7 | 0:60d829a0353a | 9 | * |
tushki7 | 0:60d829a0353a | 10 | * Unless required by applicable law or agreed to in writing, software |
tushki7 | 0:60d829a0353a | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
tushki7 | 0:60d829a0353a | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
tushki7 | 0:60d829a0353a | 13 | * See the License for the specific language governing permissions and |
tushki7 | 0:60d829a0353a | 14 | * limitations under the License. |
tushki7 | 0:60d829a0353a | 15 | */ |
tushki7 | 0:60d829a0353a | 16 | #ifndef MBED_TICKER_H |
tushki7 | 0:60d829a0353a | 17 | #define MBED_TICKER_H |
tushki7 | 0:60d829a0353a | 18 | |
tushki7 | 0:60d829a0353a | 19 | #include "TimerEvent.h" |
tushki7 | 0:60d829a0353a | 20 | #include "FunctionPointer.h" |
tushki7 | 0:60d829a0353a | 21 | |
tushki7 | 0:60d829a0353a | 22 | namespace mbed { |
tushki7 | 0:60d829a0353a | 23 | |
tushki7 | 0:60d829a0353a | 24 | /** A Ticker is used to call a function at a recurring interval |
tushki7 | 0:60d829a0353a | 25 | * |
tushki7 | 0:60d829a0353a | 26 | * You can use as many seperate Ticker objects as you require. |
tushki7 | 0:60d829a0353a | 27 | * |
tushki7 | 0:60d829a0353a | 28 | * Example: |
tushki7 | 0:60d829a0353a | 29 | * @code |
tushki7 | 0:60d829a0353a | 30 | * // Toggle the blinking led after 5 seconds |
tushki7 | 0:60d829a0353a | 31 | * |
tushki7 | 0:60d829a0353a | 32 | * #include "mbed.h" |
tushki7 | 0:60d829a0353a | 33 | * |
tushki7 | 0:60d829a0353a | 34 | * Ticker timer; |
tushki7 | 0:60d829a0353a | 35 | * DigitalOut led1(LED1); |
tushki7 | 0:60d829a0353a | 36 | * DigitalOut led2(LED2); |
tushki7 | 0:60d829a0353a | 37 | * |
tushki7 | 0:60d829a0353a | 38 | * int flip = 0; |
tushki7 | 0:60d829a0353a | 39 | * |
tushki7 | 0:60d829a0353a | 40 | * void attime() { |
tushki7 | 0:60d829a0353a | 41 | * flip = !flip; |
tushki7 | 0:60d829a0353a | 42 | * } |
tushki7 | 0:60d829a0353a | 43 | * |
tushki7 | 0:60d829a0353a | 44 | * int main() { |
tushki7 | 0:60d829a0353a | 45 | * timer.attach(&attime, 5); |
tushki7 | 0:60d829a0353a | 46 | * while(1) { |
tushki7 | 0:60d829a0353a | 47 | * if(flip == 0) { |
tushki7 | 0:60d829a0353a | 48 | * led1 = !led1; |
tushki7 | 0:60d829a0353a | 49 | * } else { |
tushki7 | 0:60d829a0353a | 50 | * led2 = !led2; |
tushki7 | 0:60d829a0353a | 51 | * } |
tushki7 | 0:60d829a0353a | 52 | * wait(0.2); |
tushki7 | 0:60d829a0353a | 53 | * } |
tushki7 | 0:60d829a0353a | 54 | * } |
tushki7 | 0:60d829a0353a | 55 | * @endcode |
tushki7 | 0:60d829a0353a | 56 | */ |
tushki7 | 0:60d829a0353a | 57 | class Ticker : public TimerEvent { |
tushki7 | 0:60d829a0353a | 58 | |
tushki7 | 0:60d829a0353a | 59 | public: |
tushki7 | 0:60d829a0353a | 60 | |
tushki7 | 0:60d829a0353a | 61 | /** Attach a function to be called by the Ticker, specifiying the interval in seconds |
tushki7 | 0:60d829a0353a | 62 | * |
tushki7 | 0:60d829a0353a | 63 | * @param fptr pointer to the function to be called |
tushki7 | 0:60d829a0353a | 64 | * @param t the time between calls in seconds |
tushki7 | 0:60d829a0353a | 65 | */ |
tushki7 | 0:60d829a0353a | 66 | void attach(void (*fptr)(void), float t) { |
tushki7 | 0:60d829a0353a | 67 | attach_us(fptr, t * 1000000.0f); |
tushki7 | 0:60d829a0353a | 68 | } |
tushki7 | 0:60d829a0353a | 69 | |
tushki7 | 0:60d829a0353a | 70 | /** Attach a member function to be called by the Ticker, specifiying the interval in seconds |
tushki7 | 0:60d829a0353a | 71 | * |
tushki7 | 0:60d829a0353a | 72 | * @param tptr pointer to the object to call the member function on |
tushki7 | 0:60d829a0353a | 73 | * @param mptr pointer to the member function to be called |
tushki7 | 0:60d829a0353a | 74 | * @param t the time between calls in seconds |
tushki7 | 0:60d829a0353a | 75 | */ |
tushki7 | 0:60d829a0353a | 76 | template<typename T> |
tushki7 | 0:60d829a0353a | 77 | void attach(T* tptr, void (T::*mptr)(void), float t) { |
tushki7 | 0:60d829a0353a | 78 | attach_us(tptr, mptr, t * 1000000.0f); |
tushki7 | 0:60d829a0353a | 79 | } |
tushki7 | 0:60d829a0353a | 80 | |
tushki7 | 0:60d829a0353a | 81 | /** Attach a function to be called by the Ticker, specifiying the interval in micro-seconds |
tushki7 | 0:60d829a0353a | 82 | * |
tushki7 | 0:60d829a0353a | 83 | * @param fptr pointer to the function to be called |
tushki7 | 0:60d829a0353a | 84 | * @param t the time between calls in micro-seconds |
tushki7 | 0:60d829a0353a | 85 | */ |
tushki7 | 0:60d829a0353a | 86 | void attach_us(void (*fptr)(void), timestamp_t t) { |
tushki7 | 0:60d829a0353a | 87 | _function.attach(fptr); |
tushki7 | 0:60d829a0353a | 88 | setup(t); |
tushki7 | 0:60d829a0353a | 89 | } |
tushki7 | 0:60d829a0353a | 90 | |
tushki7 | 0:60d829a0353a | 91 | /** Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds |
tushki7 | 0:60d829a0353a | 92 | * |
tushki7 | 0:60d829a0353a | 93 | * @param tptr pointer to the object to call the member function on |
tushki7 | 0:60d829a0353a | 94 | * @param mptr pointer to the member function to be called |
tushki7 | 0:60d829a0353a | 95 | * @param t the time between calls in micro-seconds |
tushki7 | 0:60d829a0353a | 96 | */ |
tushki7 | 0:60d829a0353a | 97 | template<typename T> |
tushki7 | 0:60d829a0353a | 98 | void attach_us(T* tptr, void (T::*mptr)(void), timestamp_t t) { |
tushki7 | 0:60d829a0353a | 99 | _function.attach(tptr, mptr); |
tushki7 | 0:60d829a0353a | 100 | setup(t); |
tushki7 | 0:60d829a0353a | 101 | } |
tushki7 | 0:60d829a0353a | 102 | |
tushki7 | 0:60d829a0353a | 103 | virtual ~Ticker() { |
tushki7 | 0:60d829a0353a | 104 | detach(); |
tushki7 | 0:60d829a0353a | 105 | } |
tushki7 | 0:60d829a0353a | 106 | |
tushki7 | 0:60d829a0353a | 107 | /** Detach the function |
tushki7 | 0:60d829a0353a | 108 | */ |
tushki7 | 0:60d829a0353a | 109 | void detach(); |
tushki7 | 0:60d829a0353a | 110 | |
tushki7 | 0:60d829a0353a | 111 | protected: |
tushki7 | 0:60d829a0353a | 112 | void setup(timestamp_t t); |
tushki7 | 0:60d829a0353a | 113 | virtual void handler(); |
tushki7 | 0:60d829a0353a | 114 | |
tushki7 | 0:60d829a0353a | 115 | protected: |
tushki7 | 0:60d829a0353a | 116 | timestamp_t _delay; /**< Time delay (in microseconds) for re-setting the multi-shot callback. */ |
tushki7 | 0:60d829a0353a | 117 | FunctionPointer _function; /**< Callback. */ |
tushki7 | 0:60d829a0353a | 118 | }; |
tushki7 | 0:60d829a0353a | 119 | |
tushki7 | 0:60d829a0353a | 120 | } // namespace mbed |
tushki7 | 0:60d829a0353a | 121 | |
tushki7 | 0:60d829a0353a | 122 | #endif |