mirror of
https://github.com/eclipse/upm.git
synced 2025-03-19 15:07:35 +03:00
54 lines
1.4 KiB
C++
54 lines
1.4 KiB
C++
/*
|
|
* Author: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
|
* Copyright (c) 2014 Intel Corporation.
|
|
*
|
|
* This program and the accompanying materials are made available under the
|
|
* terms of the The MIT License which is available at
|
|
* https://opensource.org/licenses/MIT.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#include <iostream>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
|
|
#include "rotary.hpp"
|
|
#include "upm_utilities.h"
|
|
|
|
using namespace std;
|
|
|
|
int
|
|
main()
|
|
{
|
|
//! [Interesting]
|
|
// Instantiate a rotary sensor on analog pin A0
|
|
upm::Rotary knob(0);
|
|
|
|
// Print sensor name to confirm it initialized properly
|
|
cout << knob.name() << endl;
|
|
|
|
while (true) {
|
|
float abs_value = knob.abs_value(); // Absolute raw value
|
|
float abs_deg = knob.abs_deg(); // Absolute degrees
|
|
float abs_rad = knob.abs_rad(); // Absolute radians
|
|
float rel_value = knob.rel_value(); // Relative raw value
|
|
float rel_deg = knob.rel_deg(); // Relative degrees
|
|
float rel_rad = knob.rel_rad(); // Relative radians
|
|
|
|
fprintf(stdout,
|
|
"Absolute: %4d raw %5.2f deg = %3.2f rad Relative: %4d raw %5.2f "
|
|
"deg %3.2f rad\n",
|
|
(int16_t) abs_value,
|
|
abs_deg,
|
|
abs_rad,
|
|
(int16_t) rel_value,
|
|
rel_deg,
|
|
rel_rad);
|
|
|
|
upm_delay_us(2500000); // Sleep for 2.5s
|
|
}
|
|
//! [Interesting]
|
|
return 0;
|
|
}
|