ardupilot/libraries/AP_HAL/examples/AnalogIn/AnalogIn.cpp

28 lines
516 B
C++
Raw Normal View History

#include <AP_HAL/AP_HAL.h>
2012-09-10 23:05:22 -03:00
const AP_HAL::HAL& hal = AP_HAL::get_HAL();
2012-09-10 23:05:22 -03:00
AP_HAL::AnalogSource* ch;
2012-09-10 23:05:22 -03:00
void setup (void) {
hal.console->printf_P("Starting AP_HAL::AnalogIn test\r\n");
ch = hal.analogin->channel(0);
2012-09-10 23:05:22 -03:00
}
static int8_t pin;
void loop (void)
{
float v = ch->voltage_average();
if (pin == 0) {
hal.console->println();
}
hal.console->printf_P("[%u %.3f] ",
(unsigned)pin, v);
pin = (pin+1) % 16;
ch->set_pin(pin);
hal.scheduler->delay(100);
2012-09-10 23:05:22 -03:00
}
AP_HAL_MAIN();