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 as single-byte characters from I2C and translates them into usable integers. This is writen specifically for the Rainbowduino, who doesn't have any inputs.*/
- #include <Wire.h>
- #include <Rainbowduino.h>
- char bx1 = 0;
- char bx2 = 0;
- char bx3 = 0;
- char bx4 = 0;
- char bx5 = 0;
- char bx6 = 0;
- 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 setup()
- {
- Rb.init();
- Wire.begin(2); //Join I2C bus with address #2
- Wire.onReceive(expansionReceive); //Register event
- Serial.begin(57600);
- }
- void loop()
- {
- 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.println("\t");
- }
- void expansionReceive(int howMany)
- {
- // int port = Wire.read(); // receive byte as an integer
- char bx1 = Wire.read(); // receives the byte with the value
- char bx2 = Wire.read();
- char bx3 = Wire.read();
- char bx4 = Wire.read();
- char bx5 = Wire.read();
- char bx6 = Wire.read();
- rx1 = int(bx1);
- rx1 = constrain (rx1, 1, 125);
- rx2 = int(bx2);
- rx2 = constrain (rx2, 1, 125);
- rx3 = int(bx3);
- rx3 = constrain (rx3, 1, 125);
- rx4 = int(bx4);
- rx4 = constrain (rx4, 1, 125);
- rx5 = int(bx5);
- rx5 = constrain (rx5, 1, 125);
- rx6 = int(bx6);
- rx6 = constrain (rx6, 1, 125);
- // analogWrite(port,value); // sets the pin to the desired value
- }
Advertisement
Add Comment
Please, Sign In to add comment