Working version. Tested on linux PC.
This commit is contained in:
		@@ -12,4 +12,7 @@
 | 
				
			|||||||
platform = teensy
 | 
					platform = teensy
 | 
				
			||||||
board = teensy40
 | 
					board = teensy40
 | 
				
			||||||
framework = arduino
 | 
					framework = arduino
 | 
				
			||||||
build_flags = -D USB_FLIGHTSIM_JOYSTICK
 | 
					build_flags = -D USB_HID
 | 
				
			||||||
 | 
					lib_deps = 
 | 
				
			||||||
 | 
						contrem/arduino-timer@^3.0.1
 | 
				
			||||||
 | 
						thomasfredericks/Bounce2@^2.72
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										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:
 | 
					#include <Arduino.h>
 | 
				
			||||||
int myFunction(int, int);
 | 
					#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() {
 | 
					void setup() {
 | 
				
			||||||
  // put your setup code here, to run once:
 | 
					  //Enable manual send of joystick packets
 | 
				
			||||||
  int result = myFunction(2, 3);
 | 
					  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() {
 | 
					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