Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

Arduino LCDディスプレイを表示してみる

電子工作における表示の王道、LCD

実際のところ

左いって右に戻るサンプルは、以下の通り。
使ったハードは相当古いLCDシールドですが、レイアウトは今でもあんまり変わってないようです。
そのまま使えるでしょう。

#include <LiquidCrystal.h>

#define LCD_WIDTHS 16
#define STR_WIDTHS stringWidth

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int stringWidth = 0;

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(LCD_WIDTHS, 2);
  // Print a message to the LCD.
  String str = "hello, world!";
  stringWidth = str.length();
  lcd.print(str);
}

void loop() {
  swipeLeft();
  backRight();
  delay(3000);
}

void backRight() {
   for (int positionCounter = 0; positionCounter < STR_WIDTHS; positionCounter++) {
    // scroll one position left:
    lcd.scrollDisplayRight();
    // wait a bit:
    delay(150);
  } 
}

void swipeLeft() {
    for (int positionCounter = 0; positionCounter < STR_WIDTHS; positionCounter++) {
    // scroll one position right:
    lcd.scrollDisplayLeft();
    // wait a bit:
    delay(150);
  }
}