|
#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ù)碼管類(lèi)型
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
2022-7-11 23:22 上傳
點(diǎn)擊文件名下載附件
8.36 KB, 下載次數(shù): 6
|