Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "U8glib.h"
- #include <stdlib.h>
- U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0); // I2C / TWI
- void drawGrid(void) {
- u8g.setFont(u8g_font_unifont);
- for (int i = 0; i < 10; i++)
- {
- for (int j = 0; j < 10; j++)
- {
- u8g.drawStr(0, 0, "@");
- }
- }
- }
- void setup(void) {
- // flip screen, if required
- // u8g.setRot180();
- // set SPI backup if required
- //u8g.setHardwareBackup(u8g_backup_avr_spi);
- // assign default color value
- if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
- u8g.setColorIndex(255); // white
- }
- else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
- u8g.setColorIndex(3); // max intensity
- }
- else if ( u8g.getMode() == U8G_MODE_BW ) {
- u8g.setColorIndex(1); // pixel on
- }
- else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
- u8g.setHiColorByRGB(255, 255, 255);
- }
- Serial.begin(9600);
- }
- void draw(char nums[4]) {
- // graphic commands to redraw the complete screen should be placed here
- //u8g.setFont(u8g_font_helvB12);
- u8g.setFont(u8g_font_fub30);
- u8g.drawStr( 30, 40, nums);
- u8g.setFont(u8g_font_profont17);
- u8g.drawStr(35, 55, "km/h");
- }
- void loop(void) {
- char nums[4];
- 8g.firstPage();
- do {
- if (Serial.available())
- {
- Serial.readBytesUntil('#', nums, 4);
- nums[3] = '\0';
- draw(nums);
- }
- } while ( u8g.nextPage() );
- // rebuild the picture after some delay
- // nope - MrOsamaful
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement