Hi everyone.
This is my first post on any website ever. I am also new to Arduino. So I do not posses any online etiquete. Please be kind to a newbie.
My project is to use a 5110 lcd to show one text message at start up, wait 2 seconds then go blank.
The backlite is powered by pwm and should always stay on. Then when toggle switch1 is on: “NOS ACTIVE” should be displayed. And when toggle switch2 is on: “FAN ACTIVE” should be displayed.
I have been successful in doing one switch and one message. using either switch. However when I write both in to my sketch; I get no message from either switch.
I have used pieces and examples from other peoples sketches to get this far. But I can go no longer on my own.
I tried using 2 loops, ( which turns out you cant), 2 if statements, and other stuff. but to no avail.
This is a sketch that works
/*
This is a work in progress but hopefully it will help someone else by providing
a base to start and work from.
Please check out my Youtube videos here and consider a thumbs up if this helped you!
Youtube : http://www.youtube.com/mkmeorg
Website, Forum and store are at http://mkme.org
Pin 11 for PWM LCD backlight on the Nokia 5110
pin 7 - Serial clock out (SCLK)
pin 6 - Serial data out (DIN)
pin 5 - Data/Command select (D/C)
pin 4 - LCD chip select (CS)
pin 3 - LCD reset (RST)
*/
// constants won’t change. They’re used here to set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
#include “Adafruit_GFX.h”
#include “Adafruit_PCD8544.h”
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);//4 and 3 are reversed on the cheap eBay models
void setup() {
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
analogWrite(11,100);// PWM of LCD backlight but ebay unit is backwards-
//must go high + cycle to dim
//Very Dim=230
display.begin();//Display code
display.setContrast(50);//Nokia 5110 works best around 50- change to suit your unit
display.clearDisplay(); // clears the screen and buffer
display.setTextSize(1); // set text size
display.setTextColor(BLACK);
display.setCursor(0,0);//set cursor top left
display.println(“Silverado 1997”);//Prints the first line then a line break- leave off the ln characters to continue on the same line!
display.println(" Vortec 383");
display.println(" 4L80");
display.println(" NOS “);
display.println(“SUICIDE SQUAD”);
display.display();//this command writes all the preceeding info to the lcd
delay(2000);
display.clearDisplay(); // clears the screen and buffer
display.setCursor(0,0);//set cursor top left
display.println(”");//Prints the first line then a line break- leave off the ln characters to continue on the same line!
display.println("");
display.println("");
display.println("");
display.println("");
display.println("");
display.display();//this command writes all the preceeding info to the lcd
display.clearDisplay(); // clears the screen and buffer
}
// the loop routine runs over and over again forever:
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
display.setTextSize(4);
display.setTextColor(BLACK);
display.setCursor(8,0);//set cursor 8 pixels to right
display.println(“NOS”);//Prints the first line then a line break- leave off the ln characters to continue on the same line!
display.setCursor(7,32);//set cursor 8 pixels to right
display.setTextSize(2);
display.println(“ACTIVE”);
display.display();//this command writes all the preceeding info to the lcd
display.clearDisplay(); // clears the screen and buffer
} else {
display.setTextSize(1);
display.setCursor(0,0);//set cursor top left
display.println("");//Prints the first line then a line break- leave off the ln characters to continue on the same line!
display.println("");
display.println("");
display.println("");
display.println("");
display.println("");
display.display();//this command writes all the preceeding info to the lcd
}
}
I have tried it on the Uno, Mega and Nano just to be sure. this top sketch works on all of them.
This is a sketch that doesn’t work:
void setup() {
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
pinMode(buttonPin2, INPUT);
analogWrite(11,100);// PWM of LCD backlight but ebay unit is backwards-
//must go high + cycle to dim
//Very Dim=230
display.begin();//Display code
display.setContrast(50);//Nokia 5110 works best around 50- change to suit your unit
display.clearDisplay(); // clears the screen and buffer
display.setTextSize(1); // set text size
display.setTextColor(BLACK);
display.setCursor(0,0);//set cursor top left
display.println(“Silverado 1997”);//Prints the first line then a line break- leave off the ln characters to continue on the same line!
display.println(" Vortec 383");
display.println(" 4L80");
display.println(" NOS “);
display.println(“SUICIDE SQUAD”);
display.display();//this command writes all the preceeding info to the lcd
delay(2000);
display.clearDisplay(); // clears the screen and buffer
display.setCursor(0,0);//set cursor top left
display.println(”");//Prints the first line then a line break- leave off the ln characters to continue on the same line!
display.println("");
display.println("");
display.println("");
display.println("");
display.println("");
display.display();//this command writes all the preceeding info to the lcd
display.clearDisplay(); // clears the screen and buffer
}
// the loop routine runs over and over again forever:
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
buttonState = digitalRead(buttonPin2);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
display.setTextSize(4);
display.setTextColor(BLACK);
display.setCursor(8,0);//set cursor 8 pixels to right
display.println(“NOS”);//Prints the first line then a line break- leave off the ln characters to continue on the same line!
display.setCursor(7,32);//set cursor 8 pixels to right
display.setTextSize(2);
display.println(“ACTIVE”);
display.display();//this command writes all the preceeding info to the lcd
display.clearDisplay(); // clears the screen and buffer
}
else {
display.setTextSize(1);
display.setCursor(0,0);//set cursor top left
display.println("");//Prints the first line then a line break- leave off the ln characters to continue on the same line!
display.println("");
display.println("");
display.println("");
display.println("");
display.println("");
display.display();//this command writes all the preceeding info to the lcd
}
if(buttonState2 ==HIGH) {
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
display.setTextSize(4);
display.setTextColor(BLACK);
display.setCursor(8,0);//set cursor 8 pixels to right
display.println(“FAN”);//Prints the first line then a line break- leave off the ln characters to continue on the same line!
display.setCursor(7,32);//set cursor 8 pixels to right
display.setTextSize(2);
display.println(“ACTIVE”);
display.display();//this command writes all the preceeding info to the lcd
display.clearDisplay(); // clears the screen and buffer
}
else {
display.setTextSize(1);
display.setCursor(0,0);//set cursor top left
display.println("");//Prints the first line then a line break- leave off the ln characters to continue on the same line!
display.println("");
display.println("");
display.println("");
display.println("");
display.println("");
display.display();//this command writes all the preceeding info to the lcd
}
}
I am a tinkerer by nature but I never went past high school. I have no knowledge of coding except for what I have seen for Arduino on youtube.
Any help would be appreciated, but…very dummified help would be better.
Thanks to all.
unonano1.ino (3.47 KB)