Need help programming motor movement from PS3 controller inputs
i have put camera slider uses brushed dc motor. driven arduino uno , seeedstudio motor shield (v1.2). have usb shield sandwiched between motor shield , arduino. accepts inputs ps3 controller.
i able receive , view commands ps3 controller on serial monitor. know ps3 bluetooth library have works. need how take data ps3 controller , move motor. forgive ignorance, brand new this. c++. have had lot of fun basic stamp in past, whole new ballgame. appreciated.
my goal @ stage @ least able make camera slide left/right l1/l2 ps3 buttons respectively.
i have included picture of setup code using no avail. have included annotated screenshot of code underscore problem.
here's code:
i able receive , view commands ps3 controller on serial monitor. know ps3 bluetooth library have works. need how take data ps3 controller , move motor. forgive ignorance, brand new this. c++. have had lot of fun basic stamp in past, whole new ballgame. appreciated.
my goal @ stage @ least able make camera slide left/right l1/l2 ps3 buttons respectively.
i have included picture of setup code using no avail. have included annotated screenshot of code underscore problem.
here's code:
code: [select]
#include <ps3bt.h>
usb usb;
btd btd(&usb); // have create bluetooth dongle instance so
/* can create instance of class in 2 ways */
ps3bt ps3(&btd); // create instance
//ps3bt ps3(&btd,0x00,0x15,0x83,0x3d,0x0a,0x57); // store bluetooth address - can obtained dongle when running sketch
boolean printtemperature;
boolean printangle;
int pini1=8;//define i1 interface
int pini2=11;//define i2 interface
int speedpina=9;//enable motor a
int pini3=12;//define i3 interface
int pini4=13;//define i4 interface
int speedpinb=10;//enable motor b
int spead =127;//define spead of motor
void setup() {
serial.begin(115200);
if (usb.init() == -1) {
serial.print(f("\r\nosc did not start"));
while(1); //halt
}
serial.print(f("\r\nps3 bluetooth library started"));
pinmode(pini1,output);
pinmode(pini2,output);
pinmode(speedpina,output);
pinmode(pini3,output);
pinmode(pini4,output);
pinmode(speedpinb,output);
}
void right()//
{
analogwrite(speedpina,spead);//input simulation value set speed
analogwrite(speedpinb,spead);
digitalwrite(pini4,low);//turn dc motor b move anticlockwise
digitalwrite(pini3,high);
digitalwrite(pini2,low);//turn dc motor move clockwise
digitalwrite(pini1,high);
}
void left()//
{
analogwrite(speedpina,spead);//input simulation value set speed
analogwrite(speedpinb,spead);
digitalwrite(pini4,high);//turn dc motor b move clockwise
digitalwrite(pini3,low);
digitalwrite(pini2,high);//turn dc motor move clockwise
digitalwrite(pini1,low);
}
void stop()//
{
digitalwrite(speedpina,low);// unenble pin, stop motor. should done avid damaging motor.
digitalwrite(speedpinb,low);
delay(1000);
}
void loop() {
left();
delay(2000);
stop();
right();
delay(2000);
stop();
usb.task();
if(ps3.ps3connected || ps3.ps3navigationconnected) {
if(ps3.getanaloghat(lefthatx) > 137 || ps3.getanaloghat(lefthatx) < 117 || ps3.getanaloghat(lefthaty) > 137 || ps3.getanaloghat(lefthaty) < 117 || ps3.getanaloghat(righthatx) > 137 || ps3.getanaloghat(righthatx) < 117 || ps3.getanaloghat(righthaty) > 137 || ps3.getanaloghat(righthaty) < 117) {
serial.print(f("\r\nlefthatx: "));
serial.print(ps3.getanaloghat(lefthatx));
serial.print(f("\tlefthaty: "));
serial.print(ps3.getanaloghat(lefthaty));
serial.print(f("\trighthatx: "));
serial.print(ps3.getanaloghat(righthatx));
serial.print(f("\trighthaty: "));
serial.print(ps3.getanaloghat(righthaty));
}
//analog button values can read buttons
if(ps3.getanalogbutton(l2_analog) > 0 || ps3.getanalogbutton(r2_analog) > 0) {
serial.print(f("\r\nl2: "));
serial.print(ps3.getanalogbutton(l2_analog));
serial.print(f("\tr2: "));
serial.print(ps3.getanalogbutton(r2_analog));
}
if(ps3.getbuttonclick(ps)) {
serial.print(f("\r\nps"));
ps3.disconnect();
}
else {
if(ps3.getbuttonclick(triangle))
serial.print(f("\r\ntraingle"));
if(ps3.getbuttonclick(circle))
serial.print(f("\r\ncircle"));
if(ps3.getbuttonclick(cross))
serial.print(f("\r\ncross"));
if(ps3.getbuttonclick(square))
serial.print(f("\r\nsquare"));
if(ps3.getbuttonclick(up)) {
serial.print(f("\r\nup"));
if(ps3.ps3connected) {
ps3.setalloff();
ps3.setledon(led4);
}
}
if(ps3.getbuttonclick(right)) {
serial.print(f("\r\nright"));
if(ps3.ps3connected) {
ps3.setalloff();
ps3.setledon(led1);
}
}
if(ps3.getbuttonclick(down)) {
serial.print(f("\r\ndown"));
if(ps3.ps3connected) {
ps3.setalloff();
ps3.setledon(led2);
}
}
if(ps3.getbuttonclick(left)) {
serial.print(f("\r\nleft"));
if(ps3.ps3connected) {
ps3.setalloff();
ps3.setledon(led3);
}
}
if(ps3.getbuttonclick(l1))
serial.print(f("\r\nl1"));
if(ps3.getbuttonclick(l3))
serial.print(f("\r\nl3"));
if(ps3.getbuttonclick(r1))
serial.print(f("\r\nr1"));
if(ps3.getbuttonclick(r3))
serial.print(f("\r\nr3"));
if(ps3.getbuttonclick(select)) {
serial.print(f("\r\nselect - "));
serial.print(ps3.getstatusstring());
}
if(ps3.getbuttonclick(start)) {
serial.print(f("\r\nstart"));
printangle = !printangle;
}
}
if(printangle) {
serial.print(f("\r\npitch: "));
serial.print(ps3.getangle(pitch));
serial.print(f("\troll: "));
serial.print(ps3.getangle(roll));
}
}
else if(ps3.ps3moveconnected) {
if(ps3.getanalogbutton(t_analog) > 0) {
serial.print(f("\r\nt: "));
serial.print(ps3.getanalogbutton(t_analog));
}
if(ps3.getbuttonclick(ps)) {
serial.print(f("\r\nps"));
ps3.disconnect();
}
else {
if(ps3.getbuttonclick(select)) {
serial.print(f("\r\nselect"));
printtemperature = !printtemperature;
}
if(ps3.getbuttonclick(start)) {
serial.print(f("\r\nstart"));
printangle = !printangle;
}
if(ps3.getbuttonclick(triangle)) {
serial.print(f("\r\ntriangle"));
ps3.movesetbulb(red);
}
if(ps3.getbuttonclick(circle)) {
serial.print(f("\r\ncircle"));
ps3.movesetbulb(green);
analogwrite(speedpinb,spead);
digitalwrite(pini4,low);//turn dc motor b move anticlockwise
digitalwrite(pini3,high);
}
if(ps3.getbuttonclick(square)) {
serial.print(f("\r\nsquare"));
ps3.movesetbulb(blue);
analogwrite(speedpinb,spead);
digitalwrite(pini4,high);//turn dc motor b move clockwise
digitalwrite(pini3,low);
}
if(ps3.getbuttonclick(cross)) {
serial.print(f("\r\ncross"));
ps3.movesetbulb(yellow);
}
if(ps3.getbuttonclick(move)) {
ps3.movesetbulb(off);
serial.print(f("\r\nmove"));
serial.print(f(" - "));
serial.print(ps3.getstatusstring());
}
}
if(printangle) {
serial.print(f("\r\npitch: "));
serial.print(ps3.getangle(pitch));
serial.print(f("\troll: "));
serial.print(ps3.getangle(roll));
}
else if(printtemperature) {
serial.print(f("\r\ntemperature: "));
serial.print(ps3.gettemperature());
}
}
}
i've got same issue same setup. did ever figure out?
Arduino Forum > Using Arduino > Programming Questions > Need help programming motor movement from PS3 controller inputs
arduino
Comments
Post a Comment