Serially?
Sunday, December 2, 2007
Today was incredibly frustrating, but we made some small strides. I managed to get all 16 of the MUX values, and the additional IR analog values reading through Arduino. I couldn't, however, get the values to run properly through Processing.
Here's my Arduino code. In an attempt to stop any extraneous values from coming into the processing program, I commented out all of the printlns that I could.
*****
int val[16];
int a= 3; // SELECT PIN A0 GOING INTO PIN 2
int b= 4; // SELECT PIN A1 GOING INTO PIN 3
int c= 5; // SELECT PIN A2 GOING INTO PIN 4 //variables in this code have been changed from their original value of Int
//to BYTE.
int d= 6; // SELECT PIN A3 GOING INTO PIN 5
int analog0 = 0;
//NEW INFORMATION
int analog1 = 0;
int analog2 = 0;
void setup() {
Serial.begin(9600);
pinMode(analog0, INPUT);
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(c,OUTPUT);
pinMode(d,OUTPUT);
//NEW INFORMATION
pinMode(analog1, INPUT);
pinMode(analog2, INPUT);
}
void loop() {
for (int channelNum = 0; channelNum < 16; channelNum ++) {
// determine the four address pin values from the channelNum:
// mask off bit 0:
int pinOne = 1 & channelNum;
// shift value 1 bit to the right, and mask all but bit 0:
int pinTwo = 1 & (channelNum >> 1) ;
// shift value 2 bits to the right, and mask all but bit 0:
int pinThree = 1 & (channelNum >> 2);
// shift value 3 bits to the right, and mask all but bit 0:
int pinFour = 1 & (channelNum >> 3);
// set the address pins:
digitalWrite(a,pinOne);
digitalWrite(b,pinTwo);
digitalWrite(c,pinThree);
digitalWrite(d,pinFour);
// read the analog input and store it in the value array:
val[channelNum] = analogRead(analog0)/4;
// as a unique value to punctuate the sentence:
//if (val[channelNum] == 255) {
//val[channelNum] = 254;
//}
// print the values as a single tab-separated line:
//Serial.print("VALUE");
//Serial.print(val[channelNum], BYTE);
//Serial.print("\t");
//Serial.println();
//delay(5);
}
// print a carriage return at the end of each read of the mux:
//Serial.println();
//NEW INFORMATION
analog1 = analogRead(1)/4;
analog2 = analogRead(2)/4;
if (analog1 == 255) {
analog1 = 254;
}
//Serial.print("AN1 ");
Serial.print(analog1, BYTE);
// if (analog2 == 255) {
// analog2 = 244;
//}
//Serial.print("AN2 ");
Serial.print(analog2, BYTE);
//Serial.print("Done");
//Serial.println();
//Serial.print(255, BYTE);
delay(10);
//Serial.println();
//Serial.print("Start ");
}
****
Initially I was using the punctuation method for Processing/Arduino and then I tried call and response. I'm hoping that sleeping on it will give me an advantage tomorrow.
The val array is for the first 16 MUX values (on analog pin0), then there are an additional 2 values for analog1 and analog2. The last, 19th, value is for the punctuation -- in this case 255, or 1023 divided by 4.
I can't seem to get processing to read the values in any meaningful way though. I can see, in the serial port, hat the values are coming through accurately and in order. In processing I have an array of 19 values.
posted by Amanda @ 12/02/2007 09:41:00 PM,