Skip to content

Instantly share code, notes, and snippets.

@elktros
Created February 27, 2021 08:48
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/b68f309b099a1fd9709ac3ff294f739f to your computer and use it in GitHub Desktop.
Save elktros/b68f309b099a1fd9709ac3ff294f739f to your computer and use it in GitHub Desktop.
Set contrast of Nokia 5110 LCD using POT and ESP32.
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
/* Declare LCD object for SPI
Adafruit_PCD8544(CLK, DIN, D/C, CE, RST); */
Adafruit_PCD8544 display = Adafruit_PCD8544(18, 23, 4, 15, 2);
int contrastValue = 57; // Default Contrast Value
const int adcPin = 34;
int adcValue = 0;
void setup()
{
/* Initialize the Display*/
display.begin();
/* Change the contrast using the following API*/
display.setContrast(contrastValue);
displayText();
delay(1000);
}
void loop()
{
adcValue = analogRead(adcPin);
contrastValue = map(adcValue, 0, 4095, 0, 100);
setContrast();
displayText();
}
void setContrast()
{
display.setContrast(contrastValue);
//display.display();
}
void displayText()
{
display.clearDisplay();
display.setTextColor(WHITE, BLACK);
display.setCursor(0,1);
display.setTextSize(2);
display.print("|ESP32|");
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(8,22);
display.print("SET CONTRAST");
display.drawFastHLine(0,32,83,BLACK);
display.setCursor(5, 38);
display.print("Value: ");
display.setCursor(40,38);
display.print(contrastValue);
display.display();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment