#include #include //for v1.6 #include "LPD8806.h" #include "SPI.h" PS2X ps2x; // create PS2 Controller Class //right now, the library does NOT support hot pluggable controllers, meaning //you must always either restart your Arduino after you conect the controller, //or call config_gamepad(pins) again after connecting the controller. int error = 0; byte type = 0; byte vibrate = 0; byte ON = 255; //full on for a color byte OFF = 0; //full off for no light //create object EasyTransfer ET; struct SEND_DATA_STRUCTURE{ //put your variable definitions here for the data you want to send //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO byte BOX1[23]; //24 bytes to assign R,G,B values to LEDs byte BOX2[23]; //8 boxes of 8 windows, each window has 3 bytes, one for R, G & B byte BOX3[23]; byte BOX4[23]; byte BOX5[23]; byte BOX6[23]; byte BOX7[23]; byte BOX8[23]; }; //give a name to the group of data SEND_DATA_STRUCTURE mydata; void setup(){ Serial.begin(115200); error = ps2x.config_gamepad(5,7,6,4, false, false); //setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error if(error == 0){ Serial.println("Found Controller, configured successful"); Serial.println("Try out all the buttons, X will vibrate the controller, faster as you press harder;"); Serial.println("holding L1 or R1 will print out the analog stick values."); Serial.println("Go to www.billporter.info for updates and to report bugs."); } else if(error == 1) Serial.println("No controller found, check wiring, see readme.txt to enable debug. visit www.billporter.info for troubleshooting tips"); else if(error == 2) Serial.println("Controller found but not accepting commands. see readme.txt to enable debug. Visit www.billporter.info for troubleshooting tips"); else if(error == 3) Serial.println("Controller refusing to enter Pressures mode, may not support it. "); //Serial.print(ps2x.Analog(1), HEX); type = ps2x.readType(); switch(type) { case 0: Serial.println("Unknown Controller type"); break; case 1: Serial.println("DualShock Controller Found"); break; case 2: Serial.println("GuitarHero Controller Found"); break; }//END PSX SETUP //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc. ET.begin(details(mydata), &Serial); pinMode(13, OUTPUT); randomSeed(analogRead(0)); } void loop(){ ps2x.read_gamepad(); //read controller if(ps2x.NewButtonState(PSB_BLUE)) //will be TRUE if button was JUST pressed OR released { for(int i = 0; i< 24; i++){ //Changes BOX 1 Array to 255 (on) aka white mydata.BOX1[i]=ON; //Set data in EasyTransfer Struct } } if(ps2x.ButtonPressed(PSB_RED)) //will be TRUE if button was JUST pressed OR released { for(int i = 0; i< 24; i++){ //Changes BOX 1 Array to 0 (off) aka black mydata.BOX1[i]=OFF; //Set data in EasyTransfer Struct } } //this is how you access the variables. [name of the group].[variable name] //mydata.pause = 1; //send the data ET.sendData(); //Updates the data to other arduino slaves via EasyTransfer delay(200); //wait longer than slaves check data to allow time for slaves to receive }