Nugroho's blog.: Displaying and Scrolling Text Typed via Serial Monitor on Arduino Nano

Monday, April 27, 2015

Displaying and Scrolling Text Typed via Serial Monitor on Arduino Nano

 Here we go. The challenge is reading serial data and store it in string, but fortunately there is readString command, :)

(I take the shoot from Photo Booth on my Mac)




#include <LiquidCrystal.h>

.
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);//rs e d4 d5 d6 d7
String tulisan = "Tadaa...";
void setup() {
lcd.begin(16, 2);
lcd.print(tulisan);
Serial.begin(9600);
delay(1000);
}

void loop() {
if (Serial.available()){
lcd.clear();
while(Serial.available()>0){
tulisan=Serial.readString();
lcd.print(tulisan);
}
}
// scroll 13 positions (string length) to the left
// to move it offscreen left:
for (int i = 0; i < tulisan.length(); i++) {
// scroll one position left:
lcd.scrollDisplayLeft();
// wait a bit:
delay(150);
}

// scroll 29 positions (string length + display length) to the right
// to move it offscreen right:
for (int i = 0; i < (tulisan.length()+16); i++) {
// scroll one position right:
lcd.scrollDisplayRight();
// wait a bit:
delay(150);
}

// scroll 16 positions (display length + string length) to the left
// to move it back to center:
for (int i = 0; i < 16; i++) {
// scroll one position left:
lcd.scrollDisplayLeft();
// wait a bit:
delay(150);
}

// delay at the end of the full loop:
delay(1000);

}

.


Menampilkan dan men-scroll text yang diketik menggunakan monitor serial di arduino nano.

Tantangannya adalah membaca serial data dan menyimpannya sebagai string. Di versi lama, kita harus membaca komunikai serial sebagai char yang tentu saja sangat merepotkan. Untungnya kita mempunyai perintah readString, :)

No comments:

323f (5) amp (1) android (12) apple (7) arduino (18) art (1) assembler (21) astina (4) ATTiny (23) blackberry (4) camera (3) canon (2) cerita (2) computer (106) crazyness (11) debian (1) delphi (39) diary (286) flash (8) fortran (6) freebsd (6) google apps script (8) guitar (2) HTML5 (10) IFTTT (7) Instagram (7) internet (12) iOS (5) iPad (6) iPhone (5) java (1) javascript (1) keynote (2) LaTeX (6) lazarus (1) linux (29) lion (15) mac (28) macbook air (8) macbook pro (3) macOS (1) Math (3) mathematica (1) maverick (6) mazda (4) microcontroler (35) mountain lion (2) music (37) netbook (1) nugnux (6) os x (36) php (1) Physicist (29) Picture (3) programming (189) Python (109) S2 (13) software (7) Soliloquy (125) Ubuntu (5) unix (4) Video (8) wayang (3) yosemite (3)