[教學] Hitehnic 顏色感應器 I2C讀值

首先要先謝謝高手sog, 在I2C與藍芽給我很多協助. 這個傢伙比較低調, 我這樣表示就可以了。

 

================================

 

#include "NXCDefs.h"
void checkI2C()
{
byte status;
do{
status= I2CCheckStatus(IN_1);
}while(status == STAT_COMM_PENDING);
}
task main()
{
SetSensorLowspeed(IN_1);
int count = 3;       //read count set to 6 bytes
int rval;
int gval;
int bval;
byte inI2Ccmd[];
byte outbuf[];
while (true)
{
ArrayBuild(inI2Ccmd, 0x02, 0x43);         //Rebuild the Array
checkI2C();
I2CBytes(IN_1, inI2Ccmd, count, outbuf);  //read color sensor on port 1
checkI2C();
rval=outbuf[0];                           //load R Value
gval=outbuf[1];                           //load G Value
bval=outbuf[2];                           //load B Value
ClearScreen();
TextOut(0,10,"Red  :");NumOut(50,10,rval);
TextOut(0,20,"Green:");NumOut(50,20,gval);
TextOut(0,30,"Blue :");NumOut(50,30,bval);
Wait(200);
}
}
About CAVEDU 阿吉 - 雜工 (2520 Articles)
CAVEDU 教育團隊 打雜
Contact: Website

Leave a comment

Your email address will not be published.


*