I really think I messed this one up. I trying to create a controller which is similar to a button box in a way. I have a couple questions.
-
Should I have the "buttons" connected to a ground or is my schematic feasible?
-
Where should I start with the code?
I have generic codes written and only one button will work and it just flashes the rest.
I keep getting the error "did you mean _joystick and there is no such value as joystick set button" and I'm not sure where to really start. -
How do you read the address on the hardware pins? Is there a guide or some format to follow and understand?
-
How do you tell the address of the hardware address pins? For example if A0 is ground and A1 is power, how do you know that the address would be 0x25.
-
Where should I start with my code and was that a good start that I posted?
-
Does the reset pin need a resistor as I would like to get rid of it? (very hard to CNC this design)
-
My hat switch is pretty much multiple buttons in one. Should I connect the COMM pin to GND or PWR? Basically would I connect the MCP23S08 to Power, then set the power to COMM GND, so it technically shorts the pin I am selecting?
#include <Adafruit_MCP23S08.h>
#include <Joystick.h>
// Create an instance of the MCP23S08 class
Adafruit_MCP23S08 mcp;
// Create an instance of the Joystick_ object
Joystick_ Joystick;
// Button pin mappings
const int buttonPins[8] = {2, 3, 4, 5, 6, 7, 8, 9};
void setup() {
// Initialize the MCP23S08
mcp.begin();
for (int i = 0; i < 8; i++) {
mcp.pinMode(buttonPins[i], INPUT_PULLUP); // Enable internal pull-up resistors
}
// Initialize the Joystick library
Joystick.begin();
// Initialize the serial communication
Serial.begin(9600);
}
void loop() {
// Read the state of the buttons
for (int i = 0; i < 8; i++) {
int buttonState = mcp.digitalRead(buttonPins[i]);
Joystick.setButton(i, !buttonState);
}
// Send joystick state
Joystick.sendState();
delay(50); // Delay for debounce
}