Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df4e264dba
|
||
|
|
f0d7ac873e
|
||
|
|
378d387986
|
||
|
|
5eb2aec06a
|
||
|
|
246df58947
|
||
|
|
449d3c098e
|
||
|
|
000cc7b28e
|
||
|
|
37e7d89ed7
|
||
|
|
19013fb0d7
|
||
|
|
418d9e0478
|
||
|
|
94b2ce4416
|
||
|
|
3ec8c3d570
|
||
|
|
9c67837956
|
||
|
|
35eb89d5a9
|
||
|
|
bfa985f830
|
||
|
|
e33a500985
|
||
|
|
3d098bd806
|
852
8By8/8By8.ino
852
8By8/8By8.ino
File diff suppressed because it is too large
Load Diff
@@ -1,240 +1,74 @@
|
|||||||
#include "REG.h"
|
#include "REG.h"
|
||||||
#include "wit_c_sdk.h"
|
#include "wit_c_sdk.h"
|
||||||
|
|
||||||
// #define ACC_UPDATE 0x01
|
|
||||||
// #define GYRO_UPDATE 0x02
|
|
||||||
// #define ANGLE_UPDATE 0x04
|
|
||||||
// #define MAG_UPDATE 0x08
|
|
||||||
// #define READ_UPDATE 0x80
|
|
||||||
|
|
||||||
// char s_cDataUpdate = 0;
|
|
||||||
// const uint32_t c_uiBaud[8] = {0, 4800, 9600, 19200,
|
|
||||||
// 38400, 57600, 115200, 230400};
|
|
||||||
|
|
||||||
// float fAcc[3], fGyro[3], fAngle[3];
|
|
||||||
|
|
||||||
// bool setup_ok = true;
|
|
||||||
|
|
||||||
// static void SensorUartSend(uint8_t *p_data, uint32_t uiSize);
|
|
||||||
// static void SensorDataUpdate(uint32_t uiReg, uint32_t uiRegNum);
|
|
||||||
// static void Delayms(uint16_t ucMs);
|
|
||||||
// static void AutoScanSensor();
|
|
||||||
|
|
||||||
// void setup() {
|
|
||||||
// Serial.begin(115200);
|
|
||||||
// WitInit(WIT_PROTOCOL_NORMAL, 0x50);
|
|
||||||
// WitSerialWriteRegister(SensorUartSend);
|
|
||||||
// WitRegisterCallBack(SensorDataUpdate);
|
|
||||||
// WitDelayMsRegister(Delayms);
|
|
||||||
// AutoScanSensor();
|
|
||||||
|
|
||||||
// // Ensure the setting for the sensor is the default
|
|
||||||
// if (WitSetBandwidth(BANDWIDTH_256HZ) != WIT_HAL_OK) {
|
|
||||||
// Serial.print("Set Bandwidth Error\r\n");
|
|
||||||
// setup_ok = false;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // if (WitSetUartBaud(WIT_BAUD_115200) != WIT_HAL_OK) {
|
|
||||||
// // Serial.print("Set baud error\r\n");
|
|
||||||
// // setup_ok = false;
|
|
||||||
// // return;
|
|
||||||
// // } else {
|
|
||||||
// // Serial1.begin(115200);
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// if (WitSetOutputRate(RRATE_1HZ) != WIT_HAL_OK) {
|
|
||||||
// Serial.print("Can't set report rate to 10Hz!\r\n");
|
|
||||||
// setup_ok = false;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (WitSetContent(RSW_ACC | RSW_GYRO | RSW_ANGLE | RSW_MAG) != WIT_HAL_OK)
|
|
||||||
// {
|
|
||||||
// Serial.print("Set RSW Error\r\n");
|
|
||||||
// setup_ok = false;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// void loop() {
|
|
||||||
// while (Serial1.available()) {
|
|
||||||
// WitSerialDataIn(Serial1.read());
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // if (s_cDataUpdate) {
|
|
||||||
// // for (int i = 0; i < 3; i++) {
|
|
||||||
// // fAcc[i] = sReg[AX + i] / 32768.0f * 16.0f; // Unit: g(9.8m/s^2)
|
|
||||||
// // fGyro[i] = sReg[GX + i] / 32768.0f * 2000.0f; // Unit: deg/s
|
|
||||||
// // fAngle[i] = sReg[Roll + i] / 32768.0f * 180.0f; // Unit: deg
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// // if (s_cDataUpdate & ACC_UPDATE) {
|
|
||||||
// // Serial.print("acc:");
|
|
||||||
// // Serial.print(fAcc[0], 3);
|
|
||||||
// // Serial.print(" ");
|
|
||||||
// // Serial.print(fAcc[1], 3);
|
|
||||||
// // Serial.print(" ");
|
|
||||||
// // Serial.print(fAcc[2], 3);
|
|
||||||
// // Serial.print("\r\n");
|
|
||||||
// // s_cDataUpdate &= ~ACC_UPDATE;
|
|
||||||
// // }
|
|
||||||
// // if (s_cDataUpdate & GYRO_UPDATE) {
|
|
||||||
// // Serial.print("gyro:");
|
|
||||||
// // Serial.print(fGyro[0], 1);
|
|
||||||
// // Serial.print(" ");
|
|
||||||
// // Serial.print(fGyro[1], 1);
|
|
||||||
// // Serial.print(" ");
|
|
||||||
// // Serial.print(fGyro[2], 1);
|
|
||||||
// // Serial.print("\r\n");
|
|
||||||
// // s_cDataUpdate &= ~GYRO_UPDATE;
|
|
||||||
// // }
|
|
||||||
// // if (s_cDataUpdate & ANGLE_UPDATE) {
|
|
||||||
// // Serial.print("angle:");
|
|
||||||
// // Serial.print(fAngle[0], 3);
|
|
||||||
// // Serial.print(" ");
|
|
||||||
// // Serial.print(fAngle[1], 3);
|
|
||||||
// // Serial.print(" ");
|
|
||||||
// // Serial.print(fAngle[2], 3);
|
|
||||||
// // Serial.print("\r\n");
|
|
||||||
// // s_cDataUpdate &= ~ANGLE_UPDATE;
|
|
||||||
// // }
|
|
||||||
// // if (s_cDataUpdate & MAG_UPDATE) {
|
|
||||||
// // Serial.print("mag:");
|
|
||||||
// // Serial.print(sReg[HX]);
|
|
||||||
// // Serial.print(" ");
|
|
||||||
// // Serial.print(sReg[HY]);
|
|
||||||
// // Serial.print(" ");
|
|
||||||
// // Serial.print(sReg[HZ]);
|
|
||||||
// // Serial.print("\r\n");
|
|
||||||
// // s_cDataUpdate &= ~MAG_UPDATE;
|
|
||||||
// // }
|
|
||||||
// // s_cDataUpdate = 0;
|
|
||||||
// // }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// static void SensorUartSend(uint8_t *p_data, uint32_t uiSize) {
|
|
||||||
// Serial1.print("Sensor says: ");
|
|
||||||
// Serial1.write(p_data, uiSize);
|
|
||||||
// Serial1.flush();
|
|
||||||
// };
|
|
||||||
|
|
||||||
// static void SensorDataUpdate(uint32_t uiReg, uint32_t uiRegNum) {
|
|
||||||
// int i;
|
|
||||||
// for (i = 0; i < uiRegNum; i++) {
|
|
||||||
// switch (uiReg) {
|
|
||||||
// case AZ:
|
|
||||||
// s_cDataUpdate |= ACC_UPDATE;
|
|
||||||
// break;
|
|
||||||
// case GZ:
|
|
||||||
// s_cDataUpdate |= GYRO_UPDATE;
|
|
||||||
// break;
|
|
||||||
// case HZ:
|
|
||||||
// s_cDataUpdate |= MAG_UPDATE;
|
|
||||||
// break;
|
|
||||||
// case Yaw:
|
|
||||||
// s_cDataUpdate |= ANGLE_UPDATE;
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// s_cDataUpdate |= READ_UPDATE;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// uiReg++;
|
|
||||||
// }
|
|
||||||
// Serial.println(s_cDataUpdate);
|
|
||||||
// };
|
|
||||||
|
|
||||||
// static void Delayms(uint16_t ucMs) { delay(ucMs); }
|
|
||||||
|
|
||||||
// static void AutoScanSensor() {
|
|
||||||
// int i, iRetry;
|
|
||||||
|
|
||||||
// for (i = 0; i < sizeof(c_uiBaud) / sizeof(c_uiBaud[0]); i++) {
|
|
||||||
// Serial1.begin(c_uiBaud[i]);
|
|
||||||
// Serial1.flush();
|
|
||||||
// iRetry = 2;
|
|
||||||
// s_cDataUpdate = 0;
|
|
||||||
// do {
|
|
||||||
// WitReadReg(AX, 3);
|
|
||||||
// delay(200);
|
|
||||||
// while (Serial1.available()) {
|
|
||||||
// WitSerialDataIn(Serial1.read());
|
|
||||||
// }
|
|
||||||
// if (s_cDataUpdate != 0) {
|
|
||||||
// Serial.print(c_uiBaud[i]);
|
|
||||||
// Serial.print(" baud find sensor\r\n\r\n");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// iRetry--;
|
|
||||||
// } while (iRetry);
|
|
||||||
// }
|
|
||||||
// Serial.print("can not find sensor\r\n");
|
|
||||||
// Serial.print("please check your connection\r\n");
|
|
||||||
// }
|
|
||||||
|
|
||||||
/*
|
|
||||||
Test on MEGA 2560. use WT901CTTL sensor
|
|
||||||
|
|
||||||
WT901CTTL MEGA 2560a
|
|
||||||
VCC <---> 5V/3.3V
|
|
||||||
TX <---> 19(TX1)
|
|
||||||
RX <---> 18(RX1)
|
|
||||||
GND <---> GND
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define ACC_UPDATE 0x01
|
#define ACC_UPDATE 0x01
|
||||||
#define GYRO_UPDATE 0x02
|
#define GYRO_UPDATE 0x02
|
||||||
#define ANGLE_UPDATE 0x04
|
#define ANGLE_UPDATE 0x04
|
||||||
#define MAG_UPDATE 0x08
|
#define MAG_UPDATE 0x08
|
||||||
#define READ_UPDATE 0x80
|
#define READ_UPDATE 0x80
|
||||||
static volatile char s_cDataUpdate = 0, s_cCmd = 0xff;
|
|
||||||
|
|
||||||
static void CmdProcess(void);
|
char s_cDataUpdate = 0;
|
||||||
static void AutoScanSensor(void);
|
|
||||||
static void SensorUartSend(uint8_t *p_data, uint32_t uiSize);
|
|
||||||
static void SensorDataUpdata(uint32_t uiReg, uint32_t uiRegNum);
|
|
||||||
static void Delayms(uint16_t ucMs);
|
|
||||||
const uint32_t c_uiBaud[8] = {0, 4800, 9600, 19200,
|
const uint32_t c_uiBaud[8] = {0, 4800, 9600, 19200,
|
||||||
38400, 57600, 115200, 230400};
|
38400, 57600, 115200, 230400};
|
||||||
|
|
||||||
int i;
|
|
||||||
float fAcc[3], fGyro[3], fAngle[3];
|
float fAcc[3], fGyro[3], fAngle[3];
|
||||||
|
|
||||||
|
bool setup_ok = true;
|
||||||
|
|
||||||
|
static void SensorUartSend(uint8_t *p_data, uint32_t uiSize);
|
||||||
|
static void SensorDataUpdate(uint32_t uiReg, uint32_t uiRegNum);
|
||||||
|
static void Delayms(uint16_t ucMs);
|
||||||
|
static void AutoScanSensor();
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// put your setup code here, to run once:
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
WitInit(WIT_PROTOCOL_NORMAL, 0x50);
|
WitInit(WIT_PROTOCOL_NORMAL, 0x50);
|
||||||
WitSerialWriteRegister(SensorUartSend);
|
WitSerialWriteRegister(SensorUartSend);
|
||||||
WitRegisterCallBack(SensorDataUpdata);
|
WitRegisterCallBack(SensorDataUpdate);
|
||||||
WitDelayMsRegister(Delayms);
|
WitDelayMsRegister(Delayms);
|
||||||
AutoScanSensor();
|
AutoScanSensor();
|
||||||
|
|
||||||
if (WitStartAccCali() == WIT_HAL_OK) {
|
// Ensure the setting for the sensor is the default
|
||||||
Serial.print("Start Calibri");
|
if (WitSetBandwidth(BANDWIDTH_256HZ) != WIT_HAL_OK) {
|
||||||
delay(1000);
|
Serial.print("Set Bandwidth Error\r\n");
|
||||||
Serial.print("Stop calibri");
|
setup_ok = false;
|
||||||
WitStopAccCali();
|
return;
|
||||||
} else {
|
|
||||||
Serial.print("Cannot start calibri acc\r\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WitSetUartBaud(WIT_BAUD_9600) != WIT_HAL_OK)
|
// if (WitSetUartBaud(WIT_BAUD_115200) != WIT_HAL_OK) {
|
||||||
Serial.print("\r\nSet Baud Error\r\n");
|
// Serial.print("Set baud error\r\n");
|
||||||
else {
|
// setup_ok = false;
|
||||||
Serial1.begin(c_uiBaud[WIT_BAUD_9600]);
|
// return;
|
||||||
Serial.print(" 115200 Baud rate modified successfully\r\n");
|
// } else {
|
||||||
|
// Serial1.begin(115200);
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (WitSetOutputRate(RRATE_1HZ) != WIT_HAL_OK) {
|
||||||
|
Serial.print("Can't set report rate to 10Hz!\r\n");
|
||||||
|
setup_ok = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WitSetContent(RSW_ACC | RSW_GYRO | RSW_ANGLE | RSW_MAG) != WIT_HAL_OK)
|
||||||
|
{
|
||||||
|
Serial.print("Set RSW Error\r\n");
|
||||||
|
setup_ok = false;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
while (Serial1.available()) {
|
while (Serial1.available()) {
|
||||||
WitSerialDataIn(Serial1.read());
|
WitSerialDataIn(Serial1.read());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s_cDataUpdate) {
|
if (s_cDataUpdate) {
|
||||||
for (i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
fAcc[i] = sReg[AX + i] / 32768.0f * 16.0f * 9.8f; // Unit: m/s^2
|
fAcc[i] = sReg[AX + i] / 32768.0f * 16.0f; // Unit: g(9.8m/s^2)
|
||||||
fGyro[i] = sReg[GX + i] / 32768.0f * 2000.0f; // Unit: deg/s
|
fGyro[i] = sReg[GX + i] / 32768.0f * 2000.0f; // Unit: deg/s
|
||||||
fAngle[i] = sReg[Roll + i] / 32768.0f * 180.0f; // Unit: deg
|
fAngle[i] = sReg[Roll + i] / 32768.0f * 180.0f; // Unit: deg
|
||||||
}
|
}
|
||||||
|
Serial.print("Here");
|
||||||
if (s_cDataUpdate & ACC_UPDATE) {
|
if (s_cDataUpdate & ACC_UPDATE) {
|
||||||
Serial.print("acc:");
|
Serial.print("acc:");
|
||||||
Serial.print(fAcc[0], 3);
|
Serial.print(fAcc[0], 3);
|
||||||
@@ -282,9 +116,9 @@ void loop() {
|
|||||||
static void SensorUartSend(uint8_t *p_data, uint32_t uiSize) {
|
static void SensorUartSend(uint8_t *p_data, uint32_t uiSize) {
|
||||||
Serial1.write(p_data, uiSize);
|
Serial1.write(p_data, uiSize);
|
||||||
Serial1.flush();
|
Serial1.flush();
|
||||||
}
|
};
|
||||||
static void Delayms(uint16_t ucMs) { delay(ucMs); }
|
|
||||||
static void SensorDataUpdata(uint32_t uiReg, uint32_t uiRegNum) {
|
static void SensorDataUpdate(uint32_t uiReg, uint32_t uiRegNum) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < uiRegNum; i++) {
|
for (i = 0; i < uiRegNum; i++) {
|
||||||
switch (uiReg) {
|
switch (uiReg) {
|
||||||
@@ -306,9 +140,12 @@ static void SensorDataUpdata(uint32_t uiReg, uint32_t uiRegNum) {
|
|||||||
}
|
}
|
||||||
uiReg++;
|
uiReg++;
|
||||||
}
|
}
|
||||||
}
|
// Serial.println(s_cDataUpdate);
|
||||||
|
};
|
||||||
|
|
||||||
static void AutoScanSensor(void) {
|
static void Delayms(uint16_t ucMs) { delay(ucMs); }
|
||||||
|
|
||||||
|
static void AutoScanSensor() {
|
||||||
int i, iRetry;
|
int i, iRetry;
|
||||||
|
|
||||||
for (i = 0; i < sizeof(c_uiBaud) / sizeof(c_uiBaud[0]); i++) {
|
for (i = 0; i < sizeof(c_uiBaud) / sizeof(c_uiBaud[0]); i++) {
|
||||||
@@ -333,3 +170,165 @@ static void AutoScanSensor(void) {
|
|||||||
Serial.print("can not find sensor\r\n");
|
Serial.print("can not find sensor\r\n");
|
||||||
Serial.print("please check your connection\r\n");
|
Serial.print("please check your connection\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Test on MEGA 2560. use WT901CTTL sensor
|
||||||
|
|
||||||
|
WT901CTTL MEGA 2560a
|
||||||
|
VCC <---> 5V/3.3V
|
||||||
|
TX <---> 19(TX1)
|
||||||
|
RX <---> 18(RX1)
|
||||||
|
GND <---> GND
|
||||||
|
*/
|
||||||
|
|
||||||
|
// #define ACC_UPDATE 0x01
|
||||||
|
// #define GYRO_UPDATE 0x02
|
||||||
|
// #define ANGLE_UPDATE 0x04
|
||||||
|
// #define MAG_UPDATE 0x08
|
||||||
|
// #define READ_UPDATE 0x80
|
||||||
|
// static volatile char s_cDataUpdate = 0, s_cCmd = 0xff;
|
||||||
|
|
||||||
|
// static void CmdProcess(void);
|
||||||
|
// static void AutoScanSensor(void);
|
||||||
|
// static void SensorUartSend(uint8_t *p_data, uint32_t uiSize);
|
||||||
|
// static void SensorDataUpdata(uint32_t uiReg, uint32_t uiRegNum);
|
||||||
|
// static void Delayms(uint16_t ucMs);
|
||||||
|
// const uint32_t c_uiBaud[8] = {0, 4800, 9600, 19200,
|
||||||
|
// 38400, 57600, 115200, 230400};
|
||||||
|
|
||||||
|
// int i;
|
||||||
|
// float fAcc[3], fGyro[3], fAngle[3];
|
||||||
|
|
||||||
|
// void setup() {
|
||||||
|
// // put your setup code here, to run once:
|
||||||
|
// Serial.begin(115200);
|
||||||
|
// WitInit(WIT_PROTOCOL_NORMAL, 0x50);
|
||||||
|
// WitSerialWriteRegister(SensorUartSend);
|
||||||
|
// WitRegisterCallBack(SensorDataUpdata);
|
||||||
|
// WitDelayMsRegister(Delayms);
|
||||||
|
// AutoScanSensor();
|
||||||
|
|
||||||
|
// // if (WitStartAccCali() == WIT_HAL_OK) {
|
||||||
|
// // Serial.print("Start Calibri");
|
||||||
|
// // delay(1000);
|
||||||
|
// // Serial.print("Stop calibri");
|
||||||
|
// // WitStopAccCali();
|
||||||
|
// // } else {
|
||||||
|
// // Serial.print("Cannot start calibri acc\r\n");
|
||||||
|
// // }
|
||||||
|
|
||||||
|
// if (WitSetUartBaud(WIT_BAUD_9600) != WIT_HAL_OK)
|
||||||
|
// Serial.print("\r\nSet Baud Error\r\n");
|
||||||
|
// else {
|
||||||
|
// Serial1.begin(c_uiBaud[WIT_BAUD_9600]);
|
||||||
|
// Serial.print(" 9600 Baud rate modified successfully\r\n");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// void loop() {
|
||||||
|
// while (Serial1.available()) {
|
||||||
|
// WitSerialDataIn(Serial1.read());
|
||||||
|
// }
|
||||||
|
// if (s_cDataUpdate) {
|
||||||
|
// for (i = 0; i < 3; i++) {
|
||||||
|
// fAcc[i] = sReg[AX + i] / 32768.0f * 16.0f * 9.8f; // Unit: m/s^2
|
||||||
|
// fGyro[i] = sReg[GX + i] / 32768.0f * 2000.0f; // Unit: deg/s
|
||||||
|
// fAngle[i] = sReg[Roll + i] / 32768.0f * 180.0f; // Unit: deg
|
||||||
|
// }
|
||||||
|
// if (s_cDataUpdate & ACC_UPDATE) {
|
||||||
|
// Serial.print("acc:");
|
||||||
|
// Serial.print(fAcc[0], 3);
|
||||||
|
// Serial.print(" ");
|
||||||
|
// Serial.print(fAcc[1], 3);
|
||||||
|
// Serial.print(" ");
|
||||||
|
// Serial.print(fAcc[2], 3);
|
||||||
|
// Serial.print("\r\n");
|
||||||
|
// s_cDataUpdate &= ~ACC_UPDATE;
|
||||||
|
// }
|
||||||
|
// if (s_cDataUpdate & GYRO_UPDATE) {
|
||||||
|
// Serial.print("gyro:");
|
||||||
|
// Serial.print(fGyro[0], 1);
|
||||||
|
// Serial.print(" ");
|
||||||
|
// Serial.print(fGyro[1], 1);
|
||||||
|
// Serial.print(" ");
|
||||||
|
// Serial.print(fGyro[2], 1);
|
||||||
|
// Serial.print("\r\n");
|
||||||
|
// s_cDataUpdate &= ~GYRO_UPDATE;
|
||||||
|
// }
|
||||||
|
// if (s_cDataUpdate & ANGLE_UPDATE) {
|
||||||
|
// Serial.print("angle:");
|
||||||
|
// Serial.print(fAngle[0], 3);
|
||||||
|
// Serial.print(" ");
|
||||||
|
// Serial.print(fAngle[1], 3);
|
||||||
|
// Serial.print(" ");
|
||||||
|
// Serial.print(fAngle[2], 3);
|
||||||
|
// Serial.print("\r\n");
|
||||||
|
// s_cDataUpdate &= ~ANGLE_UPDATE;
|
||||||
|
// }
|
||||||
|
// if (s_cDataUpdate & MAG_UPDATE) {
|
||||||
|
// Serial.print("mag:");
|
||||||
|
// Serial.print(sReg[HX]);
|
||||||
|
// Serial.print(" ");
|
||||||
|
// Serial.print(sReg[HY]);
|
||||||
|
// Serial.print(" ");
|
||||||
|
// Serial.print(sReg[HZ]);
|
||||||
|
// Serial.print("\r\n");
|
||||||
|
// s_cDataUpdate &= ~MAG_UPDATE;
|
||||||
|
// }
|
||||||
|
// s_cDataUpdate = 0;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// static void SensorUartSend(uint8_t *p_data, uint32_t uiSize) {
|
||||||
|
// Serial1.write(p_data, uiSize);
|
||||||
|
// Serial1.flush();
|
||||||
|
// }
|
||||||
|
// static void Delayms(uint16_t ucMs) { delay(ucMs); }
|
||||||
|
// static void SensorDataUpdata(uint32_t uiReg, uint32_t uiRegNum) {
|
||||||
|
// int i;
|
||||||
|
// for (i = 0; i < uiRegNum; i++) {
|
||||||
|
// switch (uiReg) {
|
||||||
|
// case AZ:
|
||||||
|
// s_cDataUpdate |= ACC_UPDATE;
|
||||||
|
// break;
|
||||||
|
// case GZ:
|
||||||
|
// s_cDataUpdate |= GYRO_UPDATE;
|
||||||
|
// break;
|
||||||
|
// case HZ:
|
||||||
|
// s_cDataUpdate |= MAG_UPDATE;
|
||||||
|
// break;
|
||||||
|
// case Yaw:
|
||||||
|
// s_cDataUpdate |= ANGLE_UPDATE;
|
||||||
|
// break;
|
||||||
|
// default:
|
||||||
|
// s_cDataUpdate |= READ_UPDATE;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// uiReg++;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// static void AutoScanSensor(void) {
|
||||||
|
// int i, iRetry;
|
||||||
|
|
||||||
|
// for (i = 0; i < sizeof(c_uiBaud) / sizeof(c_uiBaud[0]); i++) {
|
||||||
|
// Serial1.begin(c_uiBaud[i]);
|
||||||
|
// Serial1.flush();
|
||||||
|
// iRetry = 2;
|
||||||
|
// s_cDataUpdate = 0;
|
||||||
|
// do {
|
||||||
|
// WitReadReg(AX, 3);
|
||||||
|
// delay(200);
|
||||||
|
// while (Serial1.available()) {
|
||||||
|
// WitSerialDataIn(Serial1.read());
|
||||||
|
// }
|
||||||
|
// if (s_cDataUpdate != 0) {
|
||||||
|
// Serial.print(c_uiBaud[i]);
|
||||||
|
// Serial.print(" baud find sensor\r\n\r\n");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// iRetry--;
|
||||||
|
// } while (iRetry);
|
||||||
|
// }
|
||||||
|
// Serial.print("can not find sensor\r\n");
|
||||||
|
// Serial.print("please check your connection\r\n");
|
||||||
|
// }
|
||||||
|
|||||||
@@ -1,50 +1,14 @@
|
|||||||
byte status = 0;
|
|
||||||
byte layer = 0;
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
pinMode(A7, INPUT_PULLUP);
|
||||||
|
pinMode(2, INPUT_PULLUP);
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
pinMode(22 + i, OUTPUT);
|
pinMode(22 + i, OUTPUT);
|
||||||
|
digitalWrite(22 + i, HIGH);
|
||||||
}
|
}
|
||||||
// pinMode(30, OUTPUT);
|
Serial.begin(115200);
|
||||||
// pinMode(31, OUTPUT);
|
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++) {
|
|
||||||
pinMode(30 + i, OUTPUT);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++) {
|
|
||||||
pinMode(38 + i, OUTPUT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int column = 0;
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (Serial.available()) {
|
Serial.println(digitalRead(2));
|
||||||
int num = Serial.read();
|
delay(100);
|
||||||
if (num >= '0' && num <= '7') {
|
|
||||||
num = num - '0';
|
|
||||||
status ^= 1 << num;
|
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++) {
|
|
||||||
digitalWrite(22 + i, status >> i & 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.println(status, BIN);
|
|
||||||
} else if (num >= 'a' && num <= 'h') {
|
|
||||||
num = num - 'a';
|
|
||||||
column = num;
|
|
||||||
Serial.print("LOAD");
|
|
||||||
Serial.print(num);
|
|
||||||
Serial.println(status, BIN);
|
|
||||||
digitalWrite(30 + column, HIGH);
|
|
||||||
digitalWrite(30 + column, LOW);
|
|
||||||
}
|
|
||||||
else if (num == 'z') {
|
|
||||||
digitalWrite(38 + layer, LOW);
|
|
||||||
layer = (layer + 1) % 8;
|
|
||||||
digitalWrite(38 + layer, HIGH);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user