Hirdetés
- Sokat megélt veterán CPU-t hoz vissza a piacra az Intel
- Androidos fejegységek
- Milyen asztali (teljes vagy fél-) gépet vegyek?
- OLED TV topic
- Intel Core i5 / i7 / i9 "Alder Lake-Raptor Lake/Refresh" (LGA1700)
- TCL LCD és LED TV-k
- Fujifilm X
- Milyen házat vegyek?
- Milyen billentyűzetet vegyek?
- VR topik (Oculus Rift, stb.)
-
PROHARDVER!
Arduino hardverrel és szoftverrel foglakozó téma. Minden mikrovezérlő ami arduinoval programozható, és minden arduino program, board, és hardverrel kapcsolatos kérdések helye.
Új hozzászólás Aktív témák
-
válasz
mardal84 #12854 üzenetére
Szia!
Ha a 9-es gombot helyettesíted húzókapcsolóval, akkor mondjuk így:// 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]) && index == 0 ) { // 0 index = a húzókapcsoló a 9-es pinre kötve
lastButtonState[index] = currentButtonState;
Joystick.setButton(index, 1);
delay(10); // vár 10ms-ot, hogy a program észlelje a gombnyomást
Joystick.setButton(index, 0);
}
else if (currentButtonState != lastButtonState[index]) {
Joystick.setButton(index, currentButtonState);
lastButtonState[index] = currentButtonState;
}
}
delay(50);
}Ha másik gombra szeretnéd, akkor az index == 0 helyett 1,2 stb kell.
A kód azt csinálja, hogy minden húzás után 10ms-ig gombnyomás küld, majd elengedi. Ha ez kevés lenne, növeld a delay(10) értékét.
Új hozzászólás Aktív témák
- HIBÁTLANiPhone XR 128GB Black -1 ÉV GARANCIA - Kártyafüggetlen, MS3267, 96% Akkumulátor
- ÁRGARANCIA!Épített KomPhone i5 14400F 32/64GB RAM RX 9060 XT 8GB GAMER PC termékbeszámítással
- BESZÁMÍTÁS! LENOVO IdeaPad Gaming 3 Gamer notebook - R5 5500H 16GB DDR4 512GB SSD RTX 2050 4GB WIN11
- Bomba ár! Lenovo ThinkPad L490 - i5-G8 I 16GB I 256SSD I 14" FHD Touch I HDMI I Cam I W11 I Gari!
- Bontatlan egérpad Razer Sphex V3 (RZ02-03820100-R3M1
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
Cég: CAMERA-PRO Hungary Kft.
Város: Budapest