0% found this document useful (0 votes)
3 views2 pages

Game

The document outlines the code for handling a PS3 gamepad, initializing button states, and reading sensor values from touch pins. It compares current sensor values to calibrated untouched values to determine which buttons are pressed and displays this information via serial output. Finally, it serializes the gamepad data for transmission to a host device and includes a delay to manage output speed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Game

The document outlines the code for handling a PS3 gamepad, initializing button states, and reading sensor values from touch pins. It compares current sensor values to calibrated untouched values to determine which buttons are pressed and displays this information via serial output. Finally, it serializes the gamepad data for transmission to a host device and includes a delay to manage output speed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

else{

Serial.println("Mando en modo PS3 lanzado.");

PSGamepadReleaseAllButtons(&psGamepad);

// Inicializamos todos los botones a NO pulsados


for (int i = 0; i < PsRESERVED_LAST_BUTTON_UNUSED; i++) {
psGamepad.buttonsPressed[i] = PsNOT_PRESSED;
}

int psCurrentValues[PsRESERVED_LAST_BUTTON_UNUSED] = {0};

// Leer valores de sensores


psCurrentValues[CROSS] = touchRead(CROSS_TOUCH_PIN);
psCurrentValues[CIRCLE] = touchRead(CIRCLE_TOUCH_PIN);
psCurrentValues[SQUARE] = touchRead(SQUARE_TOUCH_PIN);
psCurrentValues[TRIANGLE] = touchRead(TRIANGLE_TOUCH_PIN);
psCurrentValues[L1] = touchRead(L1_TOUCH_PIN);
psCurrentValues[R1] = touchRead(R1_TOUCH_PIN);
psCurrentValues[L2] = touchRead(L2_TOUCH_PIN);
psCurrentValues[R2] = touchRead(R2_TOUCH_PIN);
psCurrentValues[PS_BUTTON] = touchRead(PLUS_TOUCH_PIN);
psCurrentValues[SELECT] = touchRead(SELECT_TOUCH_PIN);
psCurrentValues[START] = touchRead(START_TOUCH_PIN);
psCurrentValues[PsLEFT_STICK] = touchRead(LEFT_TOUCH_PIN);
psCurrentValues[PsRIGHT_STICK] = touchRead(RIGHT_TOUCH_PIN);
psCurrentValues[PsUP] = touchRead(UP_TOUCH_PIN);
psCurrentValues[PsDOWN] = touchRead(DOWN_TOUCH_PIN);
psCurrentValues[PsLEFT] = touchRead(LEFT_TOUCH_PIN);
psCurrentValues[PsRIGHT] = touchRead(RIGHT_TOUCH_PIN);

// Comparar valores actuales con los valores sin pulsar (calibrados)


for (int i = 0; i < PsRESERVED_LAST_BUTTON_UNUSED; i++) {
// Aplicamos el factor de reducción y comprobamos si el valor es
significativamente mayor
if (psCurrentValues[i] > psGamepad.buttonsUntouchedValues[i] *
TOUCHED_THRESHOLD_FACTOR) {
psGamepad.buttonsPressed[i] = PsPRESSED;
} else {
psGamepad.buttonsPressed[i] = PsNOT_PRESSED;
}
}

// Mostrar estado de los botones en el puerto serie


Serial.print("PS3 Botones pulsados: ");
for (int i = 0; i < PsRESERVED_LAST_BUTTON_UNUSED; i++) {
if (psGamepad.buttonsPressed[i] == PRESSED) {
Serial.print(psButtonNames[i]); // Imprime el nombre del botón pulsado
Serial.print(" ");
}
}
Serial.println();

// Enviamos los datos al anfitrion (consola, PC...)


// Serializamos los datos contenidos en nsGamepad para su envio
PSProtocolSerializePSGamepadData (psGamepad, psBuffer);

// Enviamos el contenido del buffer


esp32USB.write (PS_GAMEPAD_REPORT_SIZE, psBuffer);

// Delay para evitar que la salida sea demasiado rápida


delay(750);

You might also like