Hi
For some reasons this program is displaying U1 2 times, i.e.
I have 3 rows.
U1
U2
U1
should be 2.
U1
U2
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
//``````Adafruit_SSD1306 display(OLED_RESET);
TwoWire Wire2 (2, I2C_FAST_MODE); // PB10, PB11
#define Wire Wire2
#define OLED_RESET 4
Adafruit_SSD1306 display(128, 32, &Wire, 4);
int analog_value1 = 0;
int U1 = 0;
int analog_value2 = 0;
int U2 = 0;
void setup() {
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
Serial.begin(115200);
}
void loop() {
analog_value1 = analogRead(PA6);
U1 = (analog_value1 * 3.3) / 4.096;
analog_value2 = analogRead(PA7);
U2 = (analog_value2 * 3.3) / 4.096;
display.clearDisplay();
drawPercentbar( 0, 0, 128, 15, analogRead(PA1) / 40);
drawPercentbar( 0, 20, 128, 15, analogRead(PA2) / 40);
display.display();
delay(100);
}
void drawPercentbar(int x, int y, int width, int height, int progress)
{
//progress = progress > 100 ? 100 : progress;
progress = progress > 128 ? 128 : progress;
progress = progress < 0 ? 0 : progress;
float bar = ((float)(width - 4) / 100) * progress;
//display.drawRect(x, y, width, height, WHITE);
display.fillRect(x + 2, y + 2, bar , height - 4, WHITE);
// Display progress text
if ( height >= 10) {
display.setCursor((width / 2) - 3, y + 5 );
display.setTextSize(1);
display.setTextColor(WHITE);
if ( progress >= 50)
display.setTextColor(BLACK, WHITE); // 'inverted' text
display.print(U1 );
////////////////
display.setCursor((width / 2) - 3, y + 15 );
display.print(U2);
////////////////
}
}