Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
hey MadSci,i'm sure Aduino code will be useful to some people but do you know WebbotLib does PS2 controllers now?
(PS. http://www.billporter.info/wp-content/uploads//2010/05/PSX_example.zip is just an empty file.)
could you please post a list of what colour wire connect to what pin of the arduino
PS2PACKET g_ps2p;PS2PACKET g_ps2pPrev;...if (PS2_Query(g_ps2p.bData, sizeof(g_ps2p))) // do the query{ if (!g_ps2p.s.fNStart && g_ps2pPrev.s.fNStart) { ... }... g_ps2pPrev = g_ps2p; // Save the old state away...}
if (psx.NewButtonState()) { if(psx.Button(PSB_SELECT)) Serial.print("Select\n"); if(psx.Button(PSB_L3)) Serial.print("L3\n"); if(psx.Button(PSB_R3)) Serial.print("R3\n"); if(psx.Button(PSB_START)) Serial.print("Start\n"); if(psx.Button(PSB_PAD_UP)) Serial.print("Up\n"); if(psx.Button(PSB_PAD_RIGHT)) Serial.print("Right\n"); if(psx.Button(PSB_PAD_LEFT)) Serial.print("LEFT\n"); if(psx.Button(PSB_PAD_DOWN)) Serial.print("DOWN\n"); if(psx.Button(PSB_L1)) Serial.print("L1\n"); if(psx.Button(PSB_R1)) Serial.print("R1\n"); if(psx.Button(PSB_L2)) Serial.print("L2\n"); if(psx.Button(PSB_R2)) Serial.print("R2\n"); if(psx.Button(PSB_GREEN)) Serial.print("Triangle\n"); if(psx.Button(PSB_RED)) Serial.print("Circle\n"); if(psx.Button(PSB_PINK)) Serial.print("Square\n"); if(psx.Button(PSB_BLUE)) Serial.print("X\n"); }
boolean PS2_Query(unsigned char *paData, int cb){ int iLoopCnt; unsigned char bMode; // Hack to not have this loop forever in case of error for (iLoopCnt = 0; iLoopCnt < 10; iLoopCnt++) { //spiDeviceSelect(PS2_device, TRUE); pin_low(PS2_SEL); // shiftout CMD,CLK,FASTLSBPRE,[$1\8] gameByte(0x1); //shiftin DAT,CLK,FASTLSBPOST,[DS2Mode\8] bMode = gameByte(0x42); if ((bMode & 0xf0) == 0x70) { // we are in an analog mode so continue to read in the extra bytes. gameByte(0); // ignore first byte which should return 0x5a while (cb > 0) { *paData++ = gameByte(0); cb--; } // And clear our select line... pin_high(PS2_SEL); return TRUE; } pin_high(PS2_SEL); clockWaitms(1); pin_low(PS2_SEL); // Not initialized properly, try to send out the correct init sequences. pin_low(PS2_SEL);// shiftout CMD,CLK,FASTLSBPRE,[$1\8,$43\8,$0\8,$1\8,$0\8] ;CONFIG_MODE_ENTER static unsigned char _aps2_2a[] = {0x01, 0x43, 0x0, 0x1, 0x0}; _PS2_ShiftOut(_aps2_2a, sizeof(_aps2_2a)); pin_high(PS2_SEL); clockWaitms(1); pin_low(PS2_SEL);// shiftout CMD,CLK,FASTLSBPRE,[$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] ;SET_MODE_AND_LOCK static unsigned char _aps2_3[] = {0x01, 0x44, 0, 1, 3, 0, 0, 0, 0}; _PS2_ShiftOut(_aps2_3, sizeof(_aps2_3)); pin_high(PS2_SEL); clockWaitms(1); pin_low(PS2_SEL);// shiftout CMD,CLK,FASTLSBPRE,[$01\8,$43\8,$00\8,$00\8,$5A\8,$5A\8,$5A\8,$5A\8,$5A\8] ;CONFIG_MODE_EXIT_DS2_NATIVE static unsigned char _aps2_5[] = {0x01, 0x43, 0, 0, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a}; _PS2_ShiftOut(_aps2_5, sizeof(_aps2_5)); pin_high(PS2_SEL);// clockWaitms(1); } // If we got here it means that we tried a number of times and it failed, so set up a set of default values and return. paData[0] = 255; paData[1] = 255; paData[2] = 128; paData[3] = 128; paData[4] = 128; paData[5] = 128; return FALSE;}