极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10561|回复: 0

使用g8lib的一些问题

[复制链接]
发表于 2016-7-1 23:22:54 | 显示全部楼层 |阅读模式


如视频,为什么刷新的时候会这样呢?

代码如下


  1. #include "U8glib.h"
  2. #include <Wire.h>
  3. #include <Adafruit_BMP085.h>

  4. U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0); // I2C / TWI
  5. Adafruit_BMP085 bmp;

  6. void draw(void){
  7.   u8g.setFont(u8g_font_helvR12);  //delay(500);
  8.   char alt_buf[20];
  9.   float alt = bmp.readAltitude(101100);
  10.   char altStr[6];
  11.   dtostrf(alt, 4, 2, altStr);
  12.   sprintf(alt_buf, "ALT: %sm", altStr);

  13.   u8g.setFont(u8g_font_helvR12);  //delay(500);
  14.   int32_t pre = bmp.readPressure();
  15.   float hpa = pre / 100.0;
  16.   char preStr[6];
  17.   dtostrf(hpa, 4, 2, preStr);
  18.   char pre_buf[20];
  19.   sprintf(pre_buf, "%shpa", preStr);

  20.   u8g.setFont(u8g_font_helvR12);  //delay(500);
  21.   float tmp = bmp.readTemperature();
  22.   char tmp_buf[20];
  23.   char tmp_str[6];
  24.   dtostrf(tmp, 4, 2, tmp_str);
  25.   sprintf(tmp_buf, "TMP: %s*C", tmp_str);

  26.   u8g.setPrintPos(0, 20);
  27.   u8g.print(alt_buf);
  28.   u8g.setPrintPos(0, 40);
  29.   u8g.print(pre_buf);
  30.   u8g.setPrintPos(0, 60);
  31.   u8g.print(tmp_buf);
  32. }

  33. void initScreen(void) {
  34.   if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
  35.     u8g.setColorIndex(255);     // white
  36.   }
  37.   else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
  38.     u8g.setColorIndex(3);         // max intensity
  39.   }
  40.   else if ( u8g.getMode() == U8G_MODE_BW ) {
  41.     u8g.setColorIndex(1);         // pixel on
  42.   }
  43.   else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
  44.     u8g.setHiColorByRGB(255, 255, 255);
  45.   }
  46. }


  47. void initBmp(void) {
  48.   if (!bmp.begin()) {
  49.     Serial.println("Could not find a valid BMP085 sensor, check wiring!");
  50.     while (1) {}
  51.   }
  52. }

  53. void setup() {
  54.   Serial.begin(9600);
  55.   initScreen();
  56.   delay(50);
  57.   initBmp();

  58. }

  59. void loop() {
  60.   u8g.firstPage();
  61.   do {
  62.     draw();
  63.   } while (u8g.nextPage());
  64. delay(1000);
  65. }
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-29 20:38 , Processed in 0.043276 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表