.remoteAnalogRead()

Description

Reads the value from the specified analog pin of a remote I/O board. Newer Arduino based i/o boards have six, 10-bit analog to digital converters. Input voltages are mapped from 0 to 1023. The function returns the full 10 bit (max 1023) value. YOU must SCALE it for ANALOG output through PWM (analogWrite).

NOTE: the remoteRead functions in this library can be MUCH slower than remoteWrite functions.  This is because remoteRead requires a serial handshake, which is time consuming.  Where possible, call remoteRead functions no more than 1x per second, or conceive of a system where remote changes are written.  Also,  transitions (edges) are best detected locally and then written to a remote NODE.

Compare with Arduino analogRead()

Syntax

remoteAnalogRead(pin);

Parameters

pin: the target pin number, INTEGER

Returns

Integer: Range 0 -1023

Example:

All examples require two NODES to operate. For simplicity, one NODE should run the following while another NODE is running the listener example.

Attach an LED to digital PIN 11 of the listener NODE. Attach a POT, photoCell or other analog input circuit to analog PIN 0 of the NODE running this code.


#include <StonesThrow.h>

StonesThrow st;

#define myID 2
#define pairWithID 1

void setup(){
   st.begin(myID, pairWithID);
   pinMode(11,OUTPUT);      //  must set pinmode for local PINs
}

void loop(){

   int analogValue = st.remoteAnalogRead(0);     // read a REMOTE analog pin

   analogValue = map(analogValue,0,1023,0,100);  // scale reading to single BYTE

   analogWrite(11, analogValue);                 // write scaled reading to LOCAL pin

   delay(100);  

}

[index]