Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.45 KB | None | 0 0
  1. //Slave
  2. //Throttle Handle Pro Mini ATmega328
  3. //12 buttons 2 axis
  4.  
  5. #include <Wire.h>
  6. #include <EasyTransferI2C.h>
  7.  
  8. //create object
  9. EasyTransferI2C ET;
  10.  
  11. struct SEND_DATA_STRUCTURE {
  12.   //put your variable definitions here for the data you want to send
  13.   //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
  14.   int frontButton1;
  15.   int frontButton2;
  16.   int frontButton3;
  17.   int thumbButton1;
  18.   int thumbButton2;
  19.   int thumbButton3;
  20.   int encoderButton;
  21.   int aStickButton;
  22.   int dPadN;
  23.   int dPadE;
  24.   int dPadS;
  25.   int dPadW;
  26.   int aStickHorizontal;
  27.   int aStickVertical;
  28. };
  29.  
  30. //give a name to the group of data
  31. SEND_DATA_STRUCTURE mydata;
  32.  
  33. //define slave i2c address
  34. #define I2C_SLAVE_ADDRESS 9
  35.  
  36. const int frontButton1 = 4;
  37. const int frontButton2 = 1;
  38. const int frontButton3 = 0;
  39. const int thumbButton1 = 8;
  40. const int thumbButton2 = 7;
  41. const int thumbButton3 = 9;
  42. const int encoderButton = 5;
  43. const int aStickButton = 6;
  44. const int dPadN = 10;
  45. const int dPadE = 11;
  46. const int dPadS = 12;
  47. const int dPadW = 14;
  48. const int aStickHorizontal = A2;
  49. const int aStickVertical = A3;
  50.  
  51. void setup() {
  52.   Wire.begin();
  53.   //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
  54.   ET.begin(details(mydata), &Wire);
  55.  
  56.  
  57.   pinMode(frontButton1, INPUT_PULLUP);
  58.   pinMode(frontButton2, INPUT_PULLUP);
  59.   pinMode(frontButton3, INPUT_PULLUP);
  60.   pinMode(thumbButton1, INPUT_PULLUP);
  61.   pinMode(thumbButton2, INPUT_PULLUP);
  62.   pinMode(thumbButton3, INPUT_PULLUP);
  63.   pinMode(encoderButton, INPUT_PULLUP);
  64.   pinMode(aStickButton, INPUT_PULLUP);
  65.   pinMode(dPadN, INPUT_PULLUP);
  66.   pinMode(dPadE, INPUT_PULLUP);
  67.   pinMode(dPadS, INPUT_PULLUP);
  68.   pinMode(dPadW, INPUT_PULLUP);
  69. }
  70.  
  71. void loop() {
  72.   mydata.frontButton1 = digitalRead(frontButton1);
  73.   mydata.frontButton2 = digitalRead(frontButton2);
  74.   mydata.frontButton3 = digitalRead(frontButton3);
  75.   mydata.thumbButton1 = digitalRead(thumbButton1);
  76.   mydata.thumbButton2 = digitalRead(thumbButton2);
  77.   mydata.thumbButton3 = digitalRead(thumbButton3);
  78.   mydata.encoderButton = digitalRead(encoderButton);
  79.   mydata.aStickButton = digitalRead(aStickButton);
  80.   mydata.dPadN = digitalRead(dPadN);
  81.   mydata.dPadE = digitalRead(dPadE);
  82.   mydata.dPadS = digitalRead(dPadS);
  83.   mydata.dPadW = digitalRead(dPadW);
  84.   mydata.aStickHorizontal = analogRead(aStickHorizontal);
  85.   mydata.aStickVertical = analogRead(aStickVertical);
  86.  
  87.   ET.sendData(I2C_SLAVE_ADDRESS);
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement