Nugroho's blog.: Read Digital Pin and Serial Message, Display it on LCD using Arduino

Thursday, April 30, 2015

Read Digital Pin and Serial Message, Display it on LCD using Arduino

 In addition of my previous tinkering with LCD on arduino nano, I add a chunk of program to display the state of digital pin 7 on second row LCD.

I also remove the scroll command, package it as separate function but not called. I plan to using another scrolling method, some code without delay. (had it in mind, but still lazy to coding it, maybe next)




#include <softwareSerial.h>
#include<liquidCrystal.h>
SoftwareSerial mySerial(8, 9); // RX, TX

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);//rs e d4 d5 d6 d7
String tulisan = "Tadaa...";
String info =":)";
void setup() {
pinMode(7,INPUT);
pinMode(6,OUTPUT);
pinMode(10,OUTPUT);
pinMode(13,OUTPUT);
lcd.begin(16, 2);
lcd.print(tulisan);
mySerial.begin(9600);
delay(1000);
}


void loop() {
if (digitalRead(7)==1){
digitalWrite(10,HIGH);
}else{
digitalWrite(10,LOW);
}
if (mySerial.available()){
lcd.clear();
digitalWrite(13,HIGH);
while(mySerial.available()>0){
lcd.setCursor(0,0);
tulisan=mySerial.readString();
mySerial.println(tulisan);
lcd.print(tulisan);
}
}

//scLeft();
//scRight();
//scDef();
info ="Pin7 = ";
info+=digitalRead(7);

lcd.setCursor(0,1);
lcd.print(info);
digitalWrite(13,LOW);
delay(1000);
}

void scLeft(){
for (int i = 0; i < tulisan.length(); i++) {
lcd.scrollDisplayLeft();
delay(150);
}
}

void scRight(){
for (int i = 0; i < (tulisan.length()+16); i++) {
lcd.scrollDisplayRight();
delay(150);
}
}

void scDef(){
for (int i = 0; i < 16; i++) {
lcd.scrollDisplayLeft();
delay(150);
}
}
//PWM: 3, 5, 6, 9, 10, and 11


.


Menulis perintah ke baris pertama LCD via bluetooth, baris kedua digunakan untuk mengecek pin 7 (digital). Fitur scrill (di post sebelumnya dihilangkan, ada di bawah sebagai function tetapi tak dipanggil di program utama)



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)