mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 17:31:13 +03:00
grove: sliding potentiometer
Signed-off-by: Mihai Tudor Panu <mihai.t.panu@intel.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:

committed by
Brendan Le Foll

parent
b2ffcdd9ea
commit
cebc339d91
@ -1,6 +1,8 @@
|
||||
add_executable (hmc5883l-example hmc5883l.cxx)
|
||||
add_executable (groveled-example groveled.cxx)
|
||||
add_executable (grovetemp-example grovetemp.cxx)
|
||||
add_executable (groverotary-example groverotary.cxx)
|
||||
add_executable (groveslide-example groveslide.cxx)
|
||||
add_executable (lcm-lcd-example lcm-lcd.cxx)
|
||||
add_executable (rgb-lcd-example rgb-lcd.cxx)
|
||||
add_executable (buzzer-sound-example buzzer-sound.cxx)
|
||||
@ -77,6 +79,8 @@ include_directories (${PROJECT_SOURCE_DIR}/src/tsl2561)
|
||||
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (grovetemp-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groverotary-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groveslide-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (lcm-lcd-example i2clcd ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (rgb-lcd-example i2clcd ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (buzzer-sound-example buzzer ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
50
examples/groveslide.cxx
Normal file
50
examples/groveslide.cxx
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Author: Mihai Tudor Panu <mihai.t.panu@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include "grove.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main ()
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::GroveSlide* slide = new upm::GroveSlide(0); // Instantiate new grove slide potentiometer on analog pin A0
|
||||
|
||||
cout << slide->name() << endl;
|
||||
|
||||
while(true) {
|
||||
float adc_value = slide->raw_value(); // Read raw value
|
||||
float volts = slide->voltage_value(); // Read voltage, board reference set at 5.0V
|
||||
fprintf(stdout, "%4d = %.2f V\n", (uint16_t)adc_value, volts);
|
||||
|
||||
usleep(2500000); // Sleep for 2.5s
|
||||
}
|
||||
//! [Interesting]
|
||||
delete slide;
|
||||
return 0;
|
||||
}
|
42
examples/javascript/groveslide.js
Normal file
42
examples/javascript/groveslide.js
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Author: Mihai Tudor Panu <mihai.t.panu@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var upm_grove = require('jsupm_grove');
|
||||
|
||||
//setup access analog input Analog pin #0 (A0)
|
||||
var groveSlide = new upm_grove.GroveSlide(0);
|
||||
|
||||
loop();
|
||||
|
||||
function loop()
|
||||
{
|
||||
var raw = groveSlide.raw_value();
|
||||
var volts = groveSlide.voltage_value();
|
||||
|
||||
//write the slider values to the console
|
||||
console.log("Slider Value: " + raw + " = " + volts.toFixed(2) + " V");
|
||||
|
||||
//wait 2 s then call function again
|
||||
setTimeout(loop, 2000);
|
||||
}
|
39
examples/python/groveslide.py
Normal file
39
examples/python/groveslide.py
Normal file
@ -0,0 +1,39 @@
|
||||
# Author: Mihai Tudor Panu <mihai.t.panu@intel.com>
|
||||
# Copyright (c) 2014 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
from time import sleep
|
||||
import pyupm_grove as grove
|
||||
|
||||
# New Grove Slider on AIO pin 0
|
||||
slider = grove.GroveSlide(0)
|
||||
|
||||
# Loop indefinitely
|
||||
while True:
|
||||
|
||||
# Read values
|
||||
raw = slider.raw_value()
|
||||
volts = slider.voltage_value()
|
||||
|
||||
print "Slider value: ", raw , " = %.2f" % volts , " V"
|
||||
|
||||
# Sleep for 2.5 s
|
||||
sleep(2.5)
|
Reference in New Issue
Block a user