找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 9132|回復(fù): 2
打印 上一主題 下一主題
收起左側(cè)

Arduino+mpu6050+oled角度在OLED上波形顯示程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:14408 發(fā)表于 2019-4-4 11:39 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
arduino、6050和oled 的sda scl相連 oled是四線的     



Arduino源程序如下:
  1. //******************************************************************************
  2. //    項   目:傳感器
  3. //    說   明:檢測陀螺儀、羅盤數(shù)據(jù),進行濾波 目前只讀取X軸數(shù)據(jù)
  4. //******************************************************************************
  5. #include <Wire.h>
  6. #include "Timer.h"                                                //時間操作系統(tǒng)頭文件  本程序用作timeChange時間采集并處理一次數(shù)據(jù)
  7. #include "Imu.h"
  8. //--------------------------------------------------------------------------------------------------
  9.         #define UseOled 1                               //是否使用軟串口讀寫信息(軟串口可避免電腦串口下載程序時與藍牙沖突)
  10.         #if UseOled
  11.             #include <Adafruit_SSD1306.h>
  12.             Adafruit_SSD1306 display(4);
  13.             int DispLoop = 1;
  14.             int MinPixel = 30;
  15.             int MaxPixel = 63;
  16.             int DispPixel = 0;
  17.             int DispDegrees = 0;
  18.         #endif
  19. //---------- ------------------------------------------------------ -------------------------------
  20.       Timer timer;                                                //時間類
  21. //--------------------------------------------------------------------------------------------------
  22.         void setup() {
  23.              Serial.begin(9600);
  24.              delay(500);
  25.              GyData.Init();
  26.              #if UseOled
  27.                  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  28.                  display.display();
  29.                  delay(500);
  30.                  display.clearDisplay();
  31.             #endif
  32.          int tickEvent1=timer.every(20, getadngsle);              //本語句執(zhí)行以后timeChange毫秒執(zhí)行回調(diào)函數(shù)getangle
  33.          int tickEvent2=timer.every(50, PrintOut) ;               //本語句執(zhí)行以后50毫秒執(zhí)行回調(diào)函數(shù)PrintOut,串口輸出
  34.         }
  35. //--------------------------------------------------------------------------------------------------
  36.         void loop() {
  37.              timer.update();                                      //時間操作系統(tǒng)運行
  38.         }
  39. //--------------------------------------------------------------------------------------------------
  40.         void PrintOut(){
  41.              #if UseOled
  42.                  display.fillRect(0, 0, 128, 30, BLACK);
  43.                  display.drawRect(0, 29,128,35, WHITE);
  44.                  display.setTextSize(1);
  45.                  display.setTextColor(WHITE);
  46.                  display.setCursor(0,0);display.print("Angle:");
  47.                  display.setCursor(40,0);display.print(GyData.angle);
  48.                  DispPixel = GyData.angle/6+45;
  49.                  if(MinPixel >=DispPixel)DispPixel = MinPixel;
  50.                  if(DispPixel >=MaxPixel)DispPixel = MaxPixel;
  51.                     display.drawLine(DispLoop, MinPixel+1, DispLoop, MaxPixel-1, BLACK);         //清除前一幀
  52.                     display.drawPixel(DispLoop, DispPixel, WHITE);
  53.                     display.display();
  54.                  if(DispLoop==126)DispLoop = 1;
  55.                     DispLoop ++;
  56.             #endif
  57.         }
  58. //--------------------------------------------------------------------------------------------------
  59.         void getadngsle(){
  60.              GyData.GetAngle();
  61.         }
  62. //--------------------------------------------------------------------------------------------------
  63.         
  64.         


  65.         
復(fù)制代碼

程序編譯有問題 求指導(dǎo): Mydata.zip (28.9 KB, 下載次數(shù): 103)



評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:808634 發(fā)表于 2020-9-12 13:35 | 只看該作者
顯示庫重復(fù)使用,這是為什么
回復(fù)

使用道具 舉報

板凳
ID:150338 發(fā)表于 2023-11-4 15:06 | 只看該作者
為什么編譯會報錯啊
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表