Here is my set up:
Arduino Mega
Adafruit Motor Shields (x2 with independent addresses)
4 steppers, and 3 limit switches (2 wire).
I am currently trying to use the ezButton Library as it has some useful features like denouncing.
I am NOT using any firmware , this set up will NOT be able to use Gcode and will need to be programmed from the base up. So I am taking it one step at a time as I am relatively new to this stuff.
The limits are set to my Arduino Mega pins, 2, 3,4.
I have a buzzer set to pin 5, which I am using , along with the serial monitor, to simulate motor movement of the different axis's using different buzzer frequencies. If I had been using the actual motors, I would have fried several dozen motors by now...
The goal is simple; get a motor to run until the motor runs the apparatus into a limit switch, then shut off the motor. Then proceed to the next axis and do the same. then move to the third axis and repeat. Then Stop.
Later I'll program more things to happen after I reach a Home position, but for now, I am just trying to establish a "home" position where all three switches are "pressed" and the code is waiting for an input to proceed, or otherwise stopped.
#include <ezButton.h>
int buzzer =5;
ezButton button1(2); // create ezButton object that attach to pin 2;
ezButton button2(3); // create ezButton object that attach to pin 3;
ezButton button3(4); // create ezButton object that attach to pin 4;
void setup() {
Serial.begin(9600);
button1.setDebounceTime(5); // set debounce time to 50 milliseconds
button2.setDebounceTime(5); // set debounce time to 50 milliseconds
button3.setDebounceTime(5); // set debounce time to 50 milliseconds
pinMode(buzzer,OUTPUT);
}
void loop() {
button1.loop(); // MUST call the loop() function first
button2.loop(); // MUST call the loop() function first
button3.loop(); // MUST call the loop() function first
int btn1State = button1.getState();
int btn2State = button2.getState();
int btn3State = button3.getState();
delay (5);
//PAxis test
tone(buzzer,1000);
if(button1.isReleased()){
Serial.println("The Pbutton is released");
}
if(button1.isPressed()){
Serial.println("The Pbutton is pressed");
noTone (buzzer);
}
//XAxis test
tone(buzzer,1200);
if(button2.isReleased()){
Serial.println("The Xbutton is released");
}
if(button2.isPressed()){
Serial.println("The Xbutton is pressed");
noTone (buzzer);
}
//YAxis test
tone(buzzer,1400);
if(button3.isReleased()){
Serial.println("The Ybutton is released");
}
if(button3.isPressed()){
Serial.println("The Ybutton is pressed");
noTone (buzzer);
}
}
Right now, it is running all three buzzer frequencies simultaneously, and it will not shut any of them off if I hold down a limit switch. What did I miss?