alter_Bekannter
N.A.C.J.A.C.
Exakt dieser:
Code alt:
Einrückung ist anders als im Original weil ich die Klammern und die Schreibweisen alle in Notepad++ überprüft habe.
Da bewim ersten Zugriff auf die Klasse kein Fehler auftritt und doch alles im sleben Sichtbarkeitsbereich liegt also in im Verhältnis verstehe ich das Problem nicht.
Neuer Code der funktioniert:
[src=cpp]/************************************************************************************
* NESPi NES Controller USB Gamepad v0.1 [mike.g|june2016] *
* [daftmike.com] *
*************************************************************************************/
// Adapted from 'JoystickButton' example
// by Matthew Heironimus
// 2015-11-20
// https://github.com/MHeironimus/ArduinoJoystickLibrary
#include <Joystick.h>
Joystick_ Joystick;
void setup() {
for (int i = 2; i < 10; i++)
{
pinMode(i, INPUT_PULLUP); // set pullups on pins 2-9 for the buttons
}
Joystick.begin(); // initialise Joystick library
}
const int pinToButtonMap = 2; // start from pin 2
int lastButtonState[8] = {0, 0, 0, 0, 0, 0, 0, 0}; // last state of the button
void loop() {
for (int index = 0; index < 8; index++) // go through the loop 8 times, once for each button
{
int currentButtonState = !digitalRead(index + pinToButtonMap); // read the pin and store in variable
if (currentButtonState != lastButtonState[index]) // if the button state has changed
{
Joystick.setButton(index, currentButtonState); // write the button state to the joystick
lastButtonState[index] = currentButtonState; // save state to compare for the next loop
}
}
delay(50);
}[/src]
Code alt:
https://de.aliexpress.com/item/Mini...ule-For-Arduino-Best-Quality/32284746884.html
Man, das Teil ist wirklich winzig, man neigt dazu zu vergessen wie klein eine micro USB Buchse ist wenn man die Bilder sieht...
Folgender Code verursacht die Beschwerde das JHoystick in dem Kontext nicht existiert: (Zeile 20: 'Joystick' was not declared in this scope)
[src=cpp]#include <Joystick.h>
void setup() {
for (int i = 2; i < 10; i++)
{
pinMode(i, INPUT_PULLUP); // set pullups on pins 2-9 for the buttons
}
Joystick.begin(); // initialise Joystick library
}
const int pinToButtonMap = 2; // start from pin 2
int lastButtonState[8] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; // last state of the button
void loop() {
for (int index = 0; index < 8; index++) // go through the loop 8 times, once for each button
{
int currentButtonState = !digitalRead(index + pinToButtonMap); // read the pin and store in variable
if (currentButtonState != lastButtonState[index]) // if the button state has changed
{
Joystick.setButton(index, currentButtonState); // write the button state to the joystick <= hier
lastButtonState[index] = currentButtonState; // save state to compare for the next loop
}
}
delay(50);
}[/src]
Man, das Teil ist wirklich winzig, man neigt dazu zu vergessen wie klein eine micro USB Buchse ist wenn man die Bilder sieht...
Folgender Code verursacht die Beschwerde das JHoystick in dem Kontext nicht existiert: (Zeile 20: 'Joystick' was not declared in this scope)
[src=cpp]#include <Joystick.h>
void setup() {
for (int i = 2; i < 10; i++)
{
pinMode(i, INPUT_PULLUP); // set pullups on pins 2-9 for the buttons
}
Joystick.begin(); // initialise Joystick library
}
const int pinToButtonMap = 2; // start from pin 2
int lastButtonState[8] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; // last state of the button
void loop() {
for (int index = 0; index < 8; index++) // go through the loop 8 times, once for each button
{
int currentButtonState = !digitalRead(index + pinToButtonMap); // read the pin and store in variable
if (currentButtonState != lastButtonState[index]) // if the button state has changed
{
Joystick.setButton(index, currentButtonState); // write the button state to the joystick <= hier
lastButtonState[index] = currentButtonState; // save state to compare for the next loop
}
}
delay(50);
}[/src]
Einrückung ist anders als im Original weil ich die Klammern und die Schreibweisen alle in Notepad++ überprüft habe.
Da bewim ersten Zugriff auf die Klasse kein Fehler auftritt und doch alles im sleben Sichtbarkeitsbereich liegt also in im Verhältnis verstehe ich das Problem nicht.
Neuer Code der funktioniert:
[src=cpp]/************************************************************************************
* NESPi NES Controller USB Gamepad v0.1 [mike.g|june2016] *
* [daftmike.com] *
*************************************************************************************/
// Adapted from 'JoystickButton' example
// by Matthew Heironimus
// 2015-11-20
// https://github.com/MHeironimus/ArduinoJoystickLibrary
#include <Joystick.h>
Joystick_ Joystick;
void setup() {
for (int i = 2; i < 10; i++)
{
pinMode(i, INPUT_PULLUP); // set pullups on pins 2-9 for the buttons
}
Joystick.begin(); // initialise Joystick library
}
const int pinToButtonMap = 2; // start from pin 2
int lastButtonState[8] = {0, 0, 0, 0, 0, 0, 0, 0}; // last state of the button
void loop() {
for (int index = 0; index < 8; index++) // go through the loop 8 times, once for each button
{
int currentButtonState = !digitalRead(index + pinToButtonMap); // read the pin and store in variable
if (currentButtonState != lastButtonState[index]) // if the button state has changed
{
Joystick.setButton(index, currentButtonState); // write the button state to the joystick
lastButtonState[index] = currentButtonState; // save state to compare for the next loop
}
}
delay(50);
}[/src]
Zuletzt bearbeitet: