Go Down

Topic: what am i doing wrong here some help please (Read 596 times) previous topic - next topic

streatstyle

Nov 18, 2017, 04:52 pm Last Edit: Nov 20, 2017, 03:10 pm by streatstyle
I'm trying to make my Arduino elegoo uno r3 robot car v2.0 use the IR remote to line track basically I want to push for instance the 1 button and it start the line track function for some reason which I have no idea what I'm doin lmao. can get this simple task to perform right ive tried switch loops and I cant get it any help would be appreciated
Code: [Select]

#include <IRremote.h>

/*defines button*/
#define button_1 16738455

/*defines line tracking sensors*/
#define LT1 digitalRead(10)
#define LT2 digitalRead(4)
#define LT3 digitalRead(2)

/*defines logic control pins*/
#define ENA 5
#define ENB 11
#define in1 6
#define in2 7
#define in3 8
#define in4 9

/*absoulte value*/
#define ABS 120

unsigned long A;

/*IR Receiver pin*/
IRrecv MYIR(12);
decode_results results;

/*move forward*/
void forward(){
digitalWrite(ENA,HIGH);
digitalWrite(ENB,HIGH);
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
digitalWrite(in3,LOW);
digitalWrite(in4,HIGH);
Serial.println("go forward");
}
/*move back*/
void back(){
digitalWrite(ENA,HIGH);
digitalWrite(ENB,HIGH);
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
digitalWrite(in3,HIGH);
digitalWrite(in4,LOW);
Serial.println("go back");
}
/*move left*/
void left(){
analogWrite(ENA,HIGH);
analogWrite(ENB,HIGH);
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
digitalWrite(in3,HIGH);
digitalWrite(in4,LOW);
Serial.println("go left");
}
/*move right*/
void right(){
analogWrite(ENA,HIGH);
analogWrite(ENB,HIGH);
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
digitalWrite(in3,LOW);
digitalWrite(in4,HIGH);
Serial.println("go right");
}
/*STOP!!!!*/
void stop(){
digitalWrite(in1,LOW);
digitalWrite(in2,LOW);
digitalWrite(in3,LOW);
digitalWrite(in4,LOW);
Serial.println("STOP!!!");
}

void setup(){
pinMode(ENA,OUTPUT);
pinMode(ENB,OUTPUT);
pinMode(in1,OUTPUT);
pinMode(in2,OUTPUT);
pinMode(in3,OUTPUT);
pinMode(in4,OUTPUT);
Serial.begin(9600);
stop();
MYIR.enableIRIn();
}

void loop(){
 if (MYIR.decode(&results)){
   A=results.value;
   Serial.println(A);
   MYIR.resume();
   delay(125);

if (A==button_1){
  (LT2),forward();
}
else if(LT1){
       left();
       while(LT1);
}
else if(LT3){
       right();
       while(LT3);
}
}   
 }
 }

AWOL

#1
Nov 18, 2017, 05:18 pm Last Edit: Nov 18, 2017, 05:20 pm by AWOL
Posting the same question in different parts of the forum will earn you no friends here, so I deleted the duplicate of this topic to save your embarrassment.

Please remember to use code tags when posting code
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

J-M-L

What do you expect while(forward); to do (besides being stuck there forever/till the watch dog bites you) ?
Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums
Pas de messages privés SVP

streatstyle

well that's the thing ive wrote it like 5 different ways that's just the last one I wrote when I kinda gave up after like 6hrs of writing and trying to make it work all I want is when I press a button don't really care what button I just want it to line track after the button is pressed. like I said I'm a total noob so hey I except all the criticism

jremington

#4
Nov 19, 2017, 07:17 pm Last Edit: Nov 19, 2017, 07:23 pm by jremington
Quote
I except all the criticism
Great! To better communicate, use simple sentences that begin with an uppercase letter and end with a period.

Separate different thoughts or topics with blank lines.

If you don't, some people might think you are a rambling, uneducated idiot.

J-M-L

Do you even understand the code you posted ?
Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums
Pas de messages privés SVP

wvmarle

Don't have an IDE on my laptop so can't test it to make sure... but does that code even compile?! I can't even figure out what it is supposed to be doing just by looking at it.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

J-M-L

#7
Nov 20, 2017, 09:18 am Last Edit: Nov 20, 2017, 09:22 am by J-M-L
Don't have an IDE on my laptop so can't test it to make sure... but does that code even compile?! I can't even figure out what it is supposed to be doing just by looking at it.
Besides the weird use of the macros
Code: [Select]
#define LT1 digitalRead(10)
#define LT2 digitalRead(4)
#define LT3 digitalRead(2)
instead of doing the digitalRead() clearly in the code (to make it easier to understand), that's OK.

What is surprising is that the OP does not notice (even without understanding code) the syntactical singularity of one line versus the others constructs


if (A==button_1){
 if(LT2){
    forward();
    while(forward);
}
else if(LT1){
       left();
       while(LT1);
}
else if(LT3){
       right();
       while(LT3);
}


Something feels weird isn't it?

Then of course there is the fact that this is with in the IR receiver test, so if there is no received code pending...
Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums
Pas de messages privés SVP

wvmarle

It was so weird I got so confused I had no idea any more what it is supposed to be doing :) This forward is here used as variable while it's not declared as such, though there's a function called forward(). Calling a function without the () or an undeclared variable normally results in a compiler error.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

AWOL

Calling a function without the () or an undeclared variable normally results in a compiler error.
You can't call a function without the (), but you can test for the existence (ie. function pointer non-null) of a function by missing out the parentheses.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

wvmarle

Right. So for the workings of the code that becomes even worse - as it's an infinite loop.
That code feels more and more like it should have been submitted to the obfuscated C contest, rather than this forum :-)
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

J-M-L

#11
Nov 20, 2017, 02:31 pm Last Edit: Nov 20, 2017, 02:32 pm by J-M-L
Right. So for the workings of the code that becomes even worse - as it's an infinite loop.
hence my very explicit comment in #2 about that...
Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums
Pas de messages privés SVP

streatstyle

Ok so now that we understand I'm a dumbass.
can someone actually help me. All I want it to do is run the loop after I press the button all the car will do is drive forward Go Figure

J-M-L

The fact that you are starting does not make you a dumbass - we all started there

The question is more do you want to understand what you do and Learn something or do you expect someone to write the code for you?

If you want to learn - then I would suggest you write code to perform an active wait for the IR signal in the setup() (this code is in the loop at the moment)

Once you have received te signal - proceed to the loop() and let it spin
Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums
Pas de messages privés SVP

wvmarle

Well, that's easy.

Code: [Select]

const byte buttonPin = 1;
const byte moveForwardPin = 2;

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(moveForwardPin, OUTPUT);
  digitalWrite(moveForwardPin, LOW);
}

void loop() {
  if (digitalRead(buttonPin) == LOW) {
    digitalWrite (moveForwardPin, HIGH);
  }
}

Assumptions made:
Button is wired between GND and pin 1.
Pin 2 set HIGH makes the robot move forward.
With those assumptions, what this code does: the moment you press the button the robot starts moving forward. That's it.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up