Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding horizontal bargraph support with example avri2c sketch #103

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 68 additions & 0 deletions examples/bargraphAvrI2cExample/bargraphAvrI2cExample.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//Added by jonathanmlang
#include <Arduino.h>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiAvrI2c.h"

// 0X3C+SA0 - 0x3C or 0x3D
#define I2C_ADDRESS 0x3C

// Define proper RST_PIN if required.
#define RST_PIN -1

SSD1306AsciiAvrI2c oled;
//------------------------------------------------------------------------------

byte barLength =118; //total length of bar excluding ends
byte barVal =52; //value of bar
byte barNotch =10; //location of notch in bar

byte barXpos =5;
byte barYcol =5;

void setup() {

#if RST_PIN >= 0
oled.begin(&Adafruit128x64, I2C_ADDRESS, RST_PIN);
#else // RST_PIN >= 0
oled.begin(&Adafruit128x64, I2C_ADDRESS);
//oled.begin(&ST7567_128x64, I2C_ADDRESS);
#endif // RST_PIN >= 0



}

void drawBar(){

oled.setFont(bargraph);

oled.setCursor(barXpos-1,barYcol);

oled.print('b'); //small bar line to close the front of the bar

for (byte barPos=0; barPos < barLength; barPos++){
if (barPos == barNotch){
oled.print(barPos<barVal ? 'b' : 'e'); //if the bar position equals barNotch, draw the bar thinner to create a notch.
}
else{
oled.print(barPos<barVal ? 'a' : 'd'); //if the bar position is less than bar value, draw filled line else draw empty line
}
}
oled.print('b'); //small bar line to close the end of the bar

}

//------------------------------------------------------------------------------
void loop() {

oled.setFont(System5x7);
oled.setCursor(2,1);

oled.print("Bar value: "); oled.print(barVal); oled.print(" ");

drawBar();

barVal<barLength ? barVal++ : barVal=0;

delay(100);
}
1 change: 1 addition & 0 deletions src/fonts/allFonts.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ inline uint8_t readFontByte(uint8_t const *addr) { return *addr; }
*/
#include "cp437font8x8.h" // fixed Font from 80's IBM PC
#include "font8x8.h" // fixed wider font but similar to system5x7 font
#include "bargraph.h" // bargraph font

/*
* These fonts require UTF8 encoding support
Expand Down
21 changes: 21 additions & 0 deletions src/fonts/bargraph.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Added by jonathanmlang

#ifndef BARGRAPH_H
#define BARGRAPH_H

GLCDFONTDECL(bargraph) = {
0x0, 0x1, // size of one indicates fixed font width and no pixel padding
0x01, // width
0x08, // height
0x61, // first char a
0x05, // char count 7

0xFE, // a | //large bar line
0x7C, // b l //smaller bar line
0x00, // c // gap
0x82, // d : // empty bar
0x44, // e thin : //narrow empty bar

};

#endif