极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 13459|回复: 2

?????

[复制链接]
发表于 2013-11-10 00:08:43 | 显示全部楼层 |阅读模式
arduino 用hmc5883l 磁场传感器,接线A4 和A5 后,编程序,用led 13灯来点亮,但是实实验中,当模拟数字符合点亮的条件的时候,为什么外接在13号引脚的led灯不会亮呢,而且有时候是处于微微亮的状态(一直微亮),代码如下

#include <Wire.h> //I2C Arduino Library  
  
#define address 0x1E //0011110b, I2C 7bit address of HMC5883  
int ledPin1 = 13;
void setup(){  
  //Initialize Serial and I2C communications  
  Serial.begin(9600);  
  Wire.begin();  
   
  //Put the HMC5883 IC into the correct operating mode  
  Wire.beginTransmission(address); //open communication with HMC5883  
  Wire.write(0x02); //select mode register  
  Wire.write(0x00); //continuous measurement mode  
  Wire.endTransmission();  
}  
  
void loop(){  
   
  int x,y,z,baa,all; //triple axis data  
  
  //Tell the HMC5883 where to begin reading data  
  Wire.beginTransmission(address);  
  Wire.write(0x03); //select register 3, X MSB register  
  Wire.endTransmission();  
   
   
//Read data from each axis, 2 registers per axis  
  Wire.requestFrom(address, 6);  
  if(6<=Wire.available()){  
    x = Wire.read()<<8; //X msb  
    x |= Wire.read(); //X lsb  
    z = Wire.read()<<8; //Z msb  
    z |= Wire.read(); //Z lsb  
    y = Wire.read()<<8; //Y msb  
    y |= Wire.read(); //Y lsb  
  }  
    all=x+y+z;
  if(all> 800)// 设置数值大于800  {
    digitalWrite(ledPin1,HIGH);
    Serial.print("abs(all): ");  
   Serial.print(abs(all));   
   delay(5000);  
}
else
      digitalWrite(ledPin1,LOW);  
     Serial.print("abs(all): ");  
   Serial.print(abs(all));  
delay(5000);   
}  


问题:当all的值已经达到1200的时候(已经大于800啦),为什么led13灯不会亮呢???????????[/size]
回复

使用道具 举报

 楼主| 发表于 2013-11-10 02:08:35 | 显示全部楼层
为什么没有回答的
回复 支持 反对

使用道具 举报

发表于 2013-11-10 06:50:46 来自手机 | 显示全部楼层
你把low和high互换试试?
回复 支持 反对

使用道具 举报

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

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-6 02:16 , Processed in 0.076515 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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