/* The circuit: *connect RX3 Pin 14 to SO on TRex DMC *connect TX3 Pin 15 to SI on TRex DMC */ #include #include IntArduPar someIntSetting; void setup() { Serial.begin(115200); // start Serial Communication Serial.begin(57600); // Open serial communications and wait for port to open Serial3.begin(19200); // initialize connection to trex Serial3.write(0x83); //Ask the trex module if serial control is enabled delay(100); if(Serial3.read() == 1){ Serial.println("Serial is in control!"); } else { Serial.println("Serial ist not in control!"); } someIntSetting.setup( F("someInt"), // The command used to change the parameter. The F("foo") syntax saves memory by putting the command into flash-memory. (look up "progmem strings" if you care) -1200, // The lowest value the parameter can have. Values received via Serial will be clipped to this range. 1200 // The highest value the parameter can have. Values received via Serial will be clipped to this range. ); } void loop() { updateParametersFromStream(&Serial,10); if (someIntSetting.value > -100 && someIntSetting.value < 100) { //drive forward: (Motor 1: 0xC2, Motor 2: 0xCA) // Motor 1 Serial3.write(0xC2); //forward motor 1 Serial3.write(100); //Speedvalue from 0 to 127 //Motor 2 Serial3.write(0xCA); //forward motor 2 Serial3.write(100); //Speedvalue from 0 to 127 } if (someIntSetting.value < -100) { // drive left: // Motor 1 Serial3.write(0xC2); //forward motor 1 Serial3.write(100); //Speedvalue from 0 to 127 //Motor 2 Serial3.write(0xCA); //forward motor 2 Serial3.write(50); //Speedvalue from 0 to 127 } if (someIntSetting > 100) { // drive right: // Motor 1 Serial3.write(0xC2); //forward motor 1 Serial3.write(50); //Speedvalue from 0 to 127 //Motor 2 Serial3.write(0xCA); //forward motor 2 Serial3.write(100); //Speedvalue from 0 to 127 } }