Skip to content

Instantly share code, notes, and snippets.

@JeffersGlass
Created May 3, 2020 19:44
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 JeffersGlass/d00082c8df1bf931befaf706e9ae6b75 to your computer and use it in GitHub Desktop.
Save JeffersGlass/d00082c8df1bf931befaf706e9ae6b75 to your computer and use it in GitHub Desktop.
/*
LiquidCrystal Library - Hello World
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 8, en = 9, d4 = 10, d5 = 11, d6 = 12, d7 = 13;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
byte character[8][8];
int peakPosition = 8;
int buttonUp = 3;
int buttonDown = 2;
long lastButtonPressTime = 0;
long minButtonDelay = 100;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
//showColors();
lcd.noCursor();
lcd.noBlink();
customChars();
lcd.setCursor(0,0);
pinMode(buttonUp, INPUT_PULLUP);
pinMode(buttonDown, INPUT_PULLUP);
redraw();
}
void loop() {
for (int i = 0; i <= 15; i++){
peakPosition = i;
redraw();
delay(50);
}
delay(50);
for (int i = 15; i >= 0; i--){
peakPosition = i;
redraw();
delay(50);
}
delay(50);
}
void redraw(){
lcd.clear();
lcd.setCursor(2,0);
lcd.print("DO THE WAVE");
lcd.setCursor(peakPosition, 1);
lcd.write(byte(7));
for (int i = peakPosition-1; i >= 0; i--){
lcd.setCursor(i, 1);
lcd.write(max(7-abs(peakPosition-i), 0));
}
for (int i = peakPosition+1; i <=15; i++){
lcd.setCursor(i, 1);
lcd.write(max(7-abs(peakPosition-i), 0));
}
}
void customChars(){
for (int charNum = 0; charNum < 8; charNum++){
for (int row = 0; row < 8; row++){
if (row >= 7-charNum) character[charNum][row] = B111111;
else character[charNum][row] = B00000;
}
lcd.createChar(charNum, character[charNum]);
}
/*for (int charNum = 0; charNum < 8; charNum++){
for (int col = 0; col < 5; col++){
character[charNum][7-charNum] = B11111;
}
lcd.createChar(charNum, character[charNum]);
}*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment