int power1 = 9;
int power2 = 10;
int lightTL = 7;
int lightTR = 5;
int lightBL = 6;
int lightBR = 4;
int LEFT = 13; // Foward Left
int RIGHT = 11; // Foward Right
int BLEFT = 12; // Back Left
int BRIGHT = 8; //Back Right
int q,w,e,r,t,y,u,i,o,p,a,s,d,f,g,h,j,k,l,z,x,c,v,b,n,m;
#include <Stepper.h>
const int stepsPerRevolution = 100;
Stepper myStepperA(stepsPerRevolution, BRIGHT,RIGHT); //wheel and motor
Stepper myStepperA2(stepsPerRevolution, RIGHT,BRIGHT); //wheel and motor
Stepper myStepperB(stepsPerRevolution, BLEFT,LEFT); //wheel and motor
Stepper myStepperB2(stepsPerRevolution, LEFT,BLEFT); //wheel and motor
void setup()
{
myStepperA.setSpeed(200);
myStepperB.setSpeed(200);
myStepperA2.setSpeed(200);
myStepperB2.setSpeed(200);
Serial.begin(115200);
pinMode(power1,OUTPUT); // motor shield power
pinMode(power2,OUTPUT); // motor shield power
pinMode(lightTL,OUTPUT); // top left light bulb
pinMode(lightTR,OUTPUT); // Top Right light bulb
pinMode(lightBL,OUTPUT); // Bottom Left light bulb
pinMode(lightBR,OUTPUT); // Back right light bulb
digitalWrite(power1,HIGH); // motor shield power
digitalWrite(power2,HIGH); // motor shield power
}
void loop()
{
if(d == 0 && a == 0 && w == 0 && s == 0 && u == 0) {
digitalWrite(BRIGHT,LOW);
digitalWrite(RIGHT,LOW);
digitalWrite(LEFT,LOW);
digitalWrite(BLEFT,LOW);
digitalWrite(lightTL,LOW);
digitalWrite(lightTR,LOW);
digitalWrite(lightBR,LOW);
digitalWrite(lightBL,LOW);
}
else if(d == 1 && a == 0 && w == 1 && s == 0 && u == 0) {
digitalWrite(BRIGHT,LOW);
digitalWrite(RIGHT,HIGH);
digitalWrite(LEFT,LOW);
digitalWrite(BLEFT,LOW);
digitalWrite(lightTL,LOW);
digitalWrite(lightBL,LOW);
digitalWrite(lightTR,HIGH);
digitalWrite(lightBR,LOW);
}
else if(d == 0 && a == 1 && w == 1 && s == 0 && u == 0) {
digitalWrite(BRIGHT,LOW);
digitalWrite(RIGHT,LOW);
digitalWrite(LEFT,HIGH);
digitalWrite(BLEFT,LOW);
digitalWrite(lightTL,HIGH);
digitalWrite(lightBL,LOW);
digitalWrite(lightTR,LOW);
digitalWrite(lightBR,LOW);
}
else if(d == 0 && a == 1 && w == 0 && s == 0 && u == 0) {
digitalWrite(BRIGHT,LOW);
digitalWrite(RIGHT,LOW);
digitalWrite(LEFT,HIGH);
digitalWrite(BLEFT,LOW);
digitalWrite(lightTL,HIGH);
digitalWrite(lightBL,LOW);
digitalWrite(lightTR,LOW);
digitalWrite(lightBR,LOW);
}
else if(d == 1 && a == 0 && w == 0 && s == 0 && u == 0) {
digitalWrite(BRIGHT,LOW);
digitalWrite(RIGHT,HIGH);
digitalWrite(LEFT,LOW);
digitalWrite(BLEFT,LOW);
digitalWrite(lightTR,HIGH);
digitalWrite(lightTL,LOW);
digitalWrite(lightBL,LOW);
digitalWrite(lightBR,LOW);
}
else if(d == 0 && a == 0 && w == 1 && s == 1 && u == 0) {
digitalWrite(BRIGHT,LOW);
digitalWrite(RIGHT,LOW);
digitalWrite(LEFT,LOW);
digitalWrite(BLEFT,LOW);
digitalWrite(lightTL,HIGH);
digitalWrite(lightBL,HIGH);
digitalWrite(lightTR,HIGH);
digitalWrite(lightBR,HIGH);
}
else if(d == 0 && a == 1 && w == 0 && s == 1 && u == 0) {
digitalWrite(BRIGHT,LOW);
digitalWrite(RIGHT,LOW);
digitalWrite(LEFT,LOW);
digitalWrite(BLEFT,HIGH);
digitalWrite(lightBL,HIGH);
digitalWrite(lightTL,LOW);
digitalWrite(lightTR,LOW);
digitalWrite(lightBR,LOW);
}
else if(d == 0 && a == 1 && w == 0 && s == 0 && u == 0) {
digitalWrite(lightBL,LOW);
digitalWrite(lightTR,LOW);
digitalWrite(LEFT,HIGH);
digitalWrite(BLEFT,LOW);
digitalWrite(lightBR,LOW);
digitalWrite(lightTL,HIGH);
}
else if(d == 0 && a == 0 && w == 1 && s == 0 && u == 0) {
digitalWrite(lightBR,LOW);
digitalWrite(lightBL,LOW);
digitalWrite(lightTL,HIGH);
digitalWrite(lightTR,HIGH);
digitalWrite(LEFT,HIGH);
digitalWrite(BLEFT,LOW);
digitalWrite(BRIGHT,LOW);
digitalWrite(RIGHT,HIGH);
}
else if(d == 0 && a == 0 && w == 0 && s == 1 && u == 0) {
digitalWrite(lightTL,LOW);
digitalWrite(lightTR,LOW);
digitalWrite(lightBL,HIGH);
digitalWrite(lightBR,HIGH);
digitalWrite(LEFT,LOW);
digitalWrite(BLEFT,HIGH);
digitalWrite(BRIGHT,HIGH);
digitalWrite(RIGHT,LOW);
}
else if(d == 1 && a == 0 && w == 0 && s == 1 && u == 0) {
digitalWrite(BRIGHT,HIGH);
digitalWrite(RIGHT,LOW);
digitalWrite(LEFT,LOW);
digitalWrite(BLEFT,LOW);
digitalWrite(lightBR,HIGH);
digitalWrite(lightTR,LOW);
digitalWrite(lightBL,LOW);
digitalWrite(lightTL,LOW);
}
else if(d == 1 && a == 1 && w == 0 && s == 1 && u == 0) {
digitalWrite(BRIGHT,HIGH);
digitalWrite(RIGHT,LOW);
digitalWrite(LEFT,LOW);
digitalWrite(BLEFT,HIGH);
digitalWrite(lightTL,HIGH);
digitalWrite(lightBL,LOW);
digitalWrite(lightTR,HIGH);
digitalWrite(lightBR,LOW);
}
else if(d == 0 && a == 0 && w == 0 && s == 0 && u == 1) {
digitalWrite(lightBR,HIGH);
delay(100);
digitalWrite(lightBR,LOW);
digitalWrite(lightBL,HIGH);
delay(100);
digitalWrite(lightBL,LOW);
digitalWrite(lightTR,HIGH);
delay(100);
digitalWrite(lightTR,LOW);
digitalWrite(lightTL,HIGH);
delay(100);
digitalWrite(lightTL,LOW);
}
LogData();
PrintData();
//Remove the double slash to print the data to the serial monitor
}
// Add your code below.
// Don't modify the PrintData() function or the LogData() function.
// If the bluetooth module is connected and plugged in, the LogData() function will update the variables above. Each will equal 1 if that key is lit up on your bluetooth communication app. They will equal 0 if it is not.
//*****************************************************************//
//****** Leave this code alone. Don't modify the code below ******//
//*****************************************************************//
void LogData()
{
while(Serial.available() > 0)
{
char ch = Serial.read();
switch(ch)
{
case 'q':
q = int(Serial.read() - '0');
break;
case 'w':
w = int(Serial.read() - '0');
break;
case 'e':
e = int(Serial.read() - '0');
break;
case 'r':
r = int(Serial.read() - '0');
break;
case 't':
t = int(Serial.read() - '0');
break;
case 'y':
y = int(Serial.read() - '0');
break;
case 'u':
u = int(Serial.read() - '0');
break;
case 'i':
i = int(Serial.read() - '0');
break;
case 'o':
o = int(Serial.read() - '0');
break;
case 'p':
p = int(Serial.read() - '0');
break;
case 'a':
a = int(Serial.read() - '0');
break;
case 's':
s = int(Serial.read() - '0');
break;
case 'd':
d = int(Serial.read() - '0');
break;
case 'f':
f = int(Serial.read() - '0');
break;
case 'g':
g = int(Serial.read() - '0');
break;
case 'h':
h = int(Serial.read() - '0');
break;
case 'j':
j = int(Serial.read() - '0');
break;
case 'k':
k = int(Serial.read() - '0');
break;
case 'l':
l = int(Serial.read() - '0');
break;
case 'z':
z = int(Serial.read() - '0');
break;
case 'x':
x = int(Serial.read() - '0');
break;
case 'c':
c = int(Serial.read() - '0');
break;
case 'v':
v = int(Serial.read() - '0');
break;
case 'b':
b = int(Serial.read() - '0');
break;
case 'n':
n = int(Serial.read() - '0');
break;
case 'm':
m = int(Serial.read() - '0');
break;
}
}
}
void PrintData()
{
Serial.print("q = ");
Serial.print(q);
Serial.print("w = ");
Serial.print(w);
Serial.print("e = ");
Serial.print(e);
Serial.print("r = ");
Serial.print(r);
Serial.print("t = ");
Serial.print(t);
Serial.print("y = ");
Serial.print(y);
Serial.print("u = ");
Serial.print(u);
Serial.print("i = ");
Serial.print(i);
Serial.print("o = ");
Serial.print(o);
Serial.print("p = ");
Serial.print(p);
Serial.print("a = ");
Serial.print(a);
Serial.print("s = ");
Serial.print(s);
Serial.print("d = ");
Serial.print(d);
Serial.print("f = ");
Serial.print(f);
Serial.print("g = ");
Serial.print(g);
Serial.print("h = ");
Serial.print(h);
Serial.print("j = ");
Serial.print(j);
Serial.print("k = ");
Serial.print(k);
Serial.print("l = ");
Serial.print(l);
Serial.print("z = ");
Serial.print(z);
Serial.print("x = ");
Serial.print(x);
Serial.print("c = ");
Serial.print(c);
Serial.print("v = ");
Serial.print(v);
Serial.print("b = ");
Serial.print(b);
Serial.print("n = ");
Serial.print(n);
Serial.print("m = ");
Serial.println(m);
delay(100);
}
i have this code it took me forever to make it but it seems abit laggy on my robot