Need Help on Simple Sketch


i trying make when press button prints character onto lcd. happening right spams lcd character button pressed non-stop (only after press button too) here code have currently:

code: [select]
#include <liquidcrystal.h>
liquidcrystal lcd(12, 11, 5, 4, 3, 2);
const int ledpin = 13;
const int sendbutton = 6;
const int spacebutton = 7;
const int dashbutton = 8;
const int dotbutton = 9;
int man = 0;
string morsecode = "";
void setup()
{
  lcd.begin(16, 2);
  (int y = 6; y <= 9; y++)
  {
    pinmode(y, input);
  }
  pinmode(ledpin, output);
  lcd.setcursor(0, 0);
}
void loop()
{
  if (digitalread(sendbutton) == high)
  {
    (int x = 0; x < morsecode.length(); x++)
    {
      if (morsecode.charat(man) == '.')
      {
      digitalwrite(ledpin, high);
      delay(500);
      digitalwrite(ledpin, low);
      }
      else if (morsecode.charat(man) == '-')
     {
      digitalwrite(ledpin, high);
      delay(1500);
      digitalwrite(ledpin, low);
     }
     else if (morsecode.charat(man) == ' ')
     {
       delay(1500);
     }
     else if (morsecode.charat(man) == '   ')
     {
       delay(3500);
     }
     man = man + 1;
    }
    morsecode = "";
    man = 0;
    lcd.clear();
    lcd.setcursor(0, 0);
  }
  else if (digitalread(spacebutton) == high)
  {
    morsecode = morsecode + ' ';
  }
  else if (digitalread(dashbutton) == high)
  {
    morsecode = morsecode + '-';
  }
  else if (digitalread(dotbutton) == high)
  {
    morsecode = morsecode + '.';
  }
  if (morsecode.length() > 15)
  {
    lcd.setcursor(0, 2);
    lcd.print(morsecode);
  }
  else
  {
    lcd.print(morsecode);
  }
  delay(100);
}

 

this wrong:

code: [select]

   lcd.setcursor(0, 2);


you have 2 lines, line 0 , line 1.

i believe error, in:
code: [select]
  else
  {
    lcd.print(morsecode);
  }


change to:

code: [select]

  else
  {
     lcd.setcursor(0, 0);
     lcd.print(morsecode);
  }


and you'll fine!


Arduino Forum > Using Arduino > Programming Questions > Need Help on Simple Sketch


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support