Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- int rx1 = 0; //throttle
- int rx2 = 0; //aileron
- int rx3 = 0; //elevation
- int rx4 = 0; //rudder
- int rx5 = 0; //AUX
- int rx6 = 0; //Trainer
- /*
- long bytesToInteger(byte b[4]) { //This is the formula for conversion
- long val = 0; //from INT to BYTE array
- val = ((long )b[0]) << 24; //
- val |= ((long )b[1]) << 16; //
- val |= ((long )b[2]) << 8; //
- val |= b[3]; //
- return val; //
- }
- */
- void expansionReceive(int howMany)
- {
- int port = Wire.read(); // receive byte as an integer
- int value = Wire.read(); // receives the byte with the value
- // digitalWrite(port,value); // sets the pin to the desired value
- }
- void setup()
- {
- Wire.begin(2); //Join I2C bus with address #2
- Wire.onReceive(expansionReceive); //Register event
- Serial.begin(115200);
- }
- void loop()
- {
- rx1 = digitalRead(14);
- rx2 = digitalRead(15);
- rx3 = digitalRead(16);
- rx4 = digitalRead(17);
- rx5 = digitalRead(18);
- rx6 = digitalRead(19);
- Serial.print(rx1);
- Serial.print("\t");
- Serial.print(rx2);
- Serial.print("\t");
- Serial.print(rx3);
- Serial.print("\t");
- Serial.print(rx4);
- Serial.print("\t");
- Serial.print(rx5);
- Serial.print("\t");
- Serial.print(rx6);
- Serial.print("\t");
- Serial.println("\t");
- }
- /*
- long d = bytesToInteger(b); //This is the in-code portion
- Serial.println(d); //
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement