problem with using a ps3 controller to light up an led


hello , i'm aiming control motor using ps3 controller . @ start wanted cheek if can control led :) . used usb host library , modified program when press x on controller led should high . when nothing happens !!!!

can 1 explain going wrong ? i'm beginner in arduino appreciate
here code
code: [select]

/*
example sketch ps3 usb library - developed kristian lauszus
more information visit blog: http://blog.tkjelectronics.dk/ or
send me e-mail:  kristianl@tkjelectronics.com
*/

#include <ps3usb.h>
usb usb;
int led = 13;
/* can create instance of class in 2 ways */
ps3usb ps3(&usb); // create instance
//ps3usb ps3(&usb,0x00,0x15,0x83,0x3d,0x0a,0x57); // store bluetooth address - can obtained dongle when running sketch

boolean printangle;
uint8_t state = 0;

void setup() {
  serial.begin(115200);
  pinmode(led, output);     
  if (usb.init() == -1) {
    serial.print(f("\r\nosc did not start"));
    while(1); //halt
  } 
  serial.print(f("\r\nps3 usb library started"));
}
void loop() {
  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));
      if(!ps3.ps3navigationconnected) {
        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) || ps3.getanalogbutton(r2)) {
      serial.print(f("\r\nl2: "));
      serial.print(ps3.getanalogbutton(l2));
      if(!ps3.ps3navigationconnected) {
        serial.print(f("\tr2: "));
        serial.print(ps3.getanalogbutton(r2));
      }
    }
    if(ps3.getbuttonclick(ps))
      serial.print(f("\r\nps"));

    if(ps3.getbuttonclick(triangle))
      serial.print(f("\r\ntraingle"));
    if(ps3.getbuttonclick(circle))
      serial.print(f("\r\ncircle"));
    if(ps3.getbuttonclick(cross))
      digitalwrite(led, high);
    if(ps3.getbuttonclick(square))
      serial.print(f("\r\nsquare"));

    if(ps3.getbuttonclick(up)) {
      serial.print(f("\r\nup"));
      ps3.setalloff();
      ps3.setledon(led4);
    }
    if(ps3.getbuttonclick(right)) {
      serial.print(f("\r\nright"));
      ps3.setalloff();
      ps3.setledon(led1);         
    }
    if(ps3.getbuttonclick(down)) {
      serial.print(f("\r\ndown"));
      ps3.setalloff();
      ps3.setledon(led2);         
    }
    if(ps3.getbuttonclick(left)) {         
      serial.print(f("\r\nleft"));
      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) { // 1 can set color of bulb, set rumble, set , bluetooth address , calibrate magnetometer via usb
    switch(state) {
    case 0:
      ps3.movesetrumble(0);   
      ps3.movesetbulb(off);     
      state = 1;
      break;

    case 1:
      ps3.movesetrumble(75);
      ps3.movesetbulb(red);     
      state = 2;
      break;

    case 2:
      ps3.movesetrumble(125);
      ps3.movesetbulb(green);     
      state = 3;
      break;

    case 3:
      ps3.movesetrumble(150);
      ps3.movesetbulb(blue);     
      state = 4;
      break;

    case 4:
      ps3.movesetrumble(175);
      ps3.movesetbulb(yellow);   
      state = 5;
      break;

    case 5:
      ps3.movesetrumble(200);
      ps3.movesetbulb(lightblue);   
      state = 6;
      break;

    case 6:
      ps3.movesetrumble(225);
      ps3.movesetbulb(purble);   
      state = 7;
      break;

    case 7:
      ps3.movesetrumble(250);
      ps3.movesetbulb(white);   
      state = 0;
      break;
    }
    delay(1000);
  }
}

the comments say
code: [select]
/* can create instance of class in 2 ways */
ps3usb ps3(&usb); // create instance
//ps3usb ps3(&usb,0x00,0x15,0x83,0x3d,0x0a,0x57); // store bluetooth address - can obtained dongle when running sketch
i cannot see either method in code.  missing ?


Arduino Forum > Using Arduino > Programming Questions > problem with using a ps3 controller to light up an led


arduino

Comments

Popular posts from this blog

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

How to format a Get Request

avrdude: verification error, first mismatch at byte 0x0000 0x0c != 0x62