Error Message - "The function analogRead(int) does not exist"
in
Core Library Questions
•
2 years ago
Hello,
I'm new to programming and I'm trying pull serial data from my Arduino into Processing. The data is coming from an accelerometer. I have installed "Standard Firmata" on the Arduino but when I try to run my processing program, I'm getting the above mentioned error message. Any help would be much appreciated. Here's my code:
I'm new to programming and I'm trying pull serial data from my Arduino into Processing. The data is coming from an accelerometer. I have installed "Standard Firmata" on the Arduino but when I try to run my processing program, I'm getting the above mentioned error message. Any help would be much appreciated. Here's my code:
- import processing.serial.*;
Serial port;
int serialCount = 3;
int sensorPinX = 2;
int sensorPinY = 3;
int sensorPinZ = 4;
int[] xArray = new int [8]; //smoothing can adjust numbers from 0 - 10 or highger
int[] yArray = new int [8];
int[] zArray = new int [8];
char DELIM = ',';
int length;
void setup() {
String arduinoPort = Serial.list()[0];
port = new Serial(this, arduinoPort, 9600);
}
void draw() {
int i;
int xpos;
int ypos;
int zpos;
addEntry(xpos,xArray);
ypos = analogRead(sensorPinY);
addEntry(ypos,yArray);
zpos = analogRead(sensorPinZ);
addEntry(zpos,zArray);
Serial.print(xpos);
Serial.print(" ");
Serial.print(ypos);
Serial.print(" ");
Serial.println(zpos);
delay(100);
}
int getAverage(int valueArray []){
int i;
int sum = 0;
int average;
for (i=0;i<length;i++) {
sum += valueArray[i];
}
average = sum/length;
return average;
}
void addEntry(int value, int valueArray []) {
int i;
for (i=0;i<length-1;i++) {
valueArray[i]=valueArray[i+1];
}
valueArray[length-1] = value;
}
void serialEvent(Serial myPort) {
String serialString = myPort.readStringUntil('\n');
if (serialString != null) {
String[] numbers = split(serialString, DELIM);
if (numbers.length == sensorCount) {
addEntry(numbers[2],xArray); //pin numbers inside braces
addEntry(numbers[3],yArray);
addEntry(numbers[4],zArray);
}
}
}
1