Go Down

Topic: messed up display (Read 512 times) previous topic - next topic

DWRIGHT02

when i run this sketch, get weird characters showing up, any suggestions?

Code: [Select]
void loop()
{
  while (digitalRead(buttonPin) == HIGH) //if the button is pushed, then do normal sweep
  {         
    for (pos = 0; pos < 180; pos += 1)
    {
     myservo.write(pos);              // tell servo to go to position in variable 'pos'
     delay(15);   
     Serial.println(pos);
     lcd.print(pos);
     lcd.print("current");
     delay(15);
     lcd.clear();
      if (pos == 0)
      {
        digitalWrite(ledPin, HIGH);
      }
      else
      {
        digitalWrite(ledPin, LOW);
      }
      if (pos > 1)
      {
        digitalWrite(ledPin1, HIGH);
      }
      else
      {
        digitalWrite(ledPin1, LOW);
      }
     
    }
    for (pos = 180; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees                           
    {
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
   delay(15); 
   Serial.println(pos);
   lcd.print(pos);
   lcd.print("current");
   delay(15); 

      // waits 15ms for the servo to reach the position                                 
      if (pos == 180)
      {
        digitalWrite(ledPin, HIGH);
      }
      else
      {
        digitalWrite(ledPin, LOW);
      }
      if (pos < 180)
      {
        digitalWrite(ledPin1, HIGH);
      }
      else
      {
        digitalWrite(ledPin1, LOW);
      }
    }
  }   
}

liudr


DWRIGHT02

Code: [Select]
#include <LiquidCrystal.h>
#include <Servo.h> 
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Servo myservo;  // create servo object to control a servo
volatile int state = HIGH; // value to show normal operation, anything else will cause interupt
int buttonPin = 6; // push button             
int pos = 0;    // variable to store the servo position
int lastValue = pos; // saves last known value for servo to display
int ledPin = 13;
int ledPin1 = 10;
int val;
void setup()
{
  val = pos;
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode (buttonPin, INPUT); // sets button as an input
  attachInterrupt(1, rest, FALLING); //sets interrupt to sense any change from HIGH. If it does then goes to void rest.
  Serial.begin(9600); // serial monitor
  lcd.begin(16, 2);
  myservo.attach(7);  // attaches the servo on pin 9 to the servo object       
  lcd.setCursor(0, 0);
}

void loop()
{
while (digitalRead(buttonPin) == HIGH) //if the button is pushed, then do normal sweep
{           
  for (pos = 0; pos < 180; pos += 1)
  {
   myservo.write(pos);              // tell servo to go to position in variable 'pos'
   delay(15);   
   Serial.println(pos);
   lcd.write(pos);
   lcd.print("current");
   delay(15);
   lcd.clear();
       if (pos == 0)
        {
          digitalWrite(ledPin, HIGH);
        }
        else
        {
          digitalWrite(ledPin, LOW);
        }
        if (pos > 1)
        {
          digitalWrite(ledPin1, HIGH);
        }
        else
        {
          digitalWrite(ledPin1, LOW);
        }
  }
  for (pos = 180; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees                           
  {
   myservo.write(pos);              // tell servo to go to position in variable 'pos'
   delay(15); 
   Serial.println(pos);
   lcd.write(pos);
   lcd.print("current");
   delay(15);   // waits 15ms for the servo to reach the position                                 
       if (pos == 180)
        {
           digitalWrite(ledPin, HIGH);
        }
        else
        {
          digitalWrite(ledPin, LOW);
        }
        if (pos < 180)
        {
          digitalWrite(ledPin1, HIGH);
        }
        else
        {
          digitalWrite(ledPin1, LOW);
        }
  }           
}   
}

void rest()
{
  while (digitalRead(buttonPin) == LOW)
{
   if (lastValue <= pos)
   {
  //Do Nothing
   }
   if (lastValue >= pos)
   {
   //Do Nothing
   }
}
}

floresta

#3
Apr 19, 2012, 08:22 pm Last Edit: Apr 19, 2012, 08:24 pm by floresta Reason: 1
Quote
when i run this sketch, ...

At what point in the sketch?

Quote
get weird characters showing up...

What did you expect to show up and what actually did show up?

Did any of the information for the LCD actually show up correctly or is all of it all messed up?


Don

liudr

Your code in your OP was different than your second code post, not just that the second post has complete code, but the code in loop() in your second post is slightly different from the code in the loop in the OP. Only two places. Since you wrote these codes, go find the differences (read line by line) and tell me what they are and I can tell you why you get gibberish.

Go Up