- Joined
- Feb 15, 2020
- Messages
- 404
WARNING! Programming Stuff Follows!
After some sleep loss I have some working code with error correction.
I had to do some extra stuff to move counter clockwise because if you step backward past zero degrees the original code failed.
I'll be back to explain this after some chores.
Eric
After some sleep loss I have some working code with error correction.
Code:
case '3': // Rotate CW
newKey = false; // Clear key flag
if(MotStat == true) // Do this if motor is on
{
current = current + Degrees; // Add new degrees to current total
if(current >= 360)
{
current = (current - 360); // Keep it under 360
CSteps = 0;
}
if(current == 0) // Prevents "0/360" error below
{
ToMove = Degrees * (Multiplier/360); // Figure out how many steps to move
CSteps = 0; // Reset cumulative step counter
}
else
{
ToMove = (current/360) * Multiplier + 0.5 - CSteps; // This is where the magic happens!
CSteps = CSteps + ToMove; // Add moved steps to step counter
}
// More stuff follows to move table and update display...
}
I had to do some extra stuff to move counter clockwise because if you step backward past zero degrees the original code failed.
Code:
case '1': // Rotate CCW
newKey = false; // Clear key flag
if(MotStat == true) // Do this if motor is on
{
current = current - Degrees;
if(current < 0)
{
current = (current + 360); // Add new degrees to current total
CSteps = (Multiplier - CSteps); // Add table steps/rev to total steps
}
if(current == 0) // Prevents "0/360" error below
{
ToMove = Degrees * (Multiplier/360);
CSteps = 0;
}
else
{
ToMove = CSteps + 0.5 - (current * Multiplier)/360; // More magic!
CSteps = CSteps - ToMove;
}
// More stuff follows to move table and update display...
}
I'll be back to explain this after some chores.
Eric
Last edited: