In this example we read the analog-to-digital converter of the Prototyping 2.0 board every second and print the value obtained through the USB port.
Required Materials
1 x Waspmote
1 x Battery
1 x MiniUSB wire
1 x Prototyping v20 board
Notes
Take a look at the Prototyping v20 board technical guide for information about how to attach the sensor or device to be read to the analog-to-digital converter of the board.
Code
/*
* --[Pr_v20_1] - Reading the Analog-to-Digital converter at
* Prototyping v20 board--
*
* Explanation: Turn on the Prototyping v20 board and read the
* analog-to-digital converter on it once every second
*
* Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Version: 1.0
* Design: David Gascón
* Implementation: Marcos Yarza
*/
#include <WaspSensorPrototyping_v20.h>
//Variable to store the read value
float value;
void setup()
{
//Turn on the USB and print a start message
USB.ON();
USB.println(F("start"));
delay(100);
//Turn on the sensor board
SensorProtov20.ON();
//Turn on the RTC
RTC.ON();
}
void loop()
{
//Read the ADC
value = SensorProtov20.readADC();
//Print the result through the USB
USB.print(F("Value: "));
USB.print(value);
USB.println(F("V"));
delay(1000);
}