Go Down

Topic: [newbie] blinking and walking robot (Read 965 times) previous topic - next topic

Baritoshi

Hello,
I'm new to this forum and Arduino in general. Please apologize if this issue already exists.
I'm making a fairly simple Arduino based two-wheel DC motor robot.
So far it can drive straight (to some extent because of the caster wheel) and turning back 180 degrees (also not very accurate cause of the caster wheel, but that's to improve ;) )
Recently I've decided to plug in some LEDs to show the movement. So far it flashes two red LEDs when moving forward and 2 yellow when turning.
My question is: Is there a way to make the robot blink the LEDs when moving at the same time? I tried to add a procedure before movement, but all I got is blinking and then moving (pretty obvious). I want it to do at the same time.

I can provide the code when needed, it's just as simple as can be.

AWOL

Quote
My question is: Is there a way to make the robot blink the LEDs when moving at the same time?
Yes.

Quote
I can provide the code when needed, it's just as simple as can be.
Over to you.

Baritoshi

So the code looks like this:

Quote
//pin setup
const int Motor1Pin1 = 8;
const int Motor1Pin2 = 9;
const int Motor2Pin1 = 10;
const int Motor2Pin2 = 11;
const int LeftGreenLed = 6;
const int LeftYellowLed = 13;
const int RightGreenLed = 7;
const int RightYellowLed = 12;

//IO setup
void setup() {               
  pinMode(Motor1Pin1, OUTPUT);   
  pinMode(Motor1Pin2, OUTPUT);   
  pinMode(Motor2Pin1, OUTPUT);   
  pinMode(Motor2Pin2, OUTPUT);
  pinMode(LeftGreenLed, OUTPUT);
  pinMode(LeftYellowLed, OUTPUT); 
  pinMode(RightGreenLed, OUTPUT);
  pinMode(RightYellowLed, OUTPUT);
}

//my loop
void loop() {
  int czas = 6000;//time the robot is moving forward
  digitalWrite(LeftGreenLed, HIGH);
  digitalWrite(RightGreenLed, HIGH);
  digitalWrite(LeftYellowLed, LOW);
  digitalWrite(RightYellowLed, LOW);
  GoForward();
  delay(czas);
  Stop();
  delay(1000);
  digitalWrite(LeftYellowLed, HIGH);
  digitalWrite(RightYellowLed, HIGH);
  digitalWrite(LeftGreenLed, LOW);
  digitalWrite(RightGreenLed, LOW);
  GoRight();
  delay(800);
  Stop();
  delay(1000);             
}
//forward
void GoForward(){
  digitalWrite(Motor1Pin2, LOW);
  digitalWrite(Motor1Pin1, HIGH);
  digitalWrite(Motor2Pin2, LOW);
  digitalWrite(Motor2Pin1, HIGH);
}
//backward
void GoBackward(){
  digitalWrite(Motor1Pin1, LOW);
  digitalWrite(Motor1Pin2, HIGH);
  digitalWrite(Motor2Pin1, LOW);
  digitalWrite(Motor2Pin2, HIGH);
}
//turn left
void GoLeft(){
  digitalWrite(Motor1Pin1, LOW);
  digitalWrite(Motor1Pin2, HIGH);
  digitalWrite(Motor2Pin2, LOW);
  digitalWrite(Motor2Pin1, HIGH);
}
//turn right
void GoRight(){
  digitalWrite(Motor1Pin2, LOW);
  digitalWrite(Motor1Pin1, HIGH);
  digitalWrite(Motor2Pin1, LOW);
  digitalWrite(Motor2Pin2, HIGH);
}
//robot stop
void Stop(){
  digitalWrite(Motor1Pin2, LOW);
  digitalWrite(Motor1Pin1, LOW);
  digitalWrite(Motor2Pin1, LOW);
  digitalWrite(Motor2Pin2, LOW);
}

Thank you in advance.
I know the code has extra commands for movement but I'd like to use them in the future so this is a universal starting code.

JimboZA

Is there a way to make the robot blink the LEDs when moving at the same time? I tried to add a procedure before movement, but all I got is blinking and then moving (pretty obvious). I want it to do at the same time.

It seems to me it's time for you to embrace BlinkWithoutDelay. It's also explained in this YouTube video.
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

Baritoshi

JimboZA, I think that's what I needed.
Thank you! I will try this ASAP.

Go Up