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_PWMOUT_H
mturner5 0:0d6b77c9ae01 17 #define MBED_PWMOUT_H
mturner5 0:0d6b77c9ae01 18
mturner5 0:0d6b77c9ae01 19 #include "platform.h"
mturner5 0:0d6b77c9ae01 20
mturner5 0:0d6b77c9ae01 21 #if DEVICE_PWMOUT
mturner5 0:0d6b77c9ae01 22 #include "pwmout_api.h"
mturner5 0:0d6b77c9ae01 23
mturner5 0:0d6b77c9ae01 24 namespace mbed {
mturner5 0:0d6b77c9ae01 25
mturner5 0:0d6b77c9ae01 26 /** A pulse-width modulation digital output
mturner5 0:0d6b77c9ae01 27 *
mturner5 0:0d6b77c9ae01 28 * Example
mturner5 0:0d6b77c9ae01 29 * @code
mturner5 0:0d6b77c9ae01 30 * // Fade a led on.
mturner5 0:0d6b77c9ae01 31 * #include "mbed.h"
mturner5 0:0d6b77c9ae01 32 *
mturner5 0:0d6b77c9ae01 33 * PwmOut led(LED1);
mturner5 0:0d6b77c9ae01 34 *
mturner5 0:0d6b77c9ae01 35 * int main() {
mturner5 0:0d6b77c9ae01 36 * while(1) {
mturner5 0:0d6b77c9ae01 37 * led = led + 0.01;
mturner5 0:0d6b77c9ae01 38 * wait(0.2);
mturner5 0:0d6b77c9ae01 39 * if(led == 1.0) {
mturner5 0:0d6b77c9ae01 40 * led = 0;
mturner5 0:0d6b77c9ae01 41 * }
mturner5 0:0d6b77c9ae01 42 * }
mturner5 0:0d6b77c9ae01 43 * }
mturner5 0:0d6b77c9ae01 44 * @endcode
mturner5 0:0d6b77c9ae01 45 *
mturner5 0:0d6b77c9ae01 46 * @note
mturner5 0:0d6b77c9ae01 47 * On the LPC1768 and LPC2368, the PWMs all share the same
mturner5 0:0d6b77c9ae01 48 * period - if you change the period for one, you change it for all.
mturner5 0:0d6b77c9ae01 49 * Although routines that change the period maintain the duty cycle
mturner5 0:0d6b77c9ae01 50 * for its PWM, all other PWMs will require their duty cycle to be
mturner5 0:0d6b77c9ae01 51 * refreshed.
mturner5 0:0d6b77c9ae01 52 */
mturner5 0:0d6b77c9ae01 53 class PwmOut {
mturner5 0:0d6b77c9ae01 54
mturner5 0:0d6b77c9ae01 55 public:
mturner5 0:0d6b77c9ae01 56
mturner5 0:0d6b77c9ae01 57 /** Create a PwmOut connected to the specified pin
mturner5 0:0d6b77c9ae01 58 *
mturner5 0:0d6b77c9ae01 59 * @param pin PwmOut pin to connect to
mturner5 0:0d6b77c9ae01 60 */
mturner5 0:0d6b77c9ae01 61 PwmOut(PinName pin) {
mturner5 0:0d6b77c9ae01 62 pwmout_init(&_pwm, pin);
mturner5 0:0d6b77c9ae01 63 }
mturner5 0:0d6b77c9ae01 64
mturner5 0:0d6b77c9ae01 65 /** Set the ouput duty-cycle, specified as a percentage (float)
mturner5 0:0d6b77c9ae01 66 *
mturner5 0:0d6b77c9ae01 67 * @param value A floating-point value representing the output duty-cycle,
mturner5 0:0d6b77c9ae01 68 * specified as a percentage. The value should lie between
mturner5 0:0d6b77c9ae01 69 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
mturner5 0:0d6b77c9ae01 70 * Values outside this range will be saturated to 0.0f or 1.0f.
mturner5 0:0d6b77c9ae01 71 */
mturner5 0:0d6b77c9ae01 72 void write(float value) {
mturner5 0:0d6b77c9ae01 73 pwmout_write(&_pwm, value);
mturner5 0:0d6b77c9ae01 74 }
mturner5 0:0d6b77c9ae01 75
mturner5 0:0d6b77c9ae01 76 /** Return the current output duty-cycle setting, measured as a percentage (float)
mturner5 0:0d6b77c9ae01 77 *
mturner5 0:0d6b77c9ae01 78 * @returns
mturner5 0:0d6b77c9ae01 79 * A floating-point value representing the current duty-cycle being output on the pin,
mturner5 0:0d6b77c9ae01 80 * measured as a percentage. The returned value will lie between
mturner5 0:0d6b77c9ae01 81 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
mturner5 0:0d6b77c9ae01 82 *
mturner5 0:0d6b77c9ae01 83 * @note
mturner5 0:0d6b77c9ae01 84 * This value may not match exactly the value set by a previous <write>.
mturner5 0:0d6b77c9ae01 85 */
mturner5 0:0d6b77c9ae01 86 float read() {
mturner5 0:0d6b77c9ae01 87 return pwmout_read(&_pwm);
mturner5 0:0d6b77c9ae01 88 }
mturner5 0:0d6b77c9ae01 89
mturner5 0:0d6b77c9ae01 90 /** Set the PWM period, specified in seconds (float), keeping the duty cycle the same.
mturner5 0:0d6b77c9ae01 91 *
mturner5 0:0d6b77c9ae01 92 * @note
mturner5 0:0d6b77c9ae01 93 * The resolution is currently in microseconds; periods smaller than this
mturner5 0:0d6b77c9ae01 94 * will be set to zero.
mturner5 0:0d6b77c9ae01 95 */
mturner5 0:0d6b77c9ae01 96 void period(float seconds) {
mturner5 0:0d6b77c9ae01 97 pwmout_period(&_pwm, seconds);
mturner5 0:0d6b77c9ae01 98 }
mturner5 0:0d6b77c9ae01 99
mturner5 0:0d6b77c9ae01 100 /** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same.
mturner5 0:0d6b77c9ae01 101 */
mturner5 0:0d6b77c9ae01 102 void period_ms(int ms) {
mturner5 0:0d6b77c9ae01 103 pwmout_period_ms(&_pwm, ms);
mturner5 0:0d6b77c9ae01 104 }
mturner5 0:0d6b77c9ae01 105
mturner5 0:0d6b77c9ae01 106 /** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same.
mturner5 0:0d6b77c9ae01 107 */
mturner5 0:0d6b77c9ae01 108 void period_us(int us) {
mturner5 0:0d6b77c9ae01 109 pwmout_period_us(&_pwm, us);
mturner5 0:0d6b77c9ae01 110 }
mturner5 0:0d6b77c9ae01 111
mturner5 0:0d6b77c9ae01 112 /** Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.
mturner5 0:0d6b77c9ae01 113 */
mturner5 0:0d6b77c9ae01 114 void pulsewidth(float seconds) {
mturner5 0:0d6b77c9ae01 115 pwmout_pulsewidth(&_pwm, seconds);
mturner5 0:0d6b77c9ae01 116 }
mturner5 0:0d6b77c9ae01 117
mturner5 0:0d6b77c9ae01 118 /** Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same.
mturner5 0:0d6b77c9ae01 119 */
mturner5 0:0d6b77c9ae01 120 void pulsewidth_ms(int ms) {
mturner5 0:0d6b77c9ae01 121 pwmout_pulsewidth_ms(&_pwm, ms);
mturner5 0:0d6b77c9ae01 122 }
mturner5 0:0d6b77c9ae01 123
mturner5 0:0d6b77c9ae01 124 /** Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same.
mturner5 0:0d6b77c9ae01 125 */
mturner5 0:0d6b77c9ae01 126 void pulsewidth_us(int us) {
mturner5 0:0d6b77c9ae01 127 pwmout_pulsewidth_us(&_pwm, us);
mturner5 0:0d6b77c9ae01 128 }
mturner5 0:0d6b77c9ae01 129
mturner5 0:0d6b77c9ae01 130 #ifdef MBED_OPERATORS
mturner5 0:0d6b77c9ae01 131 /** A operator shorthand for write()
mturner5 0:0d6b77c9ae01 132 */
mturner5 0:0d6b77c9ae01 133 PwmOut& operator= (float value) {
mturner5 0:0d6b77c9ae01 134 write(value);
mturner5 0:0d6b77c9ae01 135 return *this;
mturner5 0:0d6b77c9ae01 136 }
mturner5 0:0d6b77c9ae01 137
mturner5 0:0d6b77c9ae01 138 PwmOut& operator= (PwmOut& rhs) {
mturner5 0:0d6b77c9ae01 139 write(rhs.read());
mturner5 0:0d6b77c9ae01 140 return *this;
mturner5 0:0d6b77c9ae01 141 }
mturner5 0:0d6b77c9ae01 142
mturner5 0:0d6b77c9ae01 143 /** An operator shorthand for read()
mturner5 0:0d6b77c9ae01 144 */
mturner5 0:0d6b77c9ae01 145 operator float() {
mturner5 0:0d6b77c9ae01 146 return read();
mturner5 0:0d6b77c9ae01 147 }
mturner5 0:0d6b77c9ae01 148 #endif
mturner5 0:0d6b77c9ae01 149
mturner5 0:0d6b77c9ae01 150 protected:
mturner5 0:0d6b77c9ae01 151 pwmout_t _pwm;
mturner5 0:0d6b77c9ae01 152 };
mturner5 0:0d6b77c9ae01 153
mturner5 0:0d6b77c9ae01 154 } // namespace mbed
mturner5 0:0d6b77c9ae01 155
mturner5 0:0d6b77c9ae01 156 #endif
mturner5 0:0d6b77c9ae01 157
mturner5 0:0d6b77c9ae01 158 #endif