Last active
December 16, 2015 00:09
-
-
Save Duckle29/5345368 to your computer and use it in GitHub Desktop.
A function for making progress bars on the arduino. Plenty of bugs to work out, but not necessarily deal breaking. Further explanation in the comments, since github doesn't allow github markdown in the description.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| byte bar1[8] = { | |
| 0b10000, | |
| 0b10000, | |
| 0b10000, | |
| 0b10000, | |
| 0b10000, | |
| 0b10000, | |
| 0b10000, | |
| 0b10000 | |
| }; | |
| byte bar2[8] = { | |
| 0b11000, | |
| 0b11000, | |
| 0b11000, | |
| 0b11000, | |
| 0b11000, | |
| 0b11000, | |
| 0b11000, | |
| 0b11000 | |
| }; | |
| byte bar3[8] = { | |
| 0b11100, | |
| 0b11100, | |
| 0b11100, | |
| 0b11100, | |
| 0b11100, | |
| 0b11100, | |
| 0b11100, | |
| 0b11100 | |
| }; | |
| byte bar4[8] = { | |
| 0b11110, | |
| 0b11110, | |
| 0b11110, | |
| 0b11110, | |
| 0b11110, | |
| 0b11110, | |
| 0b11110, | |
| 0b11110 | |
| }; | |
| byte bar5[8] = { | |
| 0b11111, | |
| 0b11111, | |
| 0b11111, | |
| 0b11111, | |
| 0b11111, | |
| 0b11111, | |
| 0b11111, | |
| 0b11111 | |
| }; | |
| void progBar(LiquidCrystal lcd, int percent, int parts, int subparts) | |
| { | |
| int totalParts = subparts * parts; | |
| int segmentProgress = totalParts * percent / 100; | |
| int x = segmentProgress / subparts; | |
| for(int i=0; i<x; i++) | |
| { | |
| lcd.write((byte)4); | |
| } | |
| switch(segmentProgress % subparts) | |
| { | |
| case 0: | |
| break; | |
| case 1: | |
| lcd.write((byte)0); | |
| break; | |
| case 2: | |
| lcd.write((byte)1); | |
| break; | |
| case 3: | |
| lcd.write((byte)2); | |
| break; | |
| case 4: | |
| lcd.write((byte)3); | |
| break; | |
| } | |
| int z = parts-x; | |
| Serial.println(z); | |
| for(int i=0; i<z; i++) | |
| { | |
| lcd.print(" "); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
List of known bugs:
Usage:
To use this function you first need to set up the custom characters. All you need to do is to go to your setup function, and do:
lcd.createChar(0, bar1);
lcd.createChar(1, bar2);
do that for bar3, 4, and 5 too.