Created
April 14, 2018 00:23
-
-
Save uXeBoy/12280d8fd5af1d327177abeed53aaf16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "PS3USB.h" | |
// Satisfy the IDE, which needs to see the include statment in the ino too. | |
#ifdef dobogusinclude | |
#include <SPI.h> | |
#endif | |
USB Usb; | |
PS3USB PS3(&Usb); | |
const byte bitMask[] = {1, 2, 4, 8, 16, 32, 64, 128}; | |
void setup() | |
{ | |
pinMode(A0, OUTPUT); // Up | |
pinMode(A1, OUTPUT); // Right | |
pinMode(A2, OUTPUT); // Left | |
pinMode(A3, OUTPUT); // Down | |
pinMode(A4, OUTPUT); // A (X) | |
pinMode(A5, OUTPUT); // B (0) | |
// set OUTPUT pins HIGH | |
PORTC |= B00111111; | |
Serial.begin(115200); | |
#if !defined(__MIPSEL__) | |
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection | |
#endif | |
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) { | |
if (PS3.getButtonPress(UP)) | |
PORTC &= ~bitMask[0]; | |
else | |
PORTC |= bitMask[0]; | |
if (PS3.getButtonPress(RIGHT)) | |
PORTC &= ~bitMask[1]; | |
else | |
PORTC |= bitMask[1]; | |
if (PS3.getButtonPress(LEFT)) | |
PORTC &= ~bitMask[2]; | |
else | |
PORTC |= bitMask[2]; | |
if (PS3.getButtonPress(DOWN)) | |
PORTC &= ~bitMask[3]; | |
else | |
PORTC |= bitMask[3]; | |
if (PS3.getButtonPress(CROSS)) // A | |
PORTC &= ~bitMask[4]; | |
else | |
PORTC |= bitMask[4]; | |
if (PS3.getButtonPress(CIRCLE)) // B | |
PORTC &= ~bitMask[5]; | |
else | |
PORTC |= bitMask[5]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment