mbed-drivers
AnalogIn.h
1 /*
2  * Copyright (c) 2006-2016, ARM Limited, All Rights Reserved
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may
6  * not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef MBED_ANALOGIN_H
18 #define MBED_ANALOGIN_H
19 
20 #include "platform.h"
21 
22 #if DEVICE_ANALOGIN
23 
24 #include "analogin_api.h"
25 
26 namespace mbed {
27 
47 class AnalogIn {
48 
49 public:
50 
56  AnalogIn(PinName pin) {
57  analogin_init(&_adc, pin);
58  }
59 
64  float read() {
65  return analogin_read(&_adc);
66  }
67 
73  unsigned short read_u16() {
74  return analogin_read_u16(&_adc);
75  }
76 
77 #ifdef MBED_OPERATORS
78 
91  operator float() {
92  return read();
93  }
94 #endif
95 
96 protected:
97  analogin_t _adc;
98 };
99 
100 } // namespace mbed
101 
102 #endif
103 
104 #endif
float read()
Definition: AnalogIn.h:64
unsigned short read_u16()
Definition: AnalogIn.h:73
Definition: AnalogIn.h:47
AnalogIn(PinName pin)
Definition: AnalogIn.h:56
Definition: BusIn.cpp:19