Advertisement
tommasta

Arduino I2C Port Replicator Slave **Not working**

Apr 15th, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <Wire.h>
  2. int rx1 = 0;  //throttle
  3. int rx2 = 0;  //aileron
  4. int rx3 = 0;  //elevation
  5. int rx4 = 0;  //rudder
  6. int rx5 = 0;  //AUX
  7. int rx6 = 0;  //Trainer
  8.  
  9. /*
  10. long bytesToInteger(byte b[4]) {    //This is the formula for conversion
  11.   long val = 0;                     //from INT to BYTE array
  12.   val = ((long )b[0]) << 24;        //
  13.   val |= ((long )b[1]) << 16;       //
  14.   val |= ((long )b[2]) << 8;        //
  15.   val |= b[3];                      //
  16.   return val;                       //
  17. }
  18. */
  19.  
  20. void expansionReceive(int howMany)
  21. {
  22.   int port = Wire.read();    // receive byte as an integer
  23.   int value = Wire.read();   // receives the byte with the value
  24. //  digitalWrite(port,value);         // sets the pin to the desired value
  25. }
  26.  
  27.  
  28.  
  29. void setup()
  30. {
  31.   Wire.begin(2);                //Join I2C bus with address #2
  32.   Wire.onReceive(expansionReceive); //Register event
  33.   Serial.begin(115200);
  34. }
  35.  
  36.  
  37. void loop()
  38. {
  39.     rx1 = digitalRead(14);
  40.     rx2 = digitalRead(15);
  41.     rx3 = digitalRead(16);
  42.     rx4 = digitalRead(17);
  43.     rx5 = digitalRead(18);
  44.     rx6 = digitalRead(19);
  45.     Serial.print(rx1);
  46.     Serial.print("\t");
  47.     Serial.print(rx2);
  48.     Serial.print("\t");
  49.     Serial.print(rx3);
  50.     Serial.print("\t");
  51.     Serial.print(rx4);
  52.     Serial.print("\t");
  53.     Serial.print(rx5);
  54.     Serial.print("\t");
  55.     Serial.print(rx6);
  56.     Serial.print("\t");
  57.     Serial.println("\t");
  58. }
  59.  
  60.  
  61. /*
  62.  
  63.   long d = bytesToInteger(b);      //This is the in-code portion
  64.   Serial.println(d);               //
  65. }
  66.  
  67. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement