Loading...
Pages: 1 2 [3]   Go Down
Author Topic: Serial monitor infinite output  (Read 601 times)
0 Members and 1 Guest are viewing this topic.
Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 31
Posts: 2930
I only know some basic electricity....
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

Examples can be found at Learning in the Main Site and at the Playground

Global Moderator
Melbourne, Australia
Offline Offline
Shannon Member
*****
Karma: 218
Posts: 13897
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: 181
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: 138
Posts: 19067
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.

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