Page 1 of 1

PS2 shield exaples

PostPosted: Wed Apr 15, 2015 3:08 am
by matana21
hi everybody

i'm new here
can somebody please share some of working codes using the ps2?

Re: PS2 shield exaples

PostPosted: Wed Apr 15, 2015 3:06 pm
by KISH
CODE: SELECT_ALL_CODE
//Cytron PS2 Shield (SHIELD-PS2)
//www.cytron.com.my
//sample code to retrieve a btn status on PS2 Controller
 
#include <Shield_PS2.h>

//declare class objects
PS2 ps2=PS2();                    //PS2 class object: ps2

#define LEDPIN 13


void setup()
{
 
   ps2.init(9600, 0, 1);   //initialize the main board to use desired (baudrate, rx, tx)
                           //for Arduino Mega use RX:10, TX: 11 for software serial
                           //for Arduino Leonardo use pin 8, 9, 10, 11 as RX and TX for software serial
                             
                             
   pinMode(LEDPIN, OUTPUT);
   digitalWrite(LEDPIN,LOW);   
     
}

void loop()
{
 
  if( ps2.getval(p_select)==0)      //LED on Main Board will light up if Select button is pressed
  {
    digitalWrite(LEDPIN,HIGH);
  }
  else
  {
    digitalWrite(LEDPIN,LOW);
  }
 
 
 
}