• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
OLED
#1
Witam
Ten program wyświetla U1 dwa razy, a powinien raz.
Mam 3 rzędy
U1
U2
U1
Powinno być 2
U1
U2


Kod:
//https://github.com/makertut/oled-progressbar
//https://www.youtube.com/watch?v=Xb4rAxsjavo
#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);
    ////////////////

  }
}
 
Odpowiedź
  


Wiadomości w tym wątku
OLED - przez zak - 23-01-2024, 14:04
RE: OLED - przez Irvin - 23-01-2024, 14:45
RE: OLED - przez zak - 23-01-2024, 17:36
RE: OLED - przez oscarX - 23-01-2024, 18:00
RE: OLED - przez zak - 23-01-2024, 18:11
RE: OLED - przez oscarX - 23-01-2024, 23:33

Skocz do:


Przeglądający: 1 gości