afr 仪表无法读取数字 是否有问题?

问题描述

任何人都可以帮助解决我正在研究的这个 oled afr 仪表,不可否认,这不是我的编码,但我无法从原作者那里得到任何回应。我已经改变了初始启动以满足我的需要,编译正常上传,条形图工作完美但数字不,我一直在寻找答案,但我不知所措,任何帮助将不胜感激

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width,in pixels
#define SCREEN_HEIGHT 64 // OLED display height,in pixels

// Declaration for an SSD1306 display connected to I2C (SDA,SCL pins)
#define OLED_RESET 4
Adafruit_SSD1306 display(SCREEN_WIDTH,SCREEN_HEIGHT,&Wire,OLED_RESET);

int XPOS = 0;
int YPOS = 0;
int analogIn = 0;
int val = 0;
int value = 0;
int x1 = 0;
int x2 = 0;
int x3 = 0;
int needle = 0;

#define Gsxr_logo_HEIGHT 64
#define Gsxr_logo_WIDTH 128
static const unsigned char PROGMEM Gsxr_logo [] = {
  // 'GSX logo ',128x64px
  0x00,0x00,0x1f,0xff,0xfc,0x0f,0x80,0x03,0xc0,0x7f,0xf8,0xfe,0xe0,0x3f,0xf0,0x07,0x01,0xfd,0x6f,0xa8,0xf7,0xef,0xcf,0x87,0x81,0x02,0xaf,0xbb,0xb5,0xe1,0x8a,0xd2,0x00
};

#define   Turbo_logo_HEIGHT 64
#define Turbo_logo_WIDTH 64
static const unsigned char PROGMEM Turbo_logo [] = {
  // 'turbo-got-boost-iphone-6-case5',64x64px
  0x00,0xf9,0xf6,0xe3,0x83,0xfb,0x13,0xf3,0x1e,0x0e,0xbf,0xc7,0xdf,0x9e,0x3c,0x78,0x40,0xbe,0x20,0x7c,0xe6,0x10,0xee,0xf1,0xce,0x73,0x08,0x06,0x77,0x76,0xac,0xfa,0xc1,0x58,0x60,0xc3,0x0c,0x7b,0xde,0xe7,0xdc,0xc8,0x18,0xf2,0x30,0x70,0x67,0x1c,0x00
};


#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect,please fix Adafruit_SSD1306.h!");
#endif

void setup()   {
  Serial.begin(9600);

  // by default,we'll generate the high voltage from the 3.3v line internally! (neat!)
  if (!display.begin(SSD1306_SWITCHCAPVCC,0x3c)) { // initialize with the I2C addr 0x3D (for the 128x64)
    Serial.println(F("SSD1306 allocation Failed"));
    for (;;); // Don't proceed,loop forever
  }
  //init done
  display.cleardisplay();
  //initbuffer
  startdisplay();
}


void loop() {

  val = analogRead(analogIn);//A0
  needle = val;
  val = map(val,1023,74,221);
  needle = map(needle,1,127);
  display.cleardisplay();
  display.drawRect(0,52,128,12,WHITE);
  drawAFR();
  devide();
  display.setTextSize(4);
  display.setTextColor(WHITE);
  display.setCursor(22,0);
  display.print(x1);
  display.print(x2);
  display.print(".");
  display.print(x3);
  display.drawLine(needle,53,needle,63,WHITE);
  display.drawLine(needle - 1,needle - 1,WHITE);
  display.drawLine(needle + 1,needle + 1,WHITE);
  display.display();

}

void startdisplay() {
  display.cleardisplay();
  display.drawBitmap(0,Gsxr_logo,64,1);
  display.display();
  delay(2000);
  XPOS = 33;
  YPOS = -20;
  while (YPOS != 0) {
    display.cleardisplay();
    display.drawBitmap(XPOS,YPOS,Turbo_logo,1);
    display.display();
    YPOS ++;
  }

  for (int x = 0; x < 5; x++) {
    display.invertdisplay(true);
    delay(150);
    display.invertdisplay(false);
    delay(150);
  }
  display.invertdisplay(true);
  delay(2000);
  display.cleardisplay();
  display.display();
  display.invertdisplay(false);
}

void drawAFR()
{
  display.drawLine(0,47,51,WHITE);
  display.drawLine(64,56,WHITE);
  display.drawLine(127,127,WHITE);
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(54,34);
  display.println("14.7");
  display.setCursor(0,34);
  display.println("7.4");
  display.setCursor(104,34);
  display.println("22.1");

}

void devide()
{
  x1 = 0;
  x2 = 0;
  x3 = 0;
  value = val;
  if (value < 100) goto dozens;
  if (value < 10) goto units;
hundreds:
  value = value - 100;
  x1 = x1 ++;
  if (value < 100) goto dozens;
  goto hundreds;
dozens:
  if (value < 10) goto units;
  value = value - 10;
  x2 = x2 ++;
  if (value < 10) goto units;
  goto dozens;
units:
  if (value < 1) goto devide_end;
  value = value - 1;
  x3 = x3 ++;
  if (value < 0) goto devide_end;
  goto units;
devide_end:
  x1 = x1;

}

  

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)