#include <Arduino.h>
//#include <TinyUSB.h>
const int buttonPins[] = {0, 1, 2, 3, 4, 5, 6, 7};
const int directionPins[] = {8, 9, 10, 11};
const int startPin = 13;
const int selectPin = 12;
void setup() {
Serial.begin(115200);
for (int i = 0; i < 8; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
for (int i = 0; i < 4; i++) {
pinMode(directionPins[i], INPUT_PULLUP);
}
pinMode(startPin, INPUT_PULLUP);
pinMode(selectPin, INPUT_PULLUP);
// TinyUSB Device init
//TinyUSB_Device_Init(0);
}
void loop() {
uint8_t buttons = 0;
for (int i = 0; i < 8; i++) {
if (digitalRead(buttonPins[i]) == LOW) {
buttons |= (1 << i);
}
}
uint8_t dpad = 0;
if (digitalRead(directionPins[0]) == LOW) dpad |= 0x01; // Left
if (digitalRead(directionPins[1]) == LOW) dpad |= 0x02; // Down
if (digitalRead(directionPins[2]) == LOW) dpad |= 0x04; // Right
if (digitalRead(directionPins[3]) == LOW) dpad |= 0x08; // Up
uint8_t startSelect = 0;
if (digitalRead(startPin) == LOW) startSelect |= 0x01;
if (digitalRead(selectPin) == LOW) startSelect |= 0x02;
// Print the states to the serial monitor
Serial.print("Buttons: ");
Serial.print(buttons, BIN);
Serial.print(" | D-Pad: ");
Serial.print(dpad, BIN);
Serial.print(" | Start/Select: ");
Serial.println(startSelect, BIN);
// Create the HID report
uint8_t report[4] = { buttons, dpad, startSelect, 0 };
//TinyUSB_HID_SendReport(0, report, sizeof(report));
delay(100);
}