This code reads a 10-bit analog value, splits it into two bytes, and sends it out serially.
Written in Arduino, should work for both Arduino and Wiring.
/*
Analog Two Bytes
by Tom Igoe
Reads an 10-bit analog value from 0 - 1024, splits it into two bytes,
and sends the bytes out the serial port.
Created: 8 Feb. 2006
*/
int analogPin = 2;
int val; // outgoing ADC value
int highByte = 0;
int lowByte = 0;
void setup()
{
// start serial port at 9600 bps:
beginSerial(9600);
}
void loop()
{
// read analog input, divide by 4 to make the range 0-255:
val = analogRead(analogPin);
// divide by 256 to get the high byte:
highByte = val /256;
// take the remainder of the division to get the low byte:
lowByte = val % 256;
// send the two bytes out to in raw binary form:
serialWrite(highByte);
serialWrite(lowByte);
// pause for 10 milliseconds:
delay(10);
}