找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

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

Arduino+tm1637數(shù)碼管不能亮完全為什么?附代碼

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:1039199 發(fā)表于 2022-7-11 23:19 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
#include <Wire.h>
#include <HMC5883L.h>
#include "TM1637.h"   

#define CLK 3
#define DIO 2

TM1637 tm1637(CLK, DIO);

HMC5883L compass;
int vol[18];  

// 初始化函數(shù)
void setup(){
    tm1637.set(BRIGHT_TYPICAL);              // 配置數(shù)碼管亮度
        tm1637.init(D4056A);                     // 配置數(shù)碼管類型
    tm1637.display(0, "P");              
    tm1637.display(1, 10);
    tm1637.display(2, 15);

        compass.setRange(HMC5883L_RANGE_0_88GA);
        compass.setMeasurementMode(HMC5883L_CONTINOUS);
        compass.setDataRate(HMC5883L_DATARATE_30HZ);
        compass.setSamples(HMC5883L_SAMPLES_1);
    delay(3000);
}

// 主函數(shù)
void loop()
{
        label1:                    
    for (int i = 0; i <= 14; i++) {
                Vector raw = compass.readRaw();
                vol[ i] = (raw.XAxis);
                vol[15] = (raw.XAxis);
                delay(66);

                if ( vol[15] > 1900 || vol[15] < -950 ){   
                        tm1637.display(0, 15);
                        tm1637.display(1, ">");
                        tm1637.display(2, ">");
                        tm1637.display(3, "8");
                        delay(3000);
                        goto label1;
                }
    }

    vol[16] = (vol[0]+vol[1]+vol[2]+vol[3]+vol[4]+vol[5]+vol[6]+vol[7])/8;
    vol[17] = (vol[8]+vol[9]+vol[10]+vol[11]+vol[12]+vol[13]+vol[14])/7;
    vol[18] = max(vol[16],vol[17]);

    tm1637.display(vol[18]);
}

TM1637.zip

8.36 KB, 下載次數(shù): 6

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

使用道具 舉報

沙發(fā)
ID:1039199 發(fā)表于 2022-7-11 23:22 | 只看該作者
用的這個驅(qū)動
回復

使用道具 舉報

板凳
ID:158588 發(fā)表于 2022-7-12 05:22 | 只看該作者

1637需要的庫有先導入嗎?編譯有報錯嗎?
回復

使用道具 舉報

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

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

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

快速回復 返回頂部 返回列表