Lab 1 Program C

Dependents:   Lab1C

Fork of mbed by -deleted-

Committer:
mattsims12
Date:
Tue Sep 29 03:04:58 2015 +0000
Revision:
44:1c5f591fce58
Parent:
43:aff670d0d510
Lab 1 Program C

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon.ford@mbed.co.uk 0:82220227f4fa 1 /* mbed Microcontroller Library - AnalogIn
emilmont 27:7110ebee3484 2 * Copyright (c) 2006-2011 ARM Limited. All rights reserved.
simon.ford@mbed.co.uk 5:62573be585e9 3 */
simon.ford@mbed.co.uk 0:82220227f4fa 4
simon.ford@mbed.co.uk 0:82220227f4fa 5 #ifndef MBED_ANALOGIN_H
simon.ford@mbed.co.uk 0:82220227f4fa 6 #define MBED_ANALOGIN_H
simon.ford@mbed.co.uk 0:82220227f4fa 7
emilmont 27:7110ebee3484 8 #include "device.h"
emilmont 27:7110ebee3484 9
emilmont 27:7110ebee3484 10 #if DEVICE_ANALOGIN
emilmont 27:7110ebee3484 11
rolf.meyer@arm.com 11:1c1ebd0324fa 12 #include "platform.h"
rolf.meyer@arm.com 11:1c1ebd0324fa 13 #include "PinNames.h"
rolf.meyer@arm.com 11:1c1ebd0324fa 14 #include "PeripheralNames.h"
simon.ford@mbed.co.uk 0:82220227f4fa 15 #include "Base.h"
simon.ford@mbed.co.uk 0:82220227f4fa 16
simon.ford@mbed.co.uk 0:82220227f4fa 17 namespace mbed {
simon.ford@mbed.co.uk 0:82220227f4fa 18
screamer 43:aff670d0d510 19 /** An analog input, used for reading the voltage on a pin
simon.ford@mbed.co.uk 5:62573be585e9 20 *
simon.ford@mbed.co.uk 5:62573be585e9 21 * Example:
screamer 43:aff670d0d510 22 * @code
screamer 43:aff670d0d510 23 * // Print messages when the AnalogIn is greater than 50%
screamer 43:aff670d0d510 24 *
screamer 43:aff670d0d510 25 * #include "mbed.h"
screamer 43:aff670d0d510 26 *
screamer 43:aff670d0d510 27 * AnalogIn temperature(p20);
screamer 43:aff670d0d510 28 *
screamer 43:aff670d0d510 29 * int main() {
screamer 43:aff670d0d510 30 * while(1) {
screamer 43:aff670d0d510 31 * if(temperature > 0.5) {
screamer 43:aff670d0d510 32 * printf("Too hot! (%f)", temperature.read());
screamer 43:aff670d0d510 33 * }
screamer 43:aff670d0d510 34 * }
screamer 43:aff670d0d510 35 * }
screamer 43:aff670d0d510 36 * @endcode
simon.ford@mbed.co.uk 0:82220227f4fa 37 */
simon.ford@mbed.co.uk 0:82220227f4fa 38 class AnalogIn : public Base {
simon.ford@mbed.co.uk 0:82220227f4fa 39
simon.ford@mbed.co.uk 0:82220227f4fa 40 public:
simon.ford@mbed.co.uk 0:82220227f4fa 41
screamer 43:aff670d0d510 42 /** Create an AnalogIn, connected to the specified pin
simon.ford@mbed.co.uk 5:62573be585e9 43 *
screamer 43:aff670d0d510 44 * @param pin AnalogIn pin to connect to
screamer 43:aff670d0d510 45 * @param name (optional) A string to identify the object
simon.ford@mbed.co.uk 5:62573be585e9 46 */
screamer 43:aff670d0d510 47 AnalogIn(PinName pin, const char *name = NULL);
screamer 43:aff670d0d510 48
screamer 43:aff670d0d510 49 /** Read the input voltage, represented as a float in the range [0.0, 1.0]
simon.ford@mbed.co.uk 5:62573be585e9 50 *
screamer 43:aff670d0d510 51 * @returns A floating-point value representing the current input voltage, measured as a percentage
simon.ford@mbed.co.uk 5:62573be585e9 52 */
screamer 43:aff670d0d510 53 float read();
simon.ford@mbed.co.uk 5:62573be585e9 54
screamer 43:aff670d0d510 55 /** Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
simon.ford@mbed.co.uk 5:62573be585e9 56 *
screamer 43:aff670d0d510 57 * @returns
screamer 43:aff670d0d510 58 * 16-bit unsigned short representing the current input voltage, normalised to a 16-bit value
simon.ford@mbed.co.uk 5:62573be585e9 59 */
simon.ford@mbed.co.uk 5:62573be585e9 60 unsigned short read_u16();
simon.ford@mbed.co.uk 5:62573be585e9 61
rolf.meyer@arm.com 11:1c1ebd0324fa 62 #ifdef MBED_OPERATORS
screamer 43:aff670d0d510 63 /** An operator shorthand for read()
simon.ford@mbed.co.uk 5:62573be585e9 64 *
screamer 43:aff670d0d510 65 * The float() operator can be used as a shorthand for read() to simplify common code sequences
simon.ford@mbed.co.uk 5:62573be585e9 66 *
simon.ford@mbed.co.uk 5:62573be585e9 67 * Example:
screamer 43:aff670d0d510 68 * @code
screamer 43:aff670d0d510 69 * float x = volume.read();
screamer 43:aff670d0d510 70 * float x = volume;
screamer 43:aff670d0d510 71 *
screamer 43:aff670d0d510 72 * if(volume.read() > 0.25) { ... }
screamer 43:aff670d0d510 73 * if(volume > 0.25) { ... }
screamer 43:aff670d0d510 74 * @endcode
simon.ford@mbed.co.uk 0:82220227f4fa 75 */
rolf.meyer@arm.com 11:1c1ebd0324fa 76 operator float();
rolf.meyer@arm.com 11:1c1ebd0324fa 77 #endif
simon.ford@mbed.co.uk 4:5d1359a283bc 78
rolf.meyer@arm.com 11:1c1ebd0324fa 79 #ifdef MBED_RPC
simon.ford@mbed.co.uk 5:62573be585e9 80 virtual const struct rpc_method *get_rpc_methods();
simon.ford@mbed.co.uk 5:62573be585e9 81 static struct rpc_class *get_rpc_class();
rolf.meyer@arm.com 11:1c1ebd0324fa 82 #endif
simon.ford@mbed.co.uk 5:62573be585e9 83
simon.ford@mbed.co.uk 0:82220227f4fa 84 protected:
rolf.meyer@arm.com 11:1c1ebd0324fa 85
rolf.meyer@arm.com 11:1c1ebd0324fa 86 ADCName _adc;
rolf.meyer@arm.com 11:1c1ebd0324fa 87
simon.ford@mbed.co.uk 0:82220227f4fa 88 };
simon.ford@mbed.co.uk 0:82220227f4fa 89
rolf.meyer@arm.com 11:1c1ebd0324fa 90 } // namespace mbed
simon.ford@mbed.co.uk 0:82220227f4fa 91
simon.ford@mbed.co.uk 1:6b7f447ca868 92 #endif
emilmont 27:7110ebee3484 93
emilmont 27:7110ebee3484 94 #endif