Arduino Esplora 加速计读数控制 RGB LED

发布于: 27 January, 2014
分享:

/* @Author: TONYLABS @Date: 2012/02/02 */ #include const uint16_t SAMPLES=64; int calx=0, caly=0, calz=0; long sums[3] = {0}; int readings[SAMPLES][3] = {0}; uint8_t index = 0; void setup() {  Serial.begin(115200); } void loop() {  int rx, ry, rz;  rx=Esplora.readAccelerometer(X_AXIS);  ry=Esplora.readAccelerometer(Y_AXIS);  rz=Esplora.readAccelerometer(Z_AXIS);  if (Esplora.readButton(SWITCH_DOWN) == LOW) {    calx=rx, caly=ry, calz=rz;  } else {    rx -= calx, ry -= caly, rz -= calz;    for (uint8_t i=0; i < 3; ++i) {      sums[i] -= readings[index][i];    }    sums[0] += rx, sums[1] += ry, sums[2] += rz;    readings[index][0] = rx;    readings[index][1] = ry;    readings[index][2] = rz;    index = (index + 1) % SAMPLES;    rx = sums[0]/SAMPLES, ry = sums[1]/SAMPLES, rz = sums[2]/SAMPLES;    Esplora.writeRGB(abs(rx), abs(ry), abs(rz));  } } /* @end */  

分享:

0 留言

留言

您的留言将被人工审核,请勿发表色情、反动言论。

您可能感兴趣

如何测试 Arduino GSM Shield 调制解调器

本文介绍如何使用GSM Shield测试调制解调器功能。通过Arduino和GSM Shield,您可以发送和接收短信、拨打电...

Arduino Esplora 说明书

Arduino Esplora 是一款富有创意、多功能的电子开发板,集成传感器、按钮和输出设备,简单编程实现互动,适...