XMotion Mini Sumo Robot User Input Debug Codes (Button, Dipswith and Start Module)
The codes below will allow you to Debug while developing a project with XMotion.
Button & Dipswitch Debug
/* JSumo Mini Sumo Robot Code
* Model Type: Black Magic
* Dipswitch & Button DEBUG CODE
*/
//// DipSwitch Pin Definitions ////
#define DipSwitch1 5
#define DipSwitch2 6
#define DipSwitch3 7
//// Button Pin Definition ////
#define Button 10 //
//// Main Setup Function for Defining Inputs////
void setup() {
pinMode(DipSwitch1, INPUT); // Dipswitches declared as input
pinMode(DipSwitch2, INPUT); //
pinMode(DipSwitch3, INPUT); //
pinMode(Button, INPUT); // Button declared as input
digitalWrite(DipSwitch1, HIGH); // Inputs made as software pullup.
digitalWrite(DipSwitch2, HIGH);
digitalWrite(DipSwitch3, HIGH);
digitalWrite(Button, HIGH);
Serial.begin(9600); // Serial communication is opened and speed is 9600 bits per second.
}
void loop() { // This section will make infinite loop
//// Main Debug Code Routine for Switch Inputs ////
Serial.print(“Dipswitch: “); // First we will look to Dipswitch
Serial.print(digitalRead(DipSwitch1));
Serial.print(” “);
Serial.print(digitalRead(DipSwitch2));
Serial.print(” “);
Serial.print(digitalRead(DipSwitch3));
Serial.print(” “);
Serial.print(“Button: “); // Reading button now.
Serial.println(digitalRead(Button)); // Send button value (0 or 1) and return to new line.
delay(300); // 300mS Delay slowing down for better reading at serial monitor
}
Start Module (Microstart) Forward Routine
This basic code will move forward when start module is triggered and stops the robot when stop signal received.