Working version. Tested on linux PC.
This commit is contained in:
9
src/defines.h
Normal file
9
src/defines.h
Normal file
@ -0,0 +1,9 @@
|
||||
//Define pins used for each gear
|
||||
#define GEAR1 1
|
||||
#define GEAR2 2
|
||||
#define GEAR3 3
|
||||
#define GEAR4 4
|
||||
#define GEAR5 5
|
||||
#define GEAR6 6
|
||||
|
||||
#define NUM_BUTTONS 6
|
43
src/main.cpp
43
src/main.cpp
@ -1,18 +1,41 @@
|
||||
#include <Arduino.h>
|
||||
#include "defines.h"
|
||||
|
||||
// put function declarations here:
|
||||
int myFunction(int, int);
|
||||
#include <Arduino.h>
|
||||
#include <arduino-timer.h>
|
||||
#include <Bounce2.h>
|
||||
#include <usb_joystick.h>
|
||||
|
||||
Timer<1, micros> TxTimer;
|
||||
Bounce2::Button * buttons = new Bounce2::Button[NUM_BUTTONS];
|
||||
const uint8_t BUTTON_PINS[NUM_BUTTONS] = {GEAR1, GEAR2, GEAR3, GEAR4, GEAR5, GEAR6};
|
||||
|
||||
bool TxJoystick(void *) {
|
||||
Joystick.send_now();
|
||||
return true;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
int result = myFunction(2, 3);
|
||||
//Enable manual send of joystick packets
|
||||
Joystick.useManualSend(true);
|
||||
|
||||
//Attach buttons to debounce library. pullup, pressed state is low
|
||||
for (int i = 0; i < NUM_BUTTONS; i++) {
|
||||
buttons[i].attach( BUTTON_PINS[i] , INPUT_PULLUP ); //setup the bounce instance for the current button
|
||||
buttons[i].interval(5); // interval in ms
|
||||
buttons[i].setPressedState(LOW);
|
||||
}
|
||||
|
||||
TxTimer.every(1000, TxJoystick);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
}
|
||||
//Read buttons and update joystick state.
|
||||
for (int i = 0; i < NUM_BUTTONS; i++) {
|
||||
buttons[i].update();
|
||||
Joystick.button(i+1, buttons[i].isPressed());
|
||||
}
|
||||
|
||||
//Transmit USB packet
|
||||
TxTimer.tick();
|
||||
|
||||
// put function definitions here:
|
||||
int myFunction(int x, int y) {
|
||||
return x + y;
|
||||
}
|
||||
|
Reference in New Issue
Block a user