Home Alert System

Dependencies:   PWM_Tone_Library DHT

Committer:
aziz111
Date:
Fri Mar 08 17:15:02 2019 +0000
Revision:
5:569a4894abc1
Parent:
3:78f223d34f36
Final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ethaderu 3:78f223d34f36 1 /* mbed Microcontroller Library
ethaderu 3:78f223d34f36 2 * Copyright (c) 2006-2013 ARM Limited
ethaderu 3:78f223d34f36 3 *
ethaderu 3:78f223d34f36 4 * Licensed under the Apache License, Version 2.0 (the "License");
ethaderu 3:78f223d34f36 5 * you may not use this file except in compliance with the License.
ethaderu 3:78f223d34f36 6 * You may obtain a copy of the License at
ethaderu 3:78f223d34f36 7 *
ethaderu 3:78f223d34f36 8 * http://www.apache.org/licenses/LICENSE-2.0
ethaderu 3:78f223d34f36 9 *
ethaderu 3:78f223d34f36 10 * Unless required by applicable law or agreed to in writing, software
ethaderu 3:78f223d34f36 11 * distributed under the License is distributed on an "AS IS" BASIS,
ethaderu 3:78f223d34f36 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ethaderu 3:78f223d34f36 13 * See the License for the specific language governing permissions and
ethaderu 3:78f223d34f36 14 * limitations under the License.
ethaderu 3:78f223d34f36 15 */
ethaderu 3:78f223d34f36 16 #ifndef MBED_ANALOGOUT_H
ethaderu 3:78f223d34f36 17 #define MBED_ANALOGOUT_H
ethaderu 3:78f223d34f36 18
ethaderu 3:78f223d34f36 19 #include "platform.h"
ethaderu 3:78f223d34f36 20
ethaderu 3:78f223d34f36 21 #if DEVICE_ANALOGOUT
ethaderu 3:78f223d34f36 22
ethaderu 3:78f223d34f36 23 #include "analogout_api.h"
ethaderu 3:78f223d34f36 24
ethaderu 3:78f223d34f36 25 namespace mbed {
ethaderu 3:78f223d34f36 26
ethaderu 3:78f223d34f36 27 /** An analog output, used for setting the voltage on a pin
ethaderu 3:78f223d34f36 28 *
ethaderu 3:78f223d34f36 29 * Example:
ethaderu 3:78f223d34f36 30 * @code
ethaderu 3:78f223d34f36 31 * // Make a sawtooth output
ethaderu 3:78f223d34f36 32 *
ethaderu 3:78f223d34f36 33 * #include "mbed.h"
ethaderu 3:78f223d34f36 34 *
ethaderu 3:78f223d34f36 35 * AnalogOut tri(p18);
ethaderu 3:78f223d34f36 36 * int main() {
ethaderu 3:78f223d34f36 37 * while(1) {
ethaderu 3:78f223d34f36 38 * tri = tri + 0.01;
ethaderu 3:78f223d34f36 39 * wait_us(1);
ethaderu 3:78f223d34f36 40 * if(tri == 1) {
ethaderu 3:78f223d34f36 41 * tri = 0;
ethaderu 3:78f223d34f36 42 * }
ethaderu 3:78f223d34f36 43 * }
ethaderu 3:78f223d34f36 44 * }
ethaderu 3:78f223d34f36 45 * @endcode
ethaderu 3:78f223d34f36 46 */
ethaderu 3:78f223d34f36 47 class AnalogOut {
ethaderu 3:78f223d34f36 48
ethaderu 3:78f223d34f36 49 public:
ethaderu 3:78f223d34f36 50
ethaderu 3:78f223d34f36 51 /** Create an AnalogOut connected to the specified pin
ethaderu 3:78f223d34f36 52 *
ethaderu 3:78f223d34f36 53 * @param AnalogOut pin to connect to (18)
ethaderu 3:78f223d34f36 54 */
ethaderu 3:78f223d34f36 55 AnalogOut(PinName pin) {
ethaderu 3:78f223d34f36 56 analogout_init(&_dac, pin);
ethaderu 3:78f223d34f36 57 }
ethaderu 3:78f223d34f36 58
ethaderu 3:78f223d34f36 59 /** Set the output voltage, specified as a percentage (float)
ethaderu 3:78f223d34f36 60 *
ethaderu 3:78f223d34f36 61 * @param value A floating-point value representing the output voltage,
ethaderu 3:78f223d34f36 62 * specified as a percentage. The value should lie between
ethaderu 3:78f223d34f36 63 * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
ethaderu 3:78f223d34f36 64 * Values outside this range will be saturated to 0.0f or 1.0f.
ethaderu 3:78f223d34f36 65 */
ethaderu 3:78f223d34f36 66 void write(float value) {
ethaderu 3:78f223d34f36 67 analogout_write(&_dac, value);
ethaderu 3:78f223d34f36 68 }
ethaderu 3:78f223d34f36 69
ethaderu 3:78f223d34f36 70 /** Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
ethaderu 3:78f223d34f36 71 *
ethaderu 3:78f223d34f36 72 * @param value 16-bit unsigned short representing the output voltage,
ethaderu 3:78f223d34f36 73 * normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v)
ethaderu 3:78f223d34f36 74 */
ethaderu 3:78f223d34f36 75 void write_u16(unsigned short value) {
ethaderu 3:78f223d34f36 76 analogout_write_u16(&_dac, value);
ethaderu 3:78f223d34f36 77 }
ethaderu 3:78f223d34f36 78
ethaderu 3:78f223d34f36 79 /** Return the current output voltage setting, measured as a percentage (float)
ethaderu 3:78f223d34f36 80 *
ethaderu 3:78f223d34f36 81 * @returns
ethaderu 3:78f223d34f36 82 * A floating-point value representing the current voltage being output on the pin,
ethaderu 3:78f223d34f36 83 * measured as a percentage. The returned value will lie between
ethaderu 3:78f223d34f36 84 * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
ethaderu 3:78f223d34f36 85 *
ethaderu 3:78f223d34f36 86 * @note
ethaderu 3:78f223d34f36 87 * This value may not match exactly the value set by a previous write().
ethaderu 3:78f223d34f36 88 */
ethaderu 3:78f223d34f36 89 float read() {
ethaderu 3:78f223d34f36 90 return analogout_read(&_dac);
ethaderu 3:78f223d34f36 91 }
ethaderu 3:78f223d34f36 92
ethaderu 3:78f223d34f36 93 #ifdef MBED_OPERATORS
ethaderu 3:78f223d34f36 94 /** An operator shorthand for write()
ethaderu 3:78f223d34f36 95 */
ethaderu 3:78f223d34f36 96 AnalogOut& operator= (float percent) {
ethaderu 3:78f223d34f36 97 write(percent);
ethaderu 3:78f223d34f36 98 return *this;
ethaderu 3:78f223d34f36 99 }
ethaderu 3:78f223d34f36 100
ethaderu 3:78f223d34f36 101 AnalogOut& operator= (AnalogOut& rhs) {
ethaderu 3:78f223d34f36 102 write(rhs.read());
ethaderu 3:78f223d34f36 103 return *this;
ethaderu 3:78f223d34f36 104 }
ethaderu 3:78f223d34f36 105
ethaderu 3:78f223d34f36 106 /** An operator shorthand for read()
ethaderu 3:78f223d34f36 107 */
ethaderu 3:78f223d34f36 108 operator float() {
ethaderu 3:78f223d34f36 109 return read();
ethaderu 3:78f223d34f36 110 }
ethaderu 3:78f223d34f36 111 #endif
ethaderu 3:78f223d34f36 112
ethaderu 3:78f223d34f36 113 protected:
ethaderu 3:78f223d34f36 114 dac_t _dac;
ethaderu 3:78f223d34f36 115 };
ethaderu 3:78f223d34f36 116
ethaderu 3:78f223d34f36 117 } // namespace mbed
ethaderu 3:78f223d34f36 118
ethaderu 3:78f223d34f36 119 #endif
ethaderu 3:78f223d34f36 120
ethaderu 3:78f223d34f36 121 #endif