Last active
August 29, 2015 14:23
-
-
Save igr-santos/d5018af0c1c7b72692cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
LiquidCrystal Library - Hello World | |
Demonstrando o uso de um display LCD 16x2. A biblioteca LiquidCrystal | |
funciona com todos os displays LCD que forem compativeis com o driver | |
Hitachi HD44780. | |
Esse programa imprime "Hello World!" no LCD | |
O circuito: | |
- LCD RS: digital 12 | |
- LCD Enable: digital 11 | |
- LCD D4: digital 5 | |
- LCD D5: digital 4 | |
- LCD D6: digital 3 | |
- LCD D7: digital 2 | |
- LCD R/W: Ground (Terra) | |
- Resistor de 10k | |
- +5v a Ground (Terra) | |
- LCD VO: digital 3 | |
*/ | |
#include <LiquidCrystal.h> | |
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); | |
String message; | |
void setup() { | |
Serial.begin(9600); | |
Serial.println("Serial conection started, waiting for instruction"); | |
lcd.begin(16, 2); | |
} | |
int getX(int x) { | |
if (x == 15) { | |
return 0; | |
} | |
return x+1; | |
} | |
int getY(int x, int y) { | |
if (x == 15 && y == 1) { | |
lcd.begin(16, 2); | |
return 0; | |
} else if (x == 15 && y == 0) { | |
return 1; | |
} | |
return y; | |
} | |
void loop() { | |
while (Serial.available() == 0) { | |
} | |
lcd.begin(16, 2); | |
message = Serial.readString(); | |
int index = 0; | |
int x = 0; | |
int y = 0; | |
while (index < message.length()) { | |
lcd.setCursor(x, y); | |
lcd.print(message.charAt(index)); | |
index += 1; | |
y = getY(x, y); | |
x = getX(x); | |
delay(125); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment