// simple project using Arduino UNO and 128x64 SSD1306 IIC OLED Display, created by upir, 2023
// youtube channel: https://www.youtube.com/upir_upir
// YOUTUBE VIDEO: https://youtu.be/Eyvzw_ujcS0
// More videos with Arduino UNO and OLED screens: https://www.youtube.com/playlist?list=PLjQRaMdk7pBZ1UV3IL5ol8Qc7R9k-kwXA
#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h> // library requires for IIC communication
int ledblue = 3;
int ledRed = 5;
int button = 0; // variable to store the read value
int button2 = 0; // variable to store the read value
int speedINT = 0;
char buffer[4]; // variable to store the read value
int DMG1 = 0;
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // initialization for the used OLED display
static const unsigned char image_Down_hvr_bits[] U8X8_PROGMEM = {0xf8,0xff,0x3f,0x00,0xfc,0xff,0x7f,0x00,0xfe,0xff,0xff,0x00,0xff,0xff,0xff,0x01,0xff,0xff,0xff,0x01,0xff,0xff,0xff,0x01,0xff,0xff,0xff,0x01,0xff,0xff,0xff,0x01,0xff,0xff,0xff,0x01,0x0f,0x00,0xe0,0x01,0x0f,0x00,0xe0,0x01,0x1f,0x00,0xf0,0x01,0x3f,0x00,0xf8,0x01,0x7f,0x00,0xfc,0x01,0xff,0x00,0xfe,0x01,0xff,0x01,0xff,0x01,0xff,0x83,0xff,0x01,0xff,0xc7,0xff,0x01,0xff,0xef,0xff,0x01,0xff,0xff,0xff,0x01,0xff,0xff,0xff,0x01,0xff,0xff,0xff,0x01,0xff,0xff,0xff,0x01,0xff,0xff,0xff,0x01,0xfe,0xff,0xff,0x00,0xfc,0xff,0x7f,0x00,0xf8,0xff,0x3f,0x00};
static const unsigned char image_Up_hvr_bits[] U8X8_PROGMEM = {0xf8,0xff,0x3f,0x00,0xfc,0xff,0x7f,0x00,0xfe,0xff,0xff,0x00,0xff,0xff,0xff,0x01,0xff,0xff,0xff,0x01,0xff,0xff,0xff,0x01,0xff,0xff,0xff,0x01,0xff,0xef,0xff,0x01,0xff,0xc7,0xff,0x01,0xff,0x83,0xff,0x01,0xff,0x01,0xff,0x01,0xff,0x00,0xfe,0x01,0x7f,0x00,0xfc,0x01,0x3f,0x00,0xf8,0x01,0x1f,0x00,0xf0,0x01,0x0f,0x00,0xe0,0x01,0x0f,0x00,0xe0,0x01,0xff,0xff,0xff,0x01,0xff,0xff,0xff,0x01,0xff,0xff,0xff,0x01,0xff,0xff,0xff,0x01,0xff,0xff,0xff,0x01,0xff,0xff,0xff,0x01,0xff,0xff,0xff,0x01,0xfe,0xff,0xff,0x00,0xfc,0xff,0x7f,0x00,0xf8,0xff,0x3f,0x00};
void setup(void) {
u8g2.begin(); // start the u8g2 library
pinMode(2, INPUT_PULLUP);
pinMode(3, OUTPUT);
pinMode(4, INPUT_PULLUP);
pinMode(5, OUTPUT);
pinMode(7, INPUT_PULLUP);
}
void loop(void) {
u8g2.clearBuffer(); // clear the internal memory
u8g2.setBitmapMode(1);
u8g2.setFontMode(1);
u8g2.drawXBMP(2, 21, 25, 27, image_Down_hvr_bits);
u8g2.drawXBMP(2, -1, 25, 27, image_Up_hvr_bits);
u8g2.setFont(u8g2_font_logisoso42_tr);
sprintf(buffer, "%d", speedINT);
u8g2.drawStr(44, 46, buffer);
u8g2.sendBuffer(); // transfer internal memory to the display
button = digitalRead(2); // read the input pin
button2 = digitalRead(4); // read the input pin
DMG1 = digitalRead(7);
if (button == LOW )
if (speedINT < 6) speedINT = speedINT + 1;
if (button2 == LOW )
if (speedINT > 0) speedINT = speedINT - 1;
if (button == LOW )
{
digitalWrite(ledblue, HIGH);
} else
{
digitalWrite(ledblue, LOW);
}
if (button2 == LOW )
{
digitalWrite(ledRed, HIGH);
} else
{
digitalWrite(ledRed, LOW);
}
}