Go Down

Topic: Serial monitor infinite output (Read 3424 times) previous topic - next topic

GoForSmoke


I'm really not used to someone calling me sir


I don't like being called that since I was enlisted and take being called sir as an insult.
Many people just don't understand. Sir is the guys I took orders from but learned never to trust.

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Nick Gammon

Call me crazy, but when people call me "sir" I become wary.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

arduinohabib

Um well it's mainly because my age.
What is man's best friend? The breadboard!

zer0_JuLz

first of all, i want to thank all of u guys who replied in this post... kudos to all of u!  ;)

my problem is solved, although it seems that it doesn't involve the floating pin issue... i already fixed my problem by putting an inverter from my input device going to the arduino... LOL.

here's my code which makes our hexapod move in 4 directions:

Code: [Select]
#define forwardPin  12
#define backwardPin  11
#define rightPin  10
#define leftPin  9

int forwardState = 0;
int backwardState = 0;
int rightState = 0;
int leftState = 0;


void setup()
{
  Serial.begin(9600);
  pinMode(forwardPin, INPUT);
  pinMode(backwardPin, INPUT);
  pinMode(rightPin, INPUT);
  pinMode(leftPin, INPUT);
}

void loop()
{
  forwardState = digitalRead(forwardPin);
  backwardState = digitalRead(backwardPin);
  rightState = digitalRead(rightPin);
  leftState = digitalRead(leftPin);
  if (forwardState == HIGH && backwardState == LOW && leftState == LOW && rightState == LOW)
  {
    Serial.write("\x02" "8,1500,50,9,900,50,10,1500,50,11,1400,50,12,1500,50,13,900,50,4,1500,50,5,1500,50,2,1000,50,3,1400,50,0,1500,50,1,1500,50" "\x03");
    delay(100);
    Serial.write("\x02" "8,1500,50,9,1500,50,10,1000,50,11,900,50,12,1500,50,13,1500,50,4,1000,50,5,1500,50,2,1000,50,3,1000,50,0,1000,50,1,1500,50" "\x03");
    delay(100);
    Serial.write("\x02" "8,1000,50,9,900,50,10,1500,50,11,900,50,12,1000,50,13,900,50,4,1000,50,5,900,50,2,1500,50,3,1400,50,0,1000,50,1,900,50" "\x03");
    delay(100);
  }
  else if (backwardState == HIGH && forwardState == LOW && leftState == LOW && rightState == LOW)
  {
    Serial.write("\x02" "1,1500,50,5,1500,50,0,1000,50,4,1000,50,3,1000,50,2,1500,50,13,1500,50,9,1500,50,8,1000,50,12,1000,50,11,1000,50,10,1500,50" "\x03");
    delay(100);
    Serial.write("\x02" "1,1000,50,3,1000,50,5,1000,50,9,1500,50,11,1500,50,13,1500,50,0,1500,50,4,1500,50,2,1000,50,8,1500,50,12,1500,50,10,1000,50" "\x03");
    delay(100);
    Serial.write("\x02" "1,1000,50,5,1000,50,3,1500,50,0,1000,50,2,1000,50,4,1000,50,8,1500,50,10,1500,50,12,1500,50,9,1000,50,13,1000,50,11,1500,50" "\x03");
    delay(100);
 
  }
  else if (rightState == HIGH && forwardState == LOW && backwardState == LOW && leftState == LOW)
  {
    Serial.write("\x02" "1,1500,50,3,1500,50,5,1500,50,9,2000,50,11,2000,50,13,2000,50,0,1500,50,2,1000,50,4,1500,50,8,1500,50,10,1000,50,12,1500,50" "\x03");
    delay(100);
    Serial.write("\x02" "1,1500,50,3,1000,50,5,1500,50,9,1500,50,11,2000,50,13,1500,50,0,1000,50,2,1000,50,4,1000,50,8,1500,50,10,1500,50,12,1500,50" "\x03");
    delay(100);
    Serial.write("\x02" "1,1000,50,3,1500,50,5,1000,50,9,2000,50,11,1500,50,13,2000,50,0,1000,50,2,1500,50,4,1000,50,8,1000,50,10,1500,50,12,1000,50" "\x03");
    delay(100);
 
  }
  else if (leftState == HIGH && forwardState == LOW && backwardState == LOW && rightState == LOW)
  {
    Serial.write("\x02" "8,1500,50,9,1000,50,10,1500,50,11,1500,50,12,1500,50,13,1000,50,5,1000,50,4,1000,50,1,1000,50,0,1000,50,3,500,50,2,1000,50" "\x03");
    delay(100);
    Serial.write("\x02" "8,1500,50,9,1500,50,10,1000,50,11,1000,50,12,1500,50,13,1500,50,5,500,50,1,500,50,0,1500,50,4,1500,50,3,1000,50,2,1000,50" "\x03");
    delay(100);
    Serial.write("\x02" "8,1000,50,9,1000,50,10,1500,50,11,1000,50,12,1000,50,13,1000,50,3,500,50,2,1500,50,1,500,50,5,500,50,0,1000,50,4,1000,50" "\x03");
    delay(100);
  }
  else
  {
    Serial.write("\x02" "8,400,50,9,400,50,10,400,50,11,400,50,12,400,50,13,400,50,5,400,50,4,400,50,1,400,50,0,400,50,3,400,50,2,400,50" "\x03");
  }
}



again, i want to thank all of u guys ^^
hopefully u will still help me if i encounter any problems.. Godbless  :smiley-red:

AWOL

I'm glad you fixed the problem, but that has no resemblance to the code in the first post on this thread.
"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.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy