I'm having trouble controlling a 3 axis fireball V90 with the arduino. I have written code to control the x,y and z axis with the use of 6 buttons. I split the code into 3 different programs each controlling one of the axis and each axis will work flawlessly. When I put them together into one code, only one of the axis will function. I'm using a tone function to step the motor. I added a noTone() function into the if loop after the tone function, which will allow function of all 3 axis but there is a jerkyness to the movement then. Is there a way to have all three axis work without using the noTone() function?
I had the steps print to the serial monitor so I could see what was happening as the program went along. This leads to my second question. Why does the program enter the if loops when i haven't pressed the button and have the values of the buttonpins initially set to low?
I have very limited experience with coding so if you can please help!
Here is the code I have written.
const int Xdirection = 12;
const int Xstepper = 13;
const int Ydirection = 4;
const int Ystepper = 7;
const int Zdirection = 2;
const int Zstepper = 6;
int buttonpin1 = LOW;
int buttonpin2 = LOW;
int buttonpin3 = LOW;
int buttonpin4 = LOW;
int buttonpin5 = LOW;
int buttonpin6 = LOW;
int button1;
int button2;
int button3;
int button4;
int button5;
int button6;
void setup() {
// put your setup code here, to run once:
pinMode(Xdirection, OUTPUT);
pinMode(Xstepper, OUTPUT);
pinMode(Ydirection, OUTPUT);
pinMode(Ystepper, OUTPUT);
pinMode(Zdirection, OUTPUT);
pinMode(Zstepper, OUTPUT);
pinMode(buttonpin1, INPUT);
pinMode(buttonpin2, INPUT);
pinMode(buttonpin3, INPUT);
pinMode(buttonpin4, INPUT);
pinMode(buttonpin5, INPUT);
pinMode(buttonpin6, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
button1 = digitalRead(buttonpin1);
Serial.println("buttonpin1 read");
button2 = digitalRead(buttonpin2);
Serial.println("buttonpin2 read");
if (button1 == HIGH)
{
digitalWrite(Xdirection, button2);
tone(Xstepper, 500);
Serial.println ("move forward or back");
noTone(Xstepper);
}
button3 = digitalRead(buttonpin3);
Serial.println("buttonpin3 read");
button4 = digitalRead(buttonpin4);
Serial.println("buttonpin4 read");
if (button3 == HIGH)
{
digitalWrite(Ydirection, button4);
tone(Ystepper, 500);
Serial.println ("move left or right");
noTone(Ystepper);
}
button5 = digitalRead(buttonpin5);
Serial.println("buttonpin5 read");
button6 = digitalRead(buttonpin6);
Serial.println("buttonpin6 read");
if (button5 == HIGH)
{
digitalWrite(Zdirection, button6);
tone(Zstepper, 500);
Serial.println ("move up or down");
noTone(Zstepper);
}
}