r/arduino • • 11h ago

Beginner's Project Pro micro button box

Post image

Hey all, looking for a bit of help and direction. Making a button box for sim racing. Pretty basic and just emulates ignition wipers lights.
- it has 4 toggles and 1 button all led and using vcc on the board for power

- The left most toggle controls the button. Meaning when it is off the button is off. When on ignition turns on. Then pressing the button will start the car.

- the other toggles will be off or on. And just be used to control lights or wipers in the game.

As the game uses key presses I’m unsure if I should be using the keyboard library or joystick library.

Can someone help point me in the right direction on the correct way to go library wise, maybe a basic toggle example

7 Upvotes

2 comments sorted by

3

u/PerFromArduino Arduino Staff 10h ago

As the game uses key presses I’m unsure if I should be using the keyboard library or joystick library.

It sounds like the Keyboard library is what you want.

maybe a basic toggle example

Here you go:

#include <Keyboard.h> // See: https://docs.arduino.cc/language-reference/en/functions/usb/Keyboard/

const byte wiperPin = 4;
const unsigned int debounceDuration = 100;  // See: https://learn.adafruit.com/make-it-switch/debouncing

byte previousWiperPinState = LOW;
unsigned long debounceTimestamp = 0;

void setup() {
  Keyboard.begin();
  pinMode(wiperPin, INPUT_PULLUP);
}

void loop() {
  byte wiperPinState = digitalRead(wiperPin);
  if (wiperPinState != previousWiperPinState && millis() - debounceTimestamp >= debounceDuration) {
    debounceTimestamp = millis();
    previousWiperPinState = wiperPinState;

    if (wiperPinState == HIGH) {
      Keyboard.write('w');
    } else {
      Keyboard.write('s');
    }
  }
}

2

u/antek_g_animations I like creating stuff with arduino 10h ago

Check out r/AskElectronics wiki general schematic diagram guidelines https://www.reddit.com/r/AskElectronics/s/YHat4dHPS4 . It's a really useful skill that will make your diagrams more readable and easier for people to help you