Pages: [1]   Go Down
Author Topic: messed up display  (Read 422 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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);
      }
    }
  }   
}
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What is pos?
Logged


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

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

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 32
Posts: 4259
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: April 19, 2012, 01:24:02 pm by floresta » Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Pages: [1]   Go Up
Jump to: