Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*I haven't gotten around to properly commenting this yet. If I don't soon, yell at me. This code takes pulseIn input values and translates them into single-byte characters for easy transfer over I2C.*/
- #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
- char bx1 = 0;
- char bx2 = 0;
- char bx3 = 0;
- char bx4 = 0;
- char bx5 = 0;
- char bx6 = 0;
- 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);
- rx1 = constrain (rx1, 1001, 2000);
- rx1 = map(rx1, 1100, 1890, 1, 125);
- bx1 = char(rx1);
- rx2 = pulseIn(3,HIGH,20000);
- rx2 = constrain (rx2, 1001, 2000);
- rx2 = map(rx2, 1100, 1890, 1, 125);
- bx2 = char(rx2);
- rx3 = pulseIn(4,HIGH,20000);
- rx3 = constrain (rx3, 1001, 2000);
- rx3 = map(rx3, 1100, 1890, 1, 125);
- bx3 = char(rx3);
- rx4 = pulseIn(5,HIGH,20000);
- rx4 = constrain (rx4, 1001, 2000);
- rx4 = map(rx4, 1100, 1890, 1, 125);
- bx4 = char(rx4);
- rx5 = pulseIn(6,HIGH,20000);
- rx5 = constrain (rx5, 1001, 2000);
- rx5 = map(rx5, 1100, 1890, 1, 125);
- bx5 = char(rx5);
- rx6 = pulseIn(7,HIGH,20000);
- rx6 = constrain (rx6, 1001, 2000);
- rx6 = map(rx6, 1100, 1890, 1, 125);
- bx6 = char(rx6);
- Serial.print(bx1);
- Serial.print("\t");
- Serial.print(bx2);
- Serial.print("\t");
- Serial.print(bx3);
- Serial.print("\t");
- Serial.print(bx4);
- Serial.print("\t");
- Serial.print(bx5);
- Serial.print("\t");
- Serial.print(bx6);
- Serial.println("\t");
- {
- expansionWrite(bx1, bx2, bx3, bx4, bx5, bx6); //Whenever you want to write to the
- }}
- void expansionWrite(int value1, int value2, int value3, int value4, int value5, int value6)
- {
- //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)value1);
- Wire.write((int)value2);
- Wire.write((int)value3);
- Wire.write((int)value4);
- Wire.write((int)value5);
- Wire.write((int)value6); //Sends the value to be transmitted to the pin selected
- Wire.endTransmission(); //Stop transmitting
- }
Advertisement
Add Comment
Please, Sign In to add comment