Hello everyone,
I built a robot with a Arduino card and I need some help for the Arduino programmation. Indeed, this code have to count turns of the wheel of my robot. I have some numbers with it but I don't understand what it is.
Can you help me to understand what the result is ? Ans how to get the number of turns of the wheel ?
Thank you !
The code :
#define RIGHT 1
long coder[2] = {
0,0};
int lastSpeed[2] = {
0,0};
void setup(){
Serial.begin(9600); //init the Serial port to print the data
attachInterrupt(RIGHT, RwheelSpeed, CHANGE); //init the interrupt mode for the digital pin 3
}
void loop(){
static unsigned long timer = 0; //print manager timer
if(millis() - timer > 100){
Serial.print("Coder value: ");
Serial.print(coder);
Serial.println("[Right Wheel]");
lastSpeed = coder;
coder = 0;
timer = millis();
}
}
void RwheelSpeed()
{
coder ++; //count the right wheel encoder interrupts
}