极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 15560|回复: 0

请教库函数问题

[复制链接]
发表于 2016-5-19 16:09:22 | 显示全部楼层 |阅读模式
请问怎样把这个函数封装成库函数?看了其他库函数的教程贴,但是还是做不出来···求大神解答
#include<Wire.h>
#include<math.h>
int BH1750address=0x23;
byte buff[2];
void setup()
{
Wire.begin();
Serial.begin(9600);
}
void loop()
{
  int j;
  uint16_t val=0;
  BH1750_Init(BH1750address);
  delay(200);
  if(2==BH1750_Read(BH1750address))
  {
    val=((buff[0]<<8)|buff[1])/1.2;
    if(val<200)
    {
      analogWrite(3,255);
      }
      else{analogWrite(3,LOW);}
    Serial.print(val,DEC);
   Serial.println("[1x]");
  }
delay(150);
}
int BH1750_Read(int address)
{
int j=0;
Wire.beginTransmission(address);
Wire.requestFrom(address,2);
while(Wire.available())
{
  buff[j]=Wire.read();
  j++;
  }
  Wire.endTransmission();
  return j;
  }
  void BH1750_Init(int address)
  {
     Wire.beginTransmission(address);
     Wire.write(0x10);
     Wire.endTransmission();
  }
回复

使用道具 举报

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

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-15 08:28 , Processed in 0.098968 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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