From 9bcc3aecc0d04c894f11ca0cb2e3987887377703 Mon Sep 17 00:00:00 2001 From: James Wood Date: Tue, 15 Sep 2020 10:27:21 +1000 Subject: [PATCH] first commit --- cockpit_switches.ino | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 cockpit_switches.ino diff --git a/cockpit_switches.ino b/cockpit_switches.ino new file mode 100644 index 0000000..2b9c94b --- /dev/null +++ b/cockpit_switches.ino @@ -0,0 +1,45 @@ +#include +char controllerState[8]; +#define I2C_SLAVE_ADDR 0x07 + +const long throttle = 100; +long lastSend=0; + +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); +} + +void loop(){ + controllerState[0] = map(analogRead(14), 0, 1023, 0, 255); + controllerState[1] = 128; //map(analogRead(15), 0, 1023, 0, 255); + controllerState[2] = 128; //map(analogRead(16), 0, 1023, 0, 255); + controllerState[3] = 128; //map(analogRead(17), 0, 1023, 0, 255); + controllerState[4] = 128; //map(analogRead(20), 0, 1023, 0, 255); + controllerState[5] = 128; //map(analogRead(21), 0, 1023, 0, 255); + controllerState[6] = readButtons(8, 0); + controllerState[7] = readButtons(6, 8); + if ((millis() - lastSend) > throttle ) { + Wire.beginTransmission(I2C_SLAVE_ADDR); + for (int i=0; i