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
- void integerToBytes(long val, byte b[4]) { //This is the formula for conversion
- b[0] = (byte )((val >> 24) & 0xff); //from BYTE array to INT
- b[1] = (byte )((val >> 16) & 0xff); //
- b[2] = (byte )((val >> 8) & 0xff); //
- b[3] = (byte )(val & 0xff); //
- }
- void expansionWrite(int pin, int value)
- {
- //pin = pin-100; substracts 100 to it maps to the real ports on the expansion arduino
- Wire.beginTransmission(2); //Transmit to device #2
- Wire.write(pin); //Sends one byte stating the pin to be addressed
- Wire.write((int)value); //Sends the value to be transmitted to the pin selected
- Wire.endTransmission(); //Stop transmitting
- }
- void setup()
- {
- Serial.begin(115200); //Open the serial port at 115200bps
- Wire.begin(); //Join I2C bus (no address for master)
- }
- void loop()
- {
- rx1 = pulseIn(2,HIGH,20000);
- rx2 = pulseIn(3,HIGH,20000);
- rx3 = pulseIn(4,HIGH,20000);
- rx4 = pulseIn(5,HIGH,20000);
- rx5 = pulseIn(6,HIGH,20000);
- rx6 = pulseIn(7,HIGH,20000);
- 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");
- {
- expansionWrite(14, rx1); //Whenever you want to write to the
- expansionWrite(15, rx2); //other Arduino just go with something
- expansionWrite(16, rx3); //like expansionWrite(102,HIGH);
- expansionWrite(17, rx4); // That will -for example- set the pin 2
- expansionWrite(18, rx5); //on the second arduino to high. I used
- expansionWrite(19, rx6); //the 102 nomenclature only to differentiate
- //the two boards. It makes it easier and
- //avoids confusion. You will see how the
- //exceeding 100 is substracted when the time comes.
- }
- }
- /*
- byte b[4];
- integerToBytes(1056964608, b); //This is the in-code portion
- for (int i=0; i<4; ++i) { //
- Serial.println((int )b[i]); //
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement