So I'm trying to wire one Toggle swich like the below to 2 LED's, one green another yellow.
I want like position1 turn on LED1 and position2 turn on LED2. the midlle position is of course both off
I'm using an arduino pro micro and the switch will work with joystick library by MHeironimus.
the code i have is this and work without LED's.
#include <Joystick.h>
//Buttons
#define button1 8
#define button2 9
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD,
2, 0, // Button Count, Hat Switch Count
false, false, false, // X and Y, but no Z Axis
false, false, false, // No Rx, Ry, or Rz
false, false, // No rudder or throttle
false, false, false); // No accelerator, brake, or steering
void setup() {
// Initialize Button Pins
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
Joystick.begin(false);
}
void loop() {
if (digitalRead(button1) == 0) Joystick.pressButton(0);
if (digitalRead(button2) == 0) Joystick.pressButton(1);
Joystick.sendState();//send state 1st before we clear the button states
ClearButtons();
}
void ClearButtons()
{
Joystick.releaseButton(0);
Joystick.releaseButton(1);
}