Alright, for my project Im were stacking Adafruit motor shields on top of a USB host shield that is stacked on an Arduino Mega. This is being controlled by a PS3 controller (cannot write actual word) via USB Dongle connected to USB Host Shield.
While writing the code we get the the PS3 button to start the corresponding motor but we can't make it stop. I wrote a code that makes it move only move when I press X button but its really slow compared to the speed it should be. Were using DC Motors but others have used servos. Then use a one line if and then an else statement.
Do any of you know anything regarding this? Can you rewrite my code to a one line if statement?
I attached the void loop (part that makes this happen) for both the servo case(worked for others) and the DC case (that I wrote but doesn't work as desired).
SERVO
void loop()
{
Usb.Task();
if(PS3.PS3Connected || PS3.PS3NavigationConnected) {
servo1.write(map(PS3.getAnalogHat(RightHatX), 0, 255, 0, 180));
servo2.write(map(PS3.getAnalogHat(LeftHatY), 0, 255, 180, 0));
}
else
{
servo1.write(90);
servo2.write(90);
}
if(PS3.getButtonClick(PS)) {
PS3.disconnect();
}
}
DC
void loop() {
// put your main code here, to run repeatedly
Usb.Task();
if(PS3.PS3Connected || PS3.PS3NavigationConnected) {
if(PS3.getButtonPress(CROSS))
M11->run(FORWARD);
M11->setSpeed(150);
}
{
M11->setSpeed(0);
}
}
YES, Ive tried putting in an else function after the if. No luck, the motor doesn't stop when press is released or when the button is pressed again.