Skip to content

Instantly share code, notes, and snippets.

@JeffersGlass
Created May 3, 2020 19:43
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/512416bca5d2c517024fa2dd8068286a to your computer and use it in GitHub Desktop.
Save JeffersGlass/512416bca5d2c517024fa2dd8068286a to your computer and use it in GitHub Desktop.
// 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[6][8];
int count = 0;
int delayTime = 50;
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();
randomSeed(analogRead(A0));
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Loading...");
}
void loop() {
if (random(0, 100) > 90){
count = (count + 1) % 80;
drawProgressBar(count);
}
delay(12);
}
void drawProgressBar(int pos){
int fullBlocks = pos / 5;
int partialBlocks = pos - (fullBlocks * 5);
for (int i = 0; i < fullBlocks; i++){
lcd.setCursor(i, 1);
lcd.write(byte(5));
}
lcd.setCursor(fullBlocks, 1);
lcd.write(byte(partialBlocks));
for (int i = fullBlocks+1; i <16; i++){
lcd.setCursor(i, 1);
lcd.write(byte(0));
}
}
void customChars(){
for (int charNum = 0; charNum < 6; charNum++){
for (int row = 0; row < 8; row++){
character[charNum][row] = B00000;
for (int col = 0; col < charNum; col++){
character[charNum][row] += B1 << (4-col);
}
}
lcd.createChar(charNum, character[charNum]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment