Hi Randy,
I didn't understand what you mean by "Adding another voltage". Could you please explain a bit more what are you planning to do?
Regarding the example, it shows how to "prepare" a message using a pre-determined format and fill the last two bytes of the "myMsg.data[]" with the actual voltage reading and send it to another node, which will unpack the "myMsg" and print on the screen.
The voltage reading is done using the function
T2Utils::readVoltage, which is defined in the files
src/utils/T2Utils.h and
src/utils/T2Utils.cpp
Here the voltage code function:
Code: Select all
uint16_t T2Utils::readVoltage(uint8_t analogPin, uint8_t controlPin, uint16_t maxVoltage, uint8_t samples)
{
analogReference(INTERNAL);
// Turn on the MOSFET via control pin
if(controlPin > 0)
{
digitalWrite(controlPin, HIGH);
pinMode(controlPin, OUTPUT);
}
// Read pin a couple of times and keep adding up.
uint16_t readings = 0;
for (uint8_t i = 0; i < samples; i++) {
readings += analogRead(analogPin);
}
// Turn off the MOSFET
if(controlPin > 0)
{
digitalWrite(controlPin, LOW);
}
/* Uncomment for Debug */
/*
Serial.print(F("AVG last X Analog Reads on analog Pin: "));
Serial.println(readings / samples);
Serial.print(F("Max Voltage: "));
Serial.println(maxVoltage);
Serial.print(F("Calculated voltage: "));
Serial.println((uint32_t)maxVoltage * (readings / samples) / 1023);
*/
/*
* This need to be casted over 32 bits to allow proper calculation.
* Still safe to return a 16 bits for results up to 65V
*/
return ((uint32_t)maxVoltage * (readings / samples) / 1023);
}
Also, you can have a look on the RFM69 examples from RadioHead, they are very simple and should work without modification (only Frequency maybe).
Not directly related to the question, but might help:
Unfortunately the Arduino IDE is a very simple "Text Editor" that does not allow source-code navigation. This makes very difficult to explore libraries and others people code. I personally like to use Eclipse to write the C/C++ code, which allows to easily navigate over the source code. I tend to use this modified version of Eclipse:
http://eclipse.baeyens.it/stable.php?OS=Windows - It might take a few frustrating hours to get it working, but it's a well spent time.
Sophisticated text editors might also assist with that, like Sublime. Some people just use a "real" IDE to write the C/C++ code, and get back to the Arduino IDE only for compiling and uploading it.
Hopefully Arduino would move toward a proper IDE in the future.