Hallo zusammen,
ich würde gerne meinem Sohn eine Handbremse für sein LKW-Spiel machen.
Die "Hardware" habe ich schon gebaut. Mit einem Mikroschalter darin.
Ein Arduino Leonardo R3 habe ich schon für die Gangschaltung in Gebrauch.
Im Internet hatte ich mal eine Programmierung für einen Joystick gefunden die jetzt darauf läuft.
In der Programmierung ist noch ein Anschluss (Pin 9) frei. Da soll die Bremse dran.
Nun ist das Problem, dass man den Hebel nochmal ziehen muss um die Bremse zu lösen.
Es soll aber so sein, dass man den Schalter drückt und die Bremse geht zu. Lässt man den Schalter dann wieder los soll die Bremse auf gehn.
Im Spiel geht das über die Leertaste. Einmal drücken die Bremse geht zu und nochmal drücken und die Bremse löst sich wieder.
Ist sowas machbar und wenn ja, könnte mir das jemand netterweise machen?
Ich hab von sowas leider keine Ahnung.
Schönen Sonntag noch...
Miracolix
Das ist die Programmierung, die ich aus dem Internet habe.
// Simple example application that shows how to read four Arduino
// digital pins and map them to the USB Joystick library.
//
// Ground digital pins 9, 10, 11, and 12 to press the joystick
// buttons 0, 1, 2, and 3.
//
// NOTE: This sketch file is for use with Arduino Leonardo and
// Arduino Micro only.
//
// by Matthew Heironimus
// 2015-11-20
//--------------------------------------------------------------------
#include <Joystick.h>
Joystick_ Joystick;
void setup() {
// Initialize Button Pins
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
// Initialize Joystick Library
Joystick.begin();
}
// Constant that maps the phyical pin to the joystick button.
const int pinToButtonMap = 9;
// Last state of the button
int lastButtonState[4] = {0,0,0,0};
void loop() {
// Read pin values
for (int index = 0; index < 4; index++)
{
int currentButtonState = !digitalRead(index + pinToButtonMap);
if (currentButtonState != lastButtonState[index])
{
Joystick.setButton(index, currentButtonState);
lastButtonState[index] = currentButtonState;
}
}
delay(50);
}