Tenho um arduino com ecrã 16x2 a funcionar com o código em baixo, devido a problema de espaço resolvi alterar o ecrã 16x2 para um ecrã de nokia 5110, o problema e agora não sei alterar o código para ele funcionar correctamente com este ecrã, agradeço a vossa ajuda.
O código é o seguinte:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int buttonPin = 8 ; // Pin onde está ligado o botão
int time = 300; // Tempo de detonação
int active = 0;
int buttonstate = 0;
// Melodia a ser tocada
int melody[] = {
262, 196,196, 220, 196,0, 247, 262};
int noteDurations[] = {
4, 8, 8, 4,4,4,4,4 };
void setup() {
pinMode(buttonPin, INPUT);
pinMode(13, OUTPUT);
// Linhas e Colunas do LCD:
lcd.begin(16, 2);
// Mensagem Primaria no LCD.
lcd.print("Power On.....");
}
void loop() {
buttonstate = digitalRead(buttonPin);
if (buttonstate == HIGH) {
switch (active)
{
case 0:
active = 1;
break;
case 1:
active = 0;
break;
default:
active = 0;
}
}
inicio:
delay(500);
switch (active)
{
case 0:
{
digitalWrite(13, LOW);
lcd.setCursor(0, 0);
lcd.print("StandBy....................."); // mensagem a ser mostrada quando a bomba está desactiva
lcd.setCursor(0, 7);
lcd.print(" JP Bombs");
time =300; // reset ao tempo da detonação
}
break;
case 1:
if (time > 0)
{
digitalWrite(13, HIGH); // Liga os Leds
lcd.setCursor(0, 0);
lcd.print("72 Virgens em"); // mensagem a ser mostrada quando a bomba está activa
lcd.setCursor(3, 7);
lcd.print(" ");
lcd.setCursor(3, 7);
lcd.print(time); // contagem decrescente
lcd.setCursor(7, 7);
lcd.print("Segundos ");
time = time - 1;
if (time > 30)
{
tone(6, 440, 200);
delay(200);
noTone(6);
buttonstate = digitalRead(buttonPin);
delay(800);
}
else
{
tone(6, 440, 200);
delay(100);
noTone(6);
buttonstate = digitalRead(buttonPin);
delay(100);
tone(6, 440, 200);
delay(100);
noTone(6);
buttonstate = digitalRead(buttonPin);
delay(100);
tone(6, 440, 200);
delay(100);
noTone(6);
buttonstate = digitalRead(buttonPin);
delay(100);
tone(6, 440, 200);
delay(100);
noTone(6);
buttonstate = digitalRead(buttonPin);
delay(100);
}
if (buttonstate == HIGH) {
active =0;
goto inicio;
}
}
else
{
// Mensagem exibida na detonação
lcd.setCursor(0, 0);
lcd.print("BOOOOOOOOMMMMMM");
lcd.setCursor(0, 7);
lcd.print("Beijinhos a Ala!");
// Aviso sonoro da detonação
for (int thisNote = 0; thisNote < 8; thisNote++) {
int noteDuration = 1000/noteDurations[thisNote];
tone(6, melody[thisNote],noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(6);
buttonstate = digitalRead(buttonPin);
if (buttonstate == HIGH) {
active =0;
goto inicio;
}
}
break;
}
}
}
O ecrã do 5110 testei com o seguinte código de exemplo e esta a funcionar bem.
#include <PCD8544.h>
// A custom glyph (a smiley)...
static const byte glyph[] = { B00010000, B00110100, B00110000, B00110100, B00010000 };
static PCD8544 lcd;
void setup() {
// PCD8544-compatible displays may have a different resolution...
lcd.begin(84, 48);
// Add the smiley to position "0" of the ASCII table...
lcd.createChar(0, glyph);
}
void loop() {
// Just to show the program is alive...
static int counter = 0;
// Write a piece of text on the first line...
lcd.setCursor(0, 0);
lcd.print("Hello, World!");
// Write the counter on the second line...
lcd.setCursor(0, 1);
lcd.print(counter, DEC);
lcd.write(' ');
lcd.write(0); // write the smiley
delay(500);
counter++;
}
Cumprimentos,
Flavio Reis