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_ANALOGOUT_H
mturner5 0:0d6b77c9ae01 17 #define MBED_ANALOGOUT_H
mturner5 0:0d6b77c9ae01 18
mturner5 0:0d6b77c9ae01 19 #include "platform.h"
mturner5 0:0d6b77c9ae01 20
mturner5 0:0d6b77c9ae01 21 #if DEVICE_ANALOGOUT
mturner5 0:0d6b77c9ae01 22
mturner5 0:0d6b77c9ae01 23 #include "analogout_api.h"
mturner5 0:0d6b77c9ae01 24
mturner5 0:0d6b77c9ae01 25 namespace mbed {
mturner5 0:0d6b77c9ae01 26
mturner5 0:0d6b77c9ae01 27 /** An analog output, used for setting the voltage on a pin
mturner5 0:0d6b77c9ae01 28 *
mturner5 0:0d6b77c9ae01 29 * Example:
mturner5 0:0d6b77c9ae01 30 * @code
mturner5 0:0d6b77c9ae01 31 * // Make a sawtooth output
mturner5 0:0d6b77c9ae01 32 *
mturner5 0:0d6b77c9ae01 33 * #include "mbed.h"
mturner5 0:0d6b77c9ae01 34 *
mturner5 0:0d6b77c9ae01 35 * AnalogOut tri(p18);
mturner5 0:0d6b77c9ae01 36 * int main() {
mturner5 0:0d6b77c9ae01 37 * while(1) {
mturner5 0:0d6b77c9ae01 38 * tri = tri + 0.01;
mturner5 0:0d6b77c9ae01 39 * wait_us(1);
mturner5 0:0d6b77c9ae01 40 * if(tri == 1) {
mturner5 0:0d6b77c9ae01 41 * tri = 0;
mturner5 0:0d6b77c9ae01 42 * }
mturner5 0:0d6b77c9ae01 43 * }
mturner5 0:0d6b77c9ae01 44 * }
mturner5 0:0d6b77c9ae01 45 * @endcode
mturner5 0:0d6b77c9ae01 46 */
mturner5 0:0d6b77c9ae01 47 class AnalogOut {
mturner5 0:0d6b77c9ae01 48
mturner5 0:0d6b77c9ae01 49 public:
mturner5 0:0d6b77c9ae01 50
mturner5 0:0d6b77c9ae01 51 /** Create an AnalogOut connected to the specified pin
mturner5 0:0d6b77c9ae01 52 *
mturner5 0:0d6b77c9ae01 53 * @param AnalogOut pin to connect to (18)
mturner5 0:0d6b77c9ae01 54 */
mturner5 0:0d6b77c9ae01 55 AnalogOut(PinName pin) {
mturner5 0:0d6b77c9ae01 56 analogout_init(&_dac, pin);
mturner5 0:0d6b77c9ae01 57 }
mturner5 0:0d6b77c9ae01 58
mturner5 0:0d6b77c9ae01 59 /** Set the output voltage, specified as a percentage (float)
mturner5 0:0d6b77c9ae01 60 *
mturner5 0:0d6b77c9ae01 61 * @param value A floating-point value representing the output voltage,
mturner5 0:0d6b77c9ae01 62 * specified as a percentage. The value should lie between
mturner5 0:0d6b77c9ae01 63 * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
mturner5 0:0d6b77c9ae01 64 * Values outside this range will be saturated to 0.0f or 1.0f.
mturner5 0:0d6b77c9ae01 65 */
mturner5 0:0d6b77c9ae01 66 void write(float value) {
mturner5 0:0d6b77c9ae01 67 analogout_write(&_dac, value);
mturner5 0:0d6b77c9ae01 68 }
mturner5 0:0d6b77c9ae01 69
mturner5 0:0d6b77c9ae01 70 /** Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
mturner5 0:0d6b77c9ae01 71 *
mturner5 0:0d6b77c9ae01 72 * @param value 16-bit unsigned short representing the output voltage,
mturner5 0:0d6b77c9ae01 73 * normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v)
mturner5 0:0d6b77c9ae01 74 */
mturner5 0:0d6b77c9ae01 75 void write_u16(unsigned short value) {
mturner5 0:0d6b77c9ae01 76 analogout_write_u16(&_dac, value);
mturner5 0:0d6b77c9ae01 77 }
mturner5 0:0d6b77c9ae01 78
mturner5 0:0d6b77c9ae01 79 /** Return the current output voltage setting, measured as a percentage (float)
mturner5 0:0d6b77c9ae01 80 *
mturner5 0:0d6b77c9ae01 81 * @returns
mturner5 0:0d6b77c9ae01 82 * A floating-point value representing the current voltage being output on the pin,
mturner5 0:0d6b77c9ae01 83 * measured as a percentage. The returned value will lie between
mturner5 0:0d6b77c9ae01 84 * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
mturner5 0:0d6b77c9ae01 85 *
mturner5 0:0d6b77c9ae01 86 * @note
mturner5 0:0d6b77c9ae01 87 * This value may not match exactly the value set by a previous write().
mturner5 0:0d6b77c9ae01 88 */
mturner5 0:0d6b77c9ae01 89 float read() {
mturner5 0:0d6b77c9ae01 90 return analogout_read(&_dac);
mturner5 0:0d6b77c9ae01 91 }
mturner5 0:0d6b77c9ae01 92
mturner5 0:0d6b77c9ae01 93 #ifdef MBED_OPERATORS
mturner5 0:0d6b77c9ae01 94 /** An operator shorthand for write()
mturner5 0:0d6b77c9ae01 95 */
mturner5 0:0d6b77c9ae01 96 AnalogOut& operator= (float percent) {
mturner5 0:0d6b77c9ae01 97 write(percent);
mturner5 0:0d6b77c9ae01 98 return *this;
mturner5 0:0d6b77c9ae01 99 }
mturner5 0:0d6b77c9ae01 100
mturner5 0:0d6b77c9ae01 101 AnalogOut& operator= (AnalogOut& rhs) {
mturner5 0:0d6b77c9ae01 102 write(rhs.read());
mturner5 0:0d6b77c9ae01 103 return *this;
mturner5 0:0d6b77c9ae01 104 }
mturner5 0:0d6b77c9ae01 105
mturner5 0:0d6b77c9ae01 106 /** An operator shorthand for read()
mturner5 0:0d6b77c9ae01 107 */
mturner5 0:0d6b77c9ae01 108 operator float() {
mturner5 0:0d6b77c9ae01 109 return read();
mturner5 0:0d6b77c9ae01 110 }
mturner5 0:0d6b77c9ae01 111 #endif
mturner5 0:0d6b77c9ae01 112
mturner5 0:0d6b77c9ae01 113 protected:
mturner5 0:0d6b77c9ae01 114 dac_t _dac;
mturner5 0:0d6b77c9ae01 115 };
mturner5 0:0d6b77c9ae01 116
mturner5 0:0d6b77c9ae01 117 } // namespace mbed
mturner5 0:0d6b77c9ae01 118
mturner5 0:0d6b77c9ae01 119 #endif
mturner5 0:0d6b77c9ae01 120
mturner5 0:0d6b77c9ae01 121 #endif