it only responds to else part it seems. We are trying to control a motor on a L298N but we only get one direction and we also want it to vary the speed. So we need to make the center of the joy stick make LY = 0 and all the way up and down make LY = 256
We seem to be closer but still not there. It controls the motor in one direction only, but does seem to control speed. I am working with my student team programmer over facebook so it is hard to do. We have class Tuesday, Wendsday, and Thursdays. I need to bring home one of the extra motors so I can try this at home too.
High on "in3" and Low in "in4" causes the motor to spin in one derection and High on "in4" and Low in "in3" causes the motor to spin in the oposite direction, "enB" is motor speed.
opps
sorry for the double print. code is:
step 1 print out the
LY=ps2x.Analog(PSS_LY);
Try this
latest
ok .. you said the ps3
ok .. you said the ps3 joystick library gives you values
0 (full down) <--> 127 (deadstick) <--> 256 (full up)
So you want your if statement to be
if LY < 127
go forward
else if LY > 127
go reverse
else
stop
The default I like to have "stop" it makes it easy then to "widen" the deadstick area.
For example :
if LY < 126
go forward
else if LY > 128
go reverse
else
stop
Now there is a bit more deadstick so the robot doesnt go when you don't want it to go...
not working yet
We seem to be closer but still not there. It controls the motor in one direction only, but does seem to control speed. I am working with my student team programmer over facebook so it is hard to do. We have class Tuesday, Wendsday, and Thursdays. I need to bring home one of the extra motors so I can try this at home too.
When we tried "else" statments we get an error: https://www.facebook.com/photo.php?fbid=1292902834189512&set=p.12929028…
Not sure if you can use the link or not.
Any thoughts?
LY=ps2x.Analog(PSS_LY);
Serial.println(LY);
if (LY < 127) {
Spd = map(LY, 126, 0, 0, 257);
analogWrite(enB, LY);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
Serial.println(LY);
}
if (LY > 127) {
Spd = map(LY, 127, 257, 0, 257);
analogWrite(enB, LY);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
Serial.println(LY);
}
if (LY == 127) {
LY = 0;
analogWrite(enB, LY);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
Serial.println(LY);
}
High on "in3" and Low in "in4" causes the motor to spin in one derection and High on "in4" and Low in "in3" causes the motor to spin in the oposite direction, "enB" is motor speed.
You are setting a speed value
You are setting a speed value by mapping it from your joystick value, but I dont see you using it?
In addition, if you are using an H-bridge isnt it better to do a brake with both pins low instead of one high and the other low?
Opps and thanks!
I was not sure about the double LOW's and ya I forgot some code LOL thanks! Hope this looks better!
LY=ps2x.Analog(PSS_LY);
Serial.println(LY);
if (LY < 127) {
spd = map(LY, 126, 0, 0, 257);
analogWrite(enB, spd);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
Serial.println(spd);
}
if (LY > 127) {
spd = map(LY, 127, 257, 0, 257);
analogWrite(enB, spd);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
Serial.println(spd);
}
if (LY == 127) {
spd = 0;
analogWrite(enB, spd);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
Serial.println(spd);
}
full code