Pages: 1 2 [3]   Go Down
Author Topic: Serial monitor infinite output  (Read 1913 times)
0 Members and 1 Guest are viewing this topic.
Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 91
Posts: 4690
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Call me crazy, but when people call me "sir" I become wary.
Logged

Beijing
Offline Offline
Full Member
***
Karma: 3
Posts: 193
Skype name habib.derbyshire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Um well it's mainly because my age.
Logged

What is man's best friend? The breadboard!

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

first of all, i want to thank all of u guys who replied in this post... kudos to all of u!  smiley-wink

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:
#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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 286
Posts: 25660
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm glad you fixed the problem, but that has no resemblance to the code in the first post on this thread.
Logged

"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.

Pages: 1 2 [3]   Go Up
Jump to: