找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 8277|回复: 2
打印 上一主题 下一主题
收起左侧

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

[复制链接]
跳转到指定楼层
楼主
arduino、6050和oled 的sda scl相连 oled是四线的     



Arduino源程序如下:
  1. //******************************************************************************
  2. //    项   目:传感器
  3. //    说   明:检测陀螺仪、罗盘数据,进行滤波 目前只读取X轴数据
  4. //******************************************************************************
  5. #include <Wire.h>
  6. #include "Timer.h"                                                //时间操作系统头文件  本程序用作timeChange时间采集并处理一次数据
  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);              //本语句执行以后timeChange毫秒执行回调函数getangle
  33.          int tickEvent2=timer.every(50, PrintOut) ;               //本语句执行以后50毫秒执行回调函数PrintOut,串口输出
  34.         }
  35. //--------------------------------------------------------------------------------------------------
  36.         void loop() {
  37.              timer.update();                                      //时间操作系统运行
  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.         
复制代码

程序编译有问题 求指导: Mydata.zip (28.9 KB, 下载次数: 102)



评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:808634 发表于 2020-9-12 13:35 | 只看该作者
显示库重复使用,这是为什么
回复

使用道具 举报

板凳
ID:150338 发表于 2023-11-4 15:06 | 只看该作者
为什么编译会报错啊
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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