Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elktros/f5f301cd51495692fb9ebe25f575d90f to your computer and use it in GitHub Desktop.
Save elktros/f5f301cd51495692fb9ebe25f575d90f to your computer and use it in GitHub Desktop.
Adjust contrast of Nokia 5110 LCD using ESP8266 NodeMCU board and a Potentiometer.
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#define analogPin A0 /* ESP8266 Analog Pin ADC0 = A0 */
/* Declare LCD object for SPI
Adafruit_PCD8544(CLK,DIN,D/C,CE,RST);*/
Adafruit_PCD8544 display = Adafruit_PCD8544(14, 13, 5, 15, 4); /*D5, D7, D1, D8, D2 */
int contrastValue = 60; /* Default Contrast Value */
int adcValue = 0; /* Variable to store Output of ADC */
void setup()
{
/* Initialize the Display*/
display.begin();
/* Change the contrast using the following API*/
display.setContrast(contrastValue);
/* Clear the buffer */
display.clearDisplay();
display.display();
delay(100);
/* Now let us display some text */
display.setTextColor(WHITE, BLACK);
display.setTextSize(1);
display.setCursor(15,1);
display.println("|ESP8266|");
display.setCursor(15,13);
display.println("|NodeMCU|");
//display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(22,25);
display.println("|Nokia|");
display.setCursor(25,37);
display.println("|5110|");
display.display();
//delay(2000);
}
void loop()
{
adcValue = analogRead(analogPin);
contrastValue = map(adcValue, 0, 1023, 0, 100);
setContrast();
//displayText();
}
void setContrast()
{
display.setContrast(contrastValue);
display.display();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment