Hi all !
I have some questions regarding the interrupts which are used for measuring the encoder counts and the storage of the counts in an array. This is because i want to store the counts in an array and use them in the void loop() function.
When i am using the variable encoder0Pos in the void loop(), the program takes into account only the last value of encoder0Pos. It is possible to store all these values in an array?
For example the code:
void doEncoder()
{
if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) {
sensorL[1000]=encoder0Pos++;
} else {
sensorL[1000]=encoder0Pos--;
}
//Serial.println(encoder0Pos);
for(i=0; i=1000; i++){ //print the elements of an array over the serial port
Serial.println(sensorL[i]);
//};
}
I am asking this question because i am dealing with 2 motors for a mobile robot and i am trying to implement dead reckoning. In other words to calculate the position of the robot in the x-y plain. The problem is that if i do not use arrays the program gives me only the last value of x and y. For example i run the program and the counters counts for example.
counter1: 1 2 3 4 (assuming 4 is the last count)
counter2: 1 2 3 4
So the void loop() calculates for every count the x and y coordinates. However when i am using Serial.print(x) in the void loop() i can see only the last calculated value of x, for example for counter1=4, x=5 meters. I would like to use serial.print(x) and see all the values of x, starting from 0 1 2 3 4 5 meters.