//#include <Arduino.h>
// #include <Wire.h>
// #include <U8g2lib.h>
// // Initialize OLED
// //U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);
// U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // initialization for the used OLED display
// // Potentiometer pin
// #define POT_PIN A0
// void setup() {
// Serial.begin(9600);
// u8g2.begin();
// }
// void loop() {
// int potValue = analogRead(POT_PIN); // Read potentiometer value
// int mappedValue = map(potValue, 0, 1023, 0, 100); // Scale to 0-100%
// // Display potentiometer value on OLED
// u8g2.clearBuffer();
// u8g2.setFont(u8g2_font_6x10_tf);
// u8g2.drawStr(10, 30, "Pot Value:");
// u8g2.setCursor(80, 30);
// u8g2.print(mappedValue);
// u8g2.print("%");
// u8g2.sendBuffer();
// Serial.println(mappedValue); // Print value in Serial Monitor
// delay(100);
// }
//-----------------------------------------------
// #include <Wire.h>
// #include <U8g2lib.h>
// #define SCREEN_WIDTH 128 // OLED width
// #define SCREEN_HEIGHT 64 // OLED height
// U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
// int faderPins[4] = {A0, A1, A2, A3}; // Analog inputs for faders
// int faderValues[4] = {0, 0, 0, 0}; // Store fader values
// int barWidth = SCREEN_WIDTH / 4; // Each bar takes equal width
// void setup() {
// Serial.begin(9600);
// u8g2.begin();
// }
// void loop() {
// for (int i = 0; i < 4; i++) {
// faderValues[i] = analogRead(faderPins[i]);
// faderValues[i] = map(faderValues[i], 0, 1023, 0, SCREEN_HEIGHT);
// }
// u8g2.clearBuffer();
// for (int i = 0; i < 4; i++) {
// u8g2.drawBox(i * barWidth, SCREEN_HEIGHT - faderValues[i], barWidth - 2, faderValues[i]);
// }
// u8g2.sendBuffer();
// delay(100);
// }
//----------- perefect bars
// #include <Wire.h>
// #include <U8g2lib.h>
// #define SCREEN_WIDTH 128 // OLED width
// #define SCREEN_HEIGHT 64 // OLED height
// #define PADDING_BOTTOM 10 // Space for labels
// #define PADDING_TOP 8 // Space for values
// U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
// int faderPins[4] = {A0, A1, A2, A3}; // Analog inputs for faders
// int faderValues[4] = {0, 0, 0, 0}; // Store fader values
// int barWidth = SCREEN_WIDTH / 4; // Each bar takes equal width
// const char* labels[] = {"F1", "F2", "F3", "F4"}; // Labels for each fader
// void setup() {
// Serial.begin(9600);
// u8g2.begin();
// }
// void loop() {
// for (int i = 0; i < 4; i++) {
// faderValues[i] = analogRead(faderPins[i]);
// faderValues[i] = map(faderValues[i], 0, 1023, 1, 128); // Keep MIDI range
// }
// u8g2.clearBuffer();
// for (int i = 0; i < 4; i++) {
// int xPos = i * barWidth;
// int barHeight = SCREEN_HEIGHT - (faderValues[i] / 2) - PADDING_BOTTOM; // Scale bars correctly
// // Draw bar graph (ensuring no overlap with labels)
// u8g2.drawBox(xPos, barHeight, barWidth - 2, SCREEN_HEIGHT - barHeight - PADDING_BOTTOM);
// // Display fader value at the top (preventing overflow)
// u8g2.setFont(u8g2_font_6x10_tf);
// int valueTextPos = barHeight - PADDING_TOP; // Adjust position
// if (valueTextPos < PADDING_TOP) valueTextPos = PADDING_TOP; // Prevent hiding
// u8g2.setCursor(xPos + 5, valueTextPos);
// u8g2.print(faderValues[i]);
// // Add fader label at the bottom
// u8g2.setCursor(xPos + 10, SCREEN_HEIGHT - 2);
// u8g2.print(labels[i]);
// }
// u8g2.sendBuffer();
// delay(100);
// }
//-----bar patterns
#include <Wire.h>
#include <U8g2lib.h>
#define SCREEN_WIDTH 128 // OLED width
#define SCREEN_HEIGHT 64 // OLED height
#define PADDING_BOTTOM 10 // Space for labels
#define PADDING_TOP 8 // Space for values
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
int faderPins[4] = {A0, A1, A2, A3}; // Analog inputs for faders
int faderValues[4] = {0, 0, 0, 0}; // Store fader values
int barWidth = SCREEN_WIDTH / 4; // Each bar takes equal width
const char* labels[] = {"F1", "F2", "F3", "F4"}; // Labels for each fader
void setup() {
Serial.begin(9600);
u8g2.begin();
}
void loop() {
for (int i = 0; i < 4; i++) {
faderValues[i] = analogRead(faderPins[i]);
faderValues[i] = map(faderValues[i], 0, 1023, 0, 128); // Keep MIDI range
}
u8g2.clearBuffer();
for (int i = 0; i < 4; i++) {
int xPos = i * barWidth;
int barHeight = SCREEN_HEIGHT - (faderValues[i] / 2) - PADDING_BOTTOM; // Scale bars correctly
// Draw patterned bar using multiple horizontal lines
for (int y = barHeight; y < SCREEN_HEIGHT - PADDING_BOTTOM; y += 3) {
u8g2.drawLine(xPos, y, xPos + barWidth - 2, y);
}
// Display fader value at the top (preventing overflow)
u8g2.setFont(u8g2_font_6x10_tf);
int valueTextPos = barHeight - PADDING_TOP; // Adjust position
if (valueTextPos < PADDING_TOP) valueTextPos = PADDING_TOP; // Prevent hiding
u8g2.setCursor(xPos + 5, valueTextPos);
u8g2.print(faderValues[i]);
// Add fader label at the bottom
u8g2.setCursor(xPos + 10, SCREEN_HEIGHT - 2);
u8g2.print(labels[i]);
}
u8g2.sendBuffer();
delay(10);
}
Loading
cd74hc4067
cd74hc4067