A compilation of some hardware sensors and their shared programming interfaces.
Embed:
(wiki syntax)
Show/hide line numbers
ADCSensor.h
00001 /* ADCSensor.h 00002 * Tested with mbed board: FRDM-KL46Z 00003 * Author: Mark Gottscho 00004 * mgottscho@ucla.edu 00005 */ 00006 00007 #ifndef ADCSensor_H 00008 #define ADCSensor_H 00009 00010 #include "mbed.h" 00011 #include "PeriodicSensor.h" 00012 00013 class ADCSensor : public PeriodicSensor { 00014 public: 00015 /** 00016 * Constructs an ADCSensor. 00017 * @param adc_pin the ADC pin to use 00018 */ 00019 ADCSensor(PinName adc_pin); 00020 00021 ~ADCSensor(); 00022 00023 /** 00024 * @param sampleNow if true, samples the ADC returns it. if false, gets the last sampled value. 00025 * The latter is preferred if this object is set up to sample using interrupts. 00026 * @returns a raw ADC reading 00027 */ 00028 uint16_t getSample(bool sampleNow); 00029 00030 /** 00031 * @param sampleNow if true, samples the ADC returns it. if false, gets the last sampled value. 00032 * The latter is preferred if this object is set up to sample using interrupts. 00033 * @returns the ADC reading in Volts 00034 */ 00035 float getSampleFloat(bool sampleNow); 00036 00037 private: 00038 /** 00039 * Interrupt service routine for sampling the ADC. 00040 */ 00041 virtual void __sample_data_ISR(); 00042 00043 AnalogIn __adc; 00044 volatile uint16_t __data; 00045 00046 const static float ADC_DIV = 0.00005035; //Volts/level 00047 }; 00048 00049 #endif
Generated on Wed Jul 13 2022 19:24:40 by 1.7.2