Tried to initialize the buttons and slider but couldn't get it to work.

Dependencies:   mbed

Committer:
mturner5
Date:
Mon Sep 19 03:28:41 2016 +0000
Revision:
0:0d6b77c9ae01
basic v2;

Who changed what in which revision?

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