From d69ceb2855e054f87bed9dcb96132c5792d69ede Mon Sep 17 00:00:00 2001 From: James Date: Tue, 15 Sep 2020 10:28:54 +1000 Subject: [PATCH] SOMEONE pushed the wrong file?? --- cockpit_switches.ino | 84 +++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 37 deletions(-) diff --git a/cockpit_switches.ino b/cockpit_switches.ino index 2b9c94b..ade5f47 100644 --- a/cockpit_switches.ino +++ b/cockpit_switches.ino @@ -1,45 +1,55 @@ -#include -char controllerState[8]; -#define I2C_SLAVE_ADDR 0x07 +#include -const long throttle = 100; -long lastSend=0; +#define BUTTONS 16 +#define FAUXBUTTONS 5 -void setup(){ - for (int pinNumber = 0; pinNumber < 14; pinNumber++) { pinMode(pinNumber, INPUT_PULLUP); } -// for (int pinNumber = 14; pinNumber <= 21; pinNumber++) { pinMode(pinNumber, INPUT); } - pinMode(0+14, INPUT); - Wire.begin(); -// Serial.begin(115200); +const long speedLimit = 10; + +unsigned long lastSend = 0; + +int buttonPins[BUTTONS] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, A0, A1, A2, A3 }; +int analogButtonPin = A4; + +EasyTransfer ET; + +struct SEND_DATA_STRUCTURE{ + //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO + int16_t joyx; + int16_t joyy; + int8_t joyz; + int16_t joyxr; + int16_t joyyr; + int8_t joyzr; + uint32_t buttonState; +}; + +SEND_DATA_STRUCTURE controllerState; + +void setup() { + Serial.begin(2000000); + ET.begin(details(controllerState), &Serial); + for (int i = 0; i < BUTTONS; i++) { pinMode(buttonPins[i], INPUT_PULLUP); } + pinMode(analogButtonPin, INPUT); +} + +uint32_t readButtons(){ + uint32_t buttonStateNow = 0; + for (int i=0; i throttle ) { - Wire.beginTransmission(I2C_SLAVE_ADDR); - for (int i=0; i speedLimit ) { + ET.sendData(); lastSend = millis(); } } - -byte readButtons(int numberOfButtonsToRead, int inputNumberOffset){ - byte tempByte = 0; - for (int i=0; i<8; i++){ - if (i < numberOfButtonsToRead) { - tempByte += (digitalRead(i + inputNumberOffset) << i); - } else { - tempByte += (1 << i); - } - } - return ~tempByte; -}