JohnnyChicago Posted April 29, 2023 Posted April 29, 2023 /* DCS F-16 Pitch Trim Display by JohnnyChicago / Special Thanks to Vinc_Vega !! Arduino Nano / Oled SSD1306 128x64 Pixel DCS-BIOS Fork Version This sketch can be easily changed to display Roll Trim I am not a profi programmer and this sketch must be improved, but for now it works. */ #define DCSBIOS_DEFAULT_SERIAL #include "DcsBios.h" #include "U8glib.h" U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0); int xmax = 128; int ymax = 64; int xcenter = xmax / 2; int ycenter = ymax / 2 + 16; int arc = ymax / 1.5; int angle = 0; int m = 10; u8g_uint_t xx = 0; int pitch = 90; void onPitchtrimindChange(unsigned int newValue) { pitch = map(newValue, 0, 65535, 0, 1050); m = map(pitch, 0, 1023, 0, 90); // show needle and dial xx = m; if (xx < 45) { xx = xx + 135; } else { xx = xx - 45; } } DcsBios::IntegerBuffer pitchtrimindBuffer(0x44d2, 0xffff, 0, onPitchtrimindChange); void gauge(uint8_t angle) { // draw border of the gauge u8g.drawCircle(xcenter, ycenter, arc + 6, U8G_DRAW_UPPER_RIGHT); u8g.drawCircle(xcenter, ycenter, arc + 6, U8G_DRAW_UPPER_LEFT); // draw the needle float x1 = sin(2 * angle * 2 * 3.14 / 360); float y1 = cos(2 * angle * 2 * 3.14 / 360); u8g.drawLine(xcenter, ycenter, xcenter + arc * x1, ycenter - arc * y1); // draw center point u8g.drawDisc(xcenter, ycenter, 2, U8G_DRAW_UPPER_LEFT); u8g.drawDisc(xcenter, ycenter, 2, U8G_DRAW_UPPER_RIGHT); // show scale u8g.drawDisc(25, 45, 2); u8g.drawDisc(30, 30, 2); u8g.drawDisc(43, 15, 2); u8g.drawDisc(61, 7, 2); u8g.drawDisc(63, 7, 2); u8g.drawDisc(66, 7, 2); u8g.drawDisc(86, 15, 2); u8g.drawDisc(96, 30, 2); u8g.drawDisc(104, 45, 2); } void setup(void) { DcsBios::setup(); //u8g.setColorIndex(1); } void loop(void) { { u8g.firstPage(); do { gauge(xx); } while (u8g.nextPage()); } DcsBios::loop(); } Hi there, Here is a working sketch do display the F-16 Roll or Pitch Trim Settings on a Oled 1306 Display. Code must be improved as i am not a profi programmer ! Have fun 1
JohnnyChicago Posted May 5, 2023 Author Posted May 5, 2023 Spoiler /* DCS-F16 Pitch and Roll Trim Display by JohnnyChicago 2 x Oled SSD1106 128x64 HW SPI on one Arduino Nano DCS-Bios Fork */ #define DCSBIOS_DEFAULT_SERIAL #include "DcsBios.h" #include <U8g2lib.h> #include <SPI.h> U8G2_SH1106_128X64_NONAME_F_4W_HW_SPI OLED1(U8G2_R0, /* cs=*/10, /* dc=*/8, /* reset=*/9); U8G2_SH1106_128X64_NONAME_F_4W_HW_SPI OLED2(U8G2_R0, /* cs=*/4, /* dc=*/7, /* reset=*/5); float gs_rad; //stores angle from where to start in radinats float ge_rad; //stores angle where to stop in radinats //example values for testing, use the values you wish to pass as argument while calling the function byte cx = 64; //x center byte cy = 64; //y center byte radius = 63; //radius byte percent = 80; //needle percent int t, c, c1 = 0; int n = 50; //needle lenghth or int n = (r / 100.00) * p; // calculate needle percent lenght void Drawgauge(int x, byte y, byte r, byte p, int v, int minVal, int maxVal) { OLED1.firstPage(); do { float gs_rad = -1.572; float ge_rad = 1.572; float i = ((v - minVal) * (ge_rad - gs_rad) / (maxVal - minVal) + gs_rad); int xp = x + (sin(i) * n); int yp = y - (cos(i) * n); //OLED1.drawCircle(x, y, r, U8G2_DRAW_UPPER_LEFT | U8G2_DRAW_UPPER_RIGHT); OLED1.drawLine(x - 1, y, xp, yp); OLED1.drawLine(x + 1, y, xp, yp); OLED1.drawDisc(15, 50, 2); OLED1.drawDisc(22, 30, 2); OLED1.drawDisc(33, 15, 2); OLED1.drawDisc(61, 7, 2); OLED1.drawDisc(63, 7, 2); OLED1.drawDisc(66, 7, 2); OLED1.drawDisc(93, 15, 2); OLED1.drawDisc(108, 30, 2); OLED1.drawDisc(115, 50, 2); } while (OLED1.nextPage()); } void Drawgauge1(int x, byte y, byte r, byte p, int v, int minVal, int maxVal) { OLED2.firstPage(); do { float gs_rad = -1.572; float ge_rad = 1.572; float i = ((v - minVal) * (ge_rad - gs_rad) / (maxVal - minVal) + gs_rad); int xp = x + (sin(i) * n); int yp = y - (cos(i) * n); //OLED2.drawCircle(x, y, r, U8G2_DRAW_UPPER_LEFT | U8G2_DRAW_UPPER_RIGHT); OLED2.drawLine(x - 1, y, xp, yp); OLED2.drawLine(x + 1, y, xp, yp); OLED2.drawDisc(15, 50, 2); OLED2.drawDisc(22, 30, 2); OLED2.drawDisc(33, 15, 2); OLED2.drawDisc(61, 7, 2); OLED2.drawDisc(63, 7, 2); OLED2.drawDisc(66, 7, 2); OLED2.drawDisc(93, 15, 2); OLED2.drawDisc(108, 30, 2); OLED2.drawDisc(115, 50, 2); } while (OLED2.nextPage()); } void onPitchtrimindChange(unsigned int newValue) { c = map(newValue, 0, 65535, 5, 95); Drawgauge(cx, cy, radius, percent, c, 0, 99); } DcsBios::IntegerBuffer pitchtrimindBuffer(0x44d2, 0xffff, 0, onPitchtrimindChange); void onRolltrimindChange(unsigned int newValue) { c1 = map(newValue, 0, 65535, 5, 95); Drawgauge1(cx, cy, radius, percent, c1, 0, 99); } DcsBios::IntegerBuffer rolltrimindBuffer(0x44d0, 0xffff, 0, onRolltrimindChange); void setup() { DcsBios::setup(); OLED1.begin(); OLED2.begin(); } void loop() { DcsBios::loop(); } New Version Now 2 Oleds in HW SPI Mode on one Arduino Nano. 2
Recommended Posts