Go Down

Topic: plz help me  (Read 99 times) previous topic - next topic

ZN2931

i have a problem which is i cant connect the cytron ps2 dualshock shield to my arduino uno. what should i do? do i need to connect the tx and rx first? i also use <Cytron_PS2Shield.h> as my library but i dont really understand how to use the library. plz i need answer ASAP.
i have sent the shield image. plz i need some help ASAP.

PaulS

Quote
i cant connect the cytron ps2 dualshock shield to my arduino uno.
Why can't you?

Quote
i also use <Cytron_PS2Shield.h> as my library but i dont really understand how to use the library.
Most libraries come with examples. Doesn't that one? Most of the time, when you use a non-core library, you need to post a link to it. This time is not an exception.

Quote
plz i need some help ASAP.
With spelling and grammar, obviously.
The art of getting good answers lies in asking good questions.

ZN2931

Code: [Select]

/*
Original written by:
            Cytron Technologies
Modified:
  29/06/15  Idris, Cytron Technologies    - Point to IDE SoftwareSerial
                                          - Restructure the code style to follow standard Arduino library
*/

#ifndef Cytron_PS2Shield_h
#define Cytron_PS2Shield_h

#include "Arduino.h"
#include <SoftwareSerial.h>

// Arduino Leonardo
#if defined (__AVR_ATmega32U4__)
  #define Serial Serial1
#else 
  #define Serial Serial
#endif

// Define PS2 button to number
enum {
  // Digital button
  #define PS2_SELECT 
  #define PS2_JOYSTICK_LEFT 
  #define PS2_JOYSTICK_RIGHT 
  #define PS2_START
  #define PS2_UP 
  #define PS2_RIGHT 
  #define PS2_DOWN 
  #define PS2_LEFT 
  #define PS2_LEFT_2 
  #define PS2_RIGHT_2 
  #define PS2_LEFT_1 
  #define PS2_RIGHT_1 
  #define PS2_TRIANGLE 
  #define PS2_CIRCLE 
  #define PS2_CROSS 
  #define PS2_SQUARE
  // Analog button
   PS2_JOYSTICK_LEFT_X_AXIS
   PS2_JOYSTICK_LEFT_Y_AXIS 
   PS2_JOYSTICK_RIGHT_X_AXIS 
   PS2_JOYSTICK_RIGHT_Y_AXIS 
   PS2_JOYSTICK_LEFT_UP 
   PS2_JOYSTICK_LEFT_DOWN 
   PS2_JOYSTICK_LEFT_LEFT 
   PS2_JOYSTICK_LEFT_RIGHT 
   PS2_JOYSTICK_RIGHT_UP 
   PS2_JOYSTICK_RIGHT_DOWN 
   PS2_JOYSTICK_RIGHT_LEFT 
   PS2_JOYSTICK_RIGHT_RIGHT 
  // Check connection status
  #define PS2_CONNECTION_STATUS 
  // Control motor vibrarion
   PS2_MOTOR_1 
   PS2_MOTOR_2 
  // Read all button
   PS2_BUTTON_JOYSTICK 
};

class Cytron_PS2Shield
{
  public:
   boolean SERIAL_ERR;
   uint8_t ps_data[6];
    uint8_t _txpin, _rxpin;

    // Software Serial
    Cytron_PS2Shield(uint8_t rxpin, uint8_t txpin);
    // Hardware Serial
    Cytron_PS2Shield();
  
    void begin(uint32_t baudrate);
    uint8_t readButton(uint8_t key);
    boolean readAllButton();
    void vibrate(uint8_t motor, uint8_t value);
    void reset(uint8_t reset);

  protected:
    boolean hardwareSerial;
    SoftwareSerial *PS2Serial;
    void write(uint8_t data);
    uint8_t read(void);
};

#endif
#include <Servo.h>

void setup() {
  // put your setup code here, to run once:
 pinMode(13, OUTPUT);
 pinMode(12, OUTPUT);
 pinMode(11, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
 int jlyu = analogRead(PS2_JOYSTICK_RIGHT_X_AXIS);
 
 if(jlyu < 25){
  digitalWrite(11, HIGH);
  digitalWrite(12, LOW);
  for(int m = 1022; m < 1023; m++)
  {
   digitalWrite(13, m);
   delay(10);
  }
 }
 else if(jlyu > 235){
  digitalWrite(11, LOW);
  digitalWrite(12, HIGH);
  for(int m = 1022; m < 1023; m++)
  {
   digitalWrite(13, m);
   delay(10);
  }
 }
 else{
  digitalWrite(11, LOW);
  digitalWrite(11, LOW);
 }
}


Go Up