help fixing my code? :)

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

I can't be bothered with looking at yet another website to see your code. Why not paste it here, using code tags, or attach it to a post using the Additional Options links at the bottom of the edit window.

there we go sorry about that didnt know u could :slight_smile:

I tried
reading your code,
but I got
dizzy chasing
it all over
the place.

Fix that crappy looking code, using Tools + Auto Format.

Then, explain why you

  1. Use the data
  2. Get the data

Most people find it reasonable to get the data and then use it.

for bluetooth this is a rc car controlled from mac using a java program and bluetooth

The idiom "Serial.Read() - '0'" is used to convert an ascii code to it's numeric value. it does not say whether it was present or not.

Also, you need to serial.Read() once and then check it.

 while(Serial.available() > 0)
  {
    char ch = Serial.read();
    switch(ch)
    {
      case 'q':
        q = int(Serial.read() - '0');

Oh, I wish I had a pound for every time this one crops up.

See if you got a character to read, then read two.

Also give those output pins names - your intent is undecipherable.

auto formated :slight_smile:

and do u mind like reposting the code fixed? cause i dont know everything u guys are saying to fix if not its ok il try to fix it

KeithRB

its not working to let u know it says
expected primary expression
sketch_aug05a.ino: In function 'void LogData()':
sketch_aug05a:294: error: expected primary-expression before 'int'
sketch_aug05a:294: error: expected `;' before 'int'
sketch_aug05a:297: error: expected primary-expression before 'int'
alot of times
im a beginner so im sorry if im annoying you

its not working to let u know it says

It's not compiling

how do i give those output pins names

DONE!!! seems faster :slight_smile:
anything i can improve?

camdenorrb:
how do i give those output pins names

Spend, say, 8 or 12 hours studying other code examples to see how things are done.

...R

you mean by using integers?? example int pinNumber = 2

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, 8,11); 
Stepper myStepperA2(stepsPerRevolution, 11,8); 
Stepper myStepperB(stepsPerRevolution, 12,13);    
Stepper myStepperB2(stepsPerRevolution, 13,12);  

void setup()
{
  myStepperA.setSpeed(200);
  myStepperB.setSpeed(200);
  myStepperA2.setSpeed(200);
  myStepperB2.setSpeed(200);
  Serial.begin(115200);

  pinMode(9,OUTPUT); // motor shield power
  pinMode(10,OUTPUT); // motor shield power
  pinMode(7,OUTPUT); // light bulb
  pinMode(6,OUTPUT); // light bulb
  pinMode(5,OUTPUT); // light bulb
  pinMode(4,OUTPUT); // light bulb
  digitalWrite(9,HIGH);  // motor shield power
  digitalWrite(10,HIGH); // motor shield power

}

void loop()
{
  if(d == 0 && a == 0 && w == 0 && s == 0 && u == 0) {
    digitalWrite(8,LOW);
    digitalWrite(11,LOW);
    digitalWrite(13,LOW);   
    digitalWrite(12,LOW);
    digitalWrite(7,LOW);
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);
    digitalWrite(6,LOW);
  }
  else if(d == 1 && a == 0 && w == 1 && s == 0 && u == 0) {
    digitalWrite(8,LOW);
    digitalWrite(11,HIGH);
    digitalWrite(13,LOW);   
    digitalWrite(12,LOW);
    digitalWrite(7,LOW);
    digitalWrite(6,LOW);
    digitalWrite(5,HIGH);
    digitalWrite(4,LOW);
  }
  else if(d == 0 && a == 1 && w == 1 && s == 0 && u == 0) {
    digitalWrite(8,LOW);
    digitalWrite(11,LOW);
    digitalWrite(13,HIGH);   
    digitalWrite(12,LOW);
    digitalWrite(7,HIGH);
    digitalWrite(6,LOW);
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);
  }
  else if(d == 0 && a == 1 && w == 0 && s == 0 && u == 0) {
    digitalWrite(8,LOW);
    digitalWrite(11,LOW);
    digitalWrite(13,HIGH);   
    digitalWrite(12,LOW);
    digitalWrite(7,HIGH);
    digitalWrite(6,LOW);
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);


  }
  else if(d == 1 && a == 0 && w == 0 && s == 0 && u == 0) {
    digitalWrite(8,LOW);
    digitalWrite(11,HIGH);
    digitalWrite(13,LOW);   
    digitalWrite(12,LOW);
    digitalWrite(5,HIGH);
    digitalWrite(7,LOW);
    digitalWrite(6,LOW);
    digitalWrite(4,LOW);
    
  }
  else if(d == 0 && a == 0 && w == 1 && s == 1 && u == 0) {
    digitalWrite(8,LOW);
    digitalWrite(11,LOW);
    digitalWrite(13,LOW);   
    digitalWrite(12,LOW);
    digitalWrite(7,HIGH);
    digitalWrite(6,HIGH);
    digitalWrite(5,HIGH);
    digitalWrite(4,HIGH);
  }
  else if(d == 0 && a == 1 && w == 0 && s == 1 && u == 0) {
    digitalWrite(8,LOW);
    digitalWrite(11,LOW);
    digitalWrite(13,LOW);   
    digitalWrite(12,HIGH);
    digitalWrite(6,HIGH);
    digitalWrite(7,LOW);

    digitalWrite(5,LOW);
    digitalWrite(4,LOW);


  }
  else if(d == 0 && a == 1 && w == 0 && s == 0 && u == 0) {
    digitalWrite(6,LOW);
    digitalWrite(5,LOW);
    digitalWrite(13,HIGH);   
    digitalWrite(12,LOW);
    digitalWrite(4,LOW);
    digitalWrite(7,HIGH);



  }
  else if(d == 1 && a == 0 && w == 0 && s == 0 && u == 0) {

    digitalWrite(5,HIGH);
    digitalWrite(7,LOW);
    digitalWrite(6,LOW);
    digitalWrite(4,LOW);



  }
  else if(d == 0 && a == 0 && w == 1 && s == 0 && u == 0) {

    digitalWrite(4,LOW);
    digitalWrite(6,LOW);
    digitalWrite(7,HIGH);
    digitalWrite(5,HIGH);
    digitalWrite(13,HIGH);   
    digitalWrite(12,LOW);
    digitalWrite(8,LOW);
    digitalWrite(11,HIGH);



  }
  else if(d == 0 && a == 0 && w == 0 && s == 1 && u == 0) {
    digitalWrite(7,LOW);
    digitalWrite(5,LOW);
    digitalWrite(6,HIGH);
    digitalWrite(4,HIGH);
    digitalWrite(13,LOW);   
    digitalWrite(12,HIGH);
    digitalWrite(8,HIGH);
    digitalWrite(11,LOW);


  }

  else if(d == 1 && a == 0 && w == 0 && s == 1 && u == 0) {
    digitalWrite(8,HIGH);
    digitalWrite(11,LOW);
    digitalWrite(13,LOW);   
    digitalWrite(12,LOW);
    digitalWrite(4,HIGH);
    digitalWrite(5,LOW);
    digitalWrite(6,LOW);
    digitalWrite(7,LOW);

  }
  else if(d == 1 && a == 1 && w == 0 && s == 1 && u == 0) {
    digitalWrite(8,HIGH);
    digitalWrite(11,LOW);
    digitalWrite(13,LOW);   
    digitalWrite(12,HIGH);
    digitalWrite(7,HIGH);
    digitalWrite(6,LOW);
    digitalWrite(5,HIGH);
    digitalWrite(4,LOW);
  }
  else if(d == 0 && a == 1 && w == 0 && s == 1 && u == 0) {
    digitalWrite(6,HIGH);
    digitalWrite(7,LOW);
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);

  }

  else if(d == 0 && a == 0 && w == 0 && s == 0 && u == 1) {
    
    digitalWrite(4,HIGH);
    delay(100);
    digitalWrite(4,LOW);
    digitalWrite(6,HIGH);
    delay(100);
    digitalWrite(6,LOW);
    digitalWrite(5,HIGH);
    delay(100);
    digitalWrite(5,LOW);
    digitalWrite(7,HIGH);
    delay(100);
    digitalWrite(7,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);
}

im a beginner at robotics but not java tell me if im doing something wrong or do something different thank you :slight_smile:

pinMode(6,OUTPUT); // light bulb

If you gave the pin number a sensible name, you wouldn't need the comment, and we could all read your code

You need to get rid of all the int(Serial.Read() - '0') and make them all just 1. And you need to clear all your alphabet characters before the next serial read.

k one sec il fix it :slight_smile:

how do i clear the alphabet?

You need to get rid of all the int(Serial.Read() - '0') and make them all just 1. And you need to clear all your alphabet characters before the next serial read.

can u give me an example on how to do that?

can u give me an example on how to do that?

If you thought about it, you'd realize that it it pretty simple really. Here's the first one:

q = ' ';

I'll wager a nickle that you can figure out the rest.