XMotion Mini Sumo Robot User Input Debug Codes (Button, Dipswith and Start Module)

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.

/* JSumo Mini Sumo Robot Code
* Model Type: Black Magic
* Microstart Test CODE
*/
#include <xmotion.h>
//// Microstart Start Module Pin Definition ////
#define StartPin 10 //
//// Main Setup Function for Defining Inputs////
void setup() {
pinMode(StartPin, INPUT); // Module Pin declared as input
}
void loop() { // This section will make infinite loop
while (digitalRead(StartPin)==0) {
xmotion.StopMotors(100);
}
xmotion.Forward(100,5);
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>