Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Slave
- //Throttle Handle Pro Mini ATmega328
- //12 buttons 2 axis
- #include <Wire.h>
- #include <EasyTransferI2C.h>
- //create object
- EasyTransferI2C ET;
- struct SEND_DATA_STRUCTURE {
- //put your variable definitions here for the data you want to send
- //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
- int frontButton1;
- int frontButton2;
- int frontButton3;
- int thumbButton1;
- int thumbButton2;
- int thumbButton3;
- int encoderButton;
- int aStickButton;
- int dPadN;
- int dPadE;
- int dPadS;
- int dPadW;
- int aStickHorizontal;
- int aStickVertical;
- };
- //give a name to the group of data
- SEND_DATA_STRUCTURE mydata;
- //define slave i2c address
- #define I2C_SLAVE_ADDRESS 9
- const int frontButton1 = 4;
- const int frontButton2 = 1;
- const int frontButton3 = 0;
- const int thumbButton1 = 8;
- const int thumbButton2 = 7;
- const int thumbButton3 = 9;
- const int encoderButton = 5;
- const int aStickButton = 6;
- const int dPadN = 10;
- const int dPadE = 11;
- const int dPadS = 12;
- const int dPadW = 14;
- const int aStickHorizontal = A2;
- const int aStickVertical = A3;
- void setup() {
- Wire.begin();
- //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
- ET.begin(details(mydata), &Wire);
- pinMode(frontButton1, INPUT_PULLUP);
- pinMode(frontButton2, INPUT_PULLUP);
- pinMode(frontButton3, INPUT_PULLUP);
- pinMode(thumbButton1, INPUT_PULLUP);
- pinMode(thumbButton2, INPUT_PULLUP);
- pinMode(thumbButton3, INPUT_PULLUP);
- pinMode(encoderButton, INPUT_PULLUP);
- pinMode(aStickButton, INPUT_PULLUP);
- pinMode(dPadN, INPUT_PULLUP);
- pinMode(dPadE, INPUT_PULLUP);
- pinMode(dPadS, INPUT_PULLUP);
- pinMode(dPadW, INPUT_PULLUP);
- }
- void loop() {
- mydata.frontButton1 = digitalRead(frontButton1);
- mydata.frontButton2 = digitalRead(frontButton2);
- mydata.frontButton3 = digitalRead(frontButton3);
- mydata.thumbButton1 = digitalRead(thumbButton1);
- mydata.thumbButton2 = digitalRead(thumbButton2);
- mydata.thumbButton3 = digitalRead(thumbButton3);
- mydata.encoderButton = digitalRead(encoderButton);
- mydata.aStickButton = digitalRead(aStickButton);
- mydata.dPadN = digitalRead(dPadN);
- mydata.dPadE = digitalRead(dPadE);
- mydata.dPadS = digitalRead(dPadS);
- mydata.dPadW = digitalRead(dPadW);
- mydata.aStickHorizontal = analogRead(aStickHorizontal);
- mydata.aStickVertical = analogRead(aStickVertical);
- ET.sendData(I2C_SLAVE_ADDRESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement