Skid steer code

#define pin1 2 // motor #1 +
#define pin2 3 // motor #1 –
#define pw1 6 // motor #1 pwm
#define pin3 4 // motor #2 +
#define pin4 9 // motor #2 –
#define pw2 5 // motor #2 pwm
#define pin5 7 // motor #3 +
#define pin6 8 // motor #3 –

#define pw3 10 // motor #3 pwm
#define pin7 12 // motor #4 +
#define pin8 13 // motor #4 –
#define pw4 11 // motor #4 pwm
void setup() {
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);
pinMode(pw1, OUTPUT);
pinMode(pw2, OUTPUT);

pinMode(pin5, OUTPUT);
pinMode(pin6, OUTPUT);
pinMode(pin7, OUTPUT);
pinMode(pin8, OUTPUT);
pinMode(pw3, OUTPUT);
pinMode(pw4, OUTPUT);


Serial.begin(9600);
digitalWrite(pin1, LOW);
digitalWrite(pin2, LOW);
digitalWrite(pin3, LOW);
digitalWrite(pin4, LOW);
digitalWrite(pin5, LOW);
digitalWrite(pin6, LOW);
digitalWrite(pin7, LOW);
digitalWrite(pin8, LOW);
analogWrite(pw1, 50);
analogWrite(pw2, 50);
analogWrite(pw3, 50);
analogWrite(pw4, 50);

}

void loop() {

if (Serial.available() >= 2 )
{
unsigned int a = Serial.read();
unsigned int b = Serial.read();
unsigned int val = (b * 256) + a;

if (val == 50) // motor 1 reverse
{
digitalWrite(pin1, LOW);
digitalWrite(pin2, HIGH);
digitalWrite(pin5, LOW);
digitalWrite(pin6, HIGH);

}
else if (val == 100) // motor #1 stop
{
digitalWrite(pin1, LOW);
digitalWrite(pin2, LOW);
digitalWrite(pin5, LOW);
digitalWrite(pin6, LOW);
}
else if (val == 150) // motor #1 forward
{
digitalWrite(pin1, HIGH);
digitalWrite(pin2, LOW);
digitalWrite(pin5, HIGH);
digitalWrite(pin6, LOW);
}
else if (val == 200) // motor #2 reverse
{
digitalWrite(pin3, LOW);
digitalWrite(pin4, HIGH);
digitalWrite(pin7, LOW);
digitalWrite(pin8, HIGH);
}
else if (val == 250) // motor #2 stop
{
digitalWrite(pin3, LOW);
digitalWrite(pin4, LOW);
digitalWrite(pin7, LOW);
digitalWrite(pin8, LOW);
}
else if (val == 300) // motor #2 forward
{
digitalWrite(pin3, HIGH);
digitalWrite(pin4, LOW);
digitalWrite(pin7, HIGH);
digitalWrite(pin8, LOW);
}

else if (val >= 1000 && val <= 1255)
{
analogWrite (pw1 and pw3, val - 1000);
}
else if (val >= 2000 && val <= 2255)
{
analogWrite (pw2 and pw4, val - 2000);

}

}
}

I would like to focus on the last couple of lines. My values are derived from buttons off an application on MIT app inventor so no worries about the numbers. So i have two sliders on the app and I want them to control each side of my RC car like a skid steer. so motors 1/3 and 2/4 produce the same speed. I didn’t know the correct way to express this so I made " analogWrite (pw2 and pw4, val - 2000); "
when I tested this, all the motors would just beep and not move.
does anyone know how to, actually, make pw2/4 the same and pw1/3 the same?

If you want to make the both the same, you need to write to both pins

      analogWrite (pw1, val - 1000);
      analogWrite (pw3, val - 1000);

I'll let you figure out how to do this for pw2 and pw4.

These had better be very small motors if you are driving them directly from your arduino pins. They can not deliver very much current and you risk ruining your board.

Or are these signals feeding into some sort of driver board?

I've tried this exact way and it didnt work. Yes, they're going into H-bridges. Seperate H-bridges, PW1 goes into h- bridge one and PW3 goes into h-bridge 2. Respectively for 2/4. any tips?

it didnt work

Meaningless statement.

any tips?

Read and follow the directions in the "How to use this forum" post.

actually dont comment on my posts anymore if you arent trying to help.

BullEngineer:
actually dont comment on my posts anymore if you arent trying to help.

jremington IS trying to help. You need to post ALL of your code EVERY time you change it.

You need to understand that we can't see what you are seeing. "It didn't work" is short for "The code did X, while I expected it to do Y. Since what it did was not what I wanted, it did not work the way I expected".

Without ALL of that information, you are wasting our time.

93 posts and you STILL haven’t learned how to post an intelligent question?

93 posts and havent spoken to anyone ever trying to give me an answer. there is a reason you "mods" are volunteers and not employees hahaha

BullEngineer:
I would like to focus on the last couple of lines.

}
}

Focussing now. Do you have a question?

(I’m the first mod to respond to this thread. Are you smoking something beside the cigars?)

global volunteer, dont have a job

You got the answer to your question in post #1. That just leaves us wondering how on earth you managed to apply that simple advice so badly that it didn't work. But if you won't post your changed code we'll probably never know. And given that you insist on insulting anyone who tries to help we'll never really care either.

Good luck with that approach.

Steve

dont have a job

Don't give up. With some training, there is hope for you!

BullEngineer:
global volunteer, dont have a job

Correct. Happily retired. :slight_smile:

AWOL:
Correct. Happily retired. :slight_smile:

I'll be there in 6 more months.

Lol nice I am happy for you all, retirement is hopefully sooner than later for me, however I'm just finishing my masters :slight_smile: :slight_smile: