Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
1.2 kB
4
Indexable
void draw() {
  static int8_t counter = 0;

  boolean blinker = blinkingValue();

  int pinWidth = 1;
  int pinHeight = height_ / 3;
  int batteryHeight = height_ - 2;
  int batteryFillWidth = map(batteryLevel_, 0, 100, 0, width_ - 2);

  if (counter > -1) counter--;
  else counter = batteryFillWidth;

  if (isCharging_) {
    display_.fillRect(x_ + width_, y_ + height_ / 2 - pinHeight / 2, pinWidth, pinHeight, WHITE);  // Draw the positive pin of the battery
    display_.drawRect(x_, y_, width_, height_, WHITE);                                             // Draw the outlay of the battery
    display_.fillRect(x_ + 1, y_ + 1, batteryFillWidth - counter, batteryHeight, WHITE);           // Draw the fill of the battery
  } else {
    display_.fillRect(x_ + width_, y_ + height_ / 2 - pinHeight / 2, pinWidth, pinHeight, batteryFillWidth ? WHITE : blinker);  // Draw the positive pin of the battery
    display_.drawRect(x_, y_, width_, height_, batteryFillWidth ? WHITE : blinker);  // Draw the outlay of the battery
    display_.fillRect(x_ + 1, y_ + 1, batteryFillWidth, batteryHeight, WHITE);       // Draw the fill of the battery
  }
  display_.display();
}