Jump to content

Recommended Posts

Posted
On 10/3/2023 at 2:41 PM, Vinc_Vega said:

Update of the adjustable sketch for the SH1106 I2C OLED, including shrinked numbers (by 2 pixels in width and height each).

Graphics file see below for download, let me know if the numbers should be smaller.

  Reveal hidden contents
// I2C -OLED display for the F-16 Fuel Flow Counter @ Display 128 * 64 by Vinc_Vega
// adapted from the A-10 Fuel Counter by Middlefart (Original code)

#define DCSBIOS_IRQ_SERIAL

#include "DcsBios.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include "digits_22x30.h"

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1   //   QT-PY / XIAO
#define i2c_Address 0x3c //initialize with the I2C addr 0x3C Typically eBay OLED's

// ***** do your adjustments to the illuminated areas on the below variables *****
const byte BL = 20; // baseline for the scrolling digits (17 to meet the center of a 64 pixel height display for a 30 px height digit)
const byte TH = 15; // height of the top left and right rectangular areas to illuminate an engraved bezle
const byte TW1 = 45; // width of the top left rectangle
const byte TW2 = 45; // width of the top right rectangle
const byte BH = 5;  // height of the bottom center illuminated area
const byte BW = 40; // width of the bottom center rectangle

// ***** adjustment to the scrolling digits *****
const byte v_dist = 35; // vertical distance between two scrolling digits (must be more than 30 !!!)
const byte h_adj = 6;  // horizontal distance adjustment (0 alligns the display to the left, 6 centers the third digit to the display)

// temporary values (only for backlight calculations)
const byte digit_w = 22;  // width of a digit 
const byte digit_h = 30;  // hieght of a digit

// Fuel Quantity - OLED-Display
  struct scrollDigit {
    int digit; //The digit that is displayed
    int y; // The vertical position of the digit
  };
  
  struct disp {
    Adafruit_SH1106G display;
    int width;
    int numberOfDigits;
    scrollDigit digits[3];
  };

// for I2C interface
  disp oled = {Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET), 22, 3, {{-1,0},{0,0},{0,0}}};

//*****************************************

void setup() {

  DcsBios::setup();

  delay(250); // wait for the OLED to power up
  oled.display.begin(i2c_Address, true); // Address 0x3C default
  // oled.display.setContrast (1); // uncomment to use the dim option for the display
  oled.display.display();
  
}

//*****************************************

void UpdateDisplay()
{
  oled.display.clearDisplay();
  
  for (int i = 0; i < oled.numberOfDigits; i++)
  {
    printScrollingDigit(oled.digits[i].digit, oled.width, oled.digits[i].y, i + 1, &oled);
  }

  // print the right most two digits
  oled.display.drawBitmap((digit_w * 4) - digit_w + 4 + h_adj, BL, c22_0, digit_w, digit_h, 1);
  oled.display.drawBitmap((digit_w * 5) - digit_w + 5 + h_adj, BL, c22_0, digit_w, digit_h, 1);

    // draw backlights for engraved bezels
    oled.display.fillRect(0, 0, TW1, TH, SH110X_WHITE); // top left
    oled.display.fillRect(128 - TW2, 0, TW2, TH, SH110X_WHITE); // top right
    oled.display.fillRect(h_adj + (3* digit_w) - digit_w/2 - BW/2, 64 - BH, BW, BH, SH110X_WHITE); // bottom
  
  oled.display.display();
}

int YPos()
{
  return (oled.width + 9) * -1;
}

void printScrollingDigit(int digit, int width, int y, int pos, disp *oled)
{
  int x = ((width * pos) - width + pos ) + h_adj;
    switch (digit)
    {
      case -1: oled->display.drawBitmap(x, y+BL, c22_Empty, 22, 30, 1); oled->display.drawBitmap(x, y+v_dist+BL, c22_1, 22, 30, 1); break;
      case 0: oled->display.drawBitmap(x, y+BL-v_dist, c22_9, 22, 30, 1); oled->display.drawBitmap(x, y+BL, c22_0, 22, 30, 1); oled->display.drawBitmap(x, y+v_dist+BL, c22_1, 22, 30, 1); break;
      case 1: oled->display.drawBitmap(x, y+BL-v_dist, c22_0, 22, 30, 1); oled->display.drawBitmap(x, y+BL, c22_1, 22, 30, 1); oled->display.drawBitmap(x, y+v_dist+BL, c22_2, 22, 30, 1); break;	  
      case 2: oled->display.drawBitmap(x, y+BL-v_dist, c22_1, 22, 30, 1); oled->display.drawBitmap(x, y+BL, c22_2, 22, 30, 1); oled->display.drawBitmap(x, y+v_dist+BL, c22_3, 22, 30, 1); break;
      case 3: oled->display.drawBitmap(x, y+BL-v_dist, c22_2, 22, 30, 1); oled->display.drawBitmap(x, y+BL, c22_3, 22, 30, 1); oled->display.drawBitmap(x, y+v_dist+BL, c22_4, 22, 30, 1); break;
      case 4: oled->display.drawBitmap(x, y+BL-v_dist, c22_3, 22, 30, 1); oled->display.drawBitmap(x, y+BL, c22_4, 22, 30, 1); oled->display.drawBitmap(x, y+v_dist+BL, c22_5, 22, 30, 1); break;
      case 5: oled->display.drawBitmap(x, y+BL-v_dist, c22_4, 22, 30, 1); oled->display.drawBitmap(x, y+BL, c22_5, 22, 30, 1); oled->display.drawBitmap(x, y+v_dist+BL, c22_6, 22, 30, 1); break;
      case 6: oled->display.drawBitmap(x, y+BL-v_dist, c22_5, 22, 30, 1); oled->display.drawBitmap(x, y+BL, c22_6, 22, 30, 1); oled->display.drawBitmap(x, y+v_dist+BL, c22_7, 22, 30, 1); break;
      case 7: oled->display.drawBitmap(x, y+BL-v_dist, c22_6, 22, 30, 1); oled->display.drawBitmap(x, y+BL, c22_7, 22, 30, 1); oled->display.drawBitmap(x, y+v_dist+BL, c22_8, 22, 30, 1); break;
      case 8: oled->display.drawBitmap(x, y+BL-v_dist, c22_7, 22, 30, 1); oled->display.drawBitmap(x, y+BL, c22_8, 22, 30, 1); oled->display.drawBitmap(x, y+v_dist+BL, c22_9, 22, 30, 1); break;
      case 9: oled->display.drawBitmap(x, y+BL-v_dist, c22_8, 22, 30, 1); oled->display.drawBitmap(x, y+BL, c22_9, 22, 30, 1); oled->display.drawBitmap(x, y+v_dist+BL, c22_0, 22, 30, 1); break;
      default: oled->display.drawBitmap(x, y+BL-v_dist, c22_9, 22, 30, 1); oled->display.drawBitmap(x, y+BL, c22_0, 22, 30, 1); oled->display.drawBitmap(x, y+v_dist+BL, c22_1, 22, 30, 1); break;
    }

}

void onFuelflowcounter10kChange(unsigned int newValue)
  {
    unsigned int mappedValue = newValue / 6553;
    unsigned int y = map(newValue, mappedValue * 6553, mappedValue * 6553 + 6553, 0, YPos());
    
    if (mappedValue == 0)
    {
      oled.digits[0].digit = -1;
      oled.digits[0].y = 0;
    }
    else
    {
    oled.digits[0].digit = mappedValue;
    oled.digits[0].y = y;
    }
  }
  
  void onFuelflowcounter1kChange(unsigned int newValue)
  {
    unsigned int mappedValue = newValue / 6553;
    unsigned int y = map(newValue, mappedValue * 6553, mappedValue * 6553 + 6553, 0, YPos());
  
    oled.digits[1].digit = mappedValue;
    oled.digits[1].y = y;
  }
  
  void onFuelflowcounter100Change(unsigned int newValue)
  {
    unsigned int mappedValue = newValue / 6553;
    unsigned int y = map(newValue, mappedValue * 6553, mappedValue * 6553 + 6553, 0, YPos());
  
    oled.digits[2].digit = mappedValue;
    oled.digits[2].y = y;
  }
  
  DcsBios::IntegerBuffer fuelflowcounter10kBuffer(0x44e4, 0xffff, 0, onFuelflowcounter10kChange);
  DcsBios::IntegerBuffer fuelflowcounter1kBuffer(0x44e6, 0xffff, 0, onFuelflowcounter1kChange);
  DcsBios::IntegerBuffer fuelflowcounter100Buffer(0x44e8, 0xffff, 0, onFuelflowcounter100Change);

//*************************************************

void loop() {
  
  DcsBios::loop();
  UpdateDisplay();
}

 

Regards, Vinc

digits_22x30.h 6.66 kB · 3 downloads

 

You nailed it, Vinc. I couldn't have done that without you or taking an entire course in programming. Thanks so much. If I can help you in any way, just ask.

20231007_153433[4799].jpg

  • Thanks 1

GD ViperWorks - YouTube

F-16CM Block 50 Replica Sim Pit Construction

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...