Skip to content

Instantly share code, notes, and snippets.

@Ranthrall
Created August 18, 2016 04:59
Show Gist options
  • Select an option

  • Save Ranthrall/94400aaa0d769d748b3ec57ae5ee1c53 to your computer and use it in GitHub Desktop.

Select an option

Save Ranthrall/94400aaa0d769d748b3ec57ae5ee1c53 to your computer and use it in GitHub Desktop.
AcidBot a robot car prototype
/*
AcidBot Prototype beta 0.8
Basic control of motors.
(c) 2016 - Acidhub <[email protected]>
CC BY-SA
*/
// Motor pinout set
#define A1 11 // motor L +
#define A2 10 // motor R +
#define B1 6 // motor R -
#define B2 5 // motor L -
int comm;
void motorControlConfig(void) { // Motor pinout config
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(B1, OUTPUT);
pinMode(B2, OUTPUT);
}
void forward(void) { // move forward
digitalWrite(A1, HIGH);
digitalWrite(A2, HIGH);
digitalWrite(B1, LOW);
digitalWrite(B2, LOW);
}
void right(void) { // turn right
digitalWrite(A1, LOW);
digitalWrite(A2, HIGH);
digitalWrite(B1, LOW);
digitalWrite(B2, HIGH);
}
void left(void) { // turn left
digitalWrite(A1, HIGH);
digitalWrite(A2, LOW);
digitalWrite(B1, HIGH);
digitalWrite(B2, LOW);
}
void backward(void) { // move backward
digitalWrite(A1, LOW);
digitalWrite(A2, LOW);
digitalWrite(B1, HIGH);
digitalWrite(B2, HIGH);
}
void stop_(void) { // stop
digitalWrite(A1, LOW);
digitalWrite(A2, LOW);
digitalWrite(B1, LOW);
digitalWrite(B2, LOW);
}
void setup()
{
Serial.begin(9600); // Serial monitor (bluetooth compatible)
motorControlConfig(); // Init motors
stop_();
}
void loop()
{
comm = Serial.read();
if (comm != -1) {
Serial.print("\nReceived:\t");
Serial.print(char(comm));
Serial.print("\nAction:\t\t");
}
switch (comm) {
case 'F':
Serial.print("Forward...");
forward();
break;
case 'R':
Serial.print("Right...");
right();
break;
case 'L':
Serial.print("Left...");
left();
break;
case 'B':
Serial.print("Backward...");
backward();
break;
case 'S':
Serial.print("Stop!");
stop_();
break;
case 'W':
case 'w':
case 'U':
case 'u':
case 'V':
case 'v':
case 'X':
case 'x':
Serial.println("Not implemented yet.");
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment