模板:DelveBit arduino

来自Labplus盛思维基百科
Tangliufeng讨论 | 贡献2019年4月18日 (四) 09:48的版本 (创建页面,内容为“<syntaxhighlight lang="Python" line='line'> #include <Wire.h> int reading = 0; void GetSensorValue(char address) { Wire.requestFrom(address, 2); if (2 <= W…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航搜索
#include <Wire.h>
int reading = 0;
void GetSensorValue(char address)
{
    Wire.requestFrom(address, 2); 
    if (2 <= Wire.available())
    {
       reading = Wire.read();  // receive high byte (overwrites previous reading)
       reading = reading << 8;    // shift high byte to be high 8 bits
       reading |= Wire.read(); // receive low byte as lower 8 bits
       Serial.println(reading);   // print the reading
    } 
}

void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
}

void loop()
{
   GetSensorValue(0x63);
}