Hi,
I'm at the end of my wits here. I have a 3-axis machine with push button encoders (every time the shaft driving the axis rotates it clicks the switch and counts up in the micro-controller.) With this, each possible position is given a coordinate (x,y,z.) Once in a position I press a button which "teaches" this position by storing the x, y and z values in tags: x1, y1 and z1. I move to another spot and teach the position again, this time in tags: x2, y2 and z2. To prevent bounce in the "encoder" P.B.s I have a delay of 75-100 milliseconds which i tuned through testing to find the ideal time. There is again a bounce in the "teach" button but I again have found a way around that. Now in serial monitor if I just monitor: x encoder count and y encoder count I have no problems, however if i monitor: x encoder count, y encoder count, x1, y1, z1, x2, y2 and z2 then my x count and y count become inaccurate (when they should be around 20 they have only registered 5 clicks of the encoder P.B.) Any ideas of what this might be?
// Encoder Count/Position + Debounce
//==================================
if (y_toggle == HIGH && com_sum == 1)
{
y_pos = y_pos+1;
delay(100);
}
if (y_toggle == HIGH && com_sum == 2)
{
y_pos = y_pos-1;
delay(75);
}
if (x_toggle == HIGH && com_sum == 4)
{
x_pos = x_pos+1;
delay(50);
}
if (x_toggle == HIGH && com_sum == 3)
{
x_pos = x_pos-1;
delay(50);
}
// Teach Position
//===============
if (com_sum == 7 && cur_pos == 0)
{
x1 = x_pos;
y1 = y_pos;
z1 = z_pos;
cur_pos = cur_pos+1;
}
if (com_sum == 7 && cur_pos == 1 && x1 != x_pos && y1 != y_pos)
{
x2 = x_pos;
y2 = y_pos;
z2 = z_pos;
cur_pos = cur_pos+1;
}
Serial.println(x_pos);
Serial.println(y_pos);
Serial.println(x1);
Serial.println(y1);
Serial.println(x2);
Serial.println(y2);
Serial.println("================");