mirror of
https://gitlab.dit.htwk-leipzig.de/phillip.kuehne/dezibot.git
synced 2025-05-19 11:01:46 +02:00
implemented read functions for Gyro / Accelerometer
This commit is contained in:
parent
e42a471a33
commit
650250f9de
@ -0,0 +1,27 @@
|
|||||||
|
#include "Dezibot.h"
|
||||||
|
Dezibot dezibot = Dezibot();
|
||||||
|
void setup() {
|
||||||
|
// put your setup code here, to run once:
|
||||||
|
dezibot.begin();
|
||||||
|
Serial.begin(115200);
|
||||||
|
}
|
||||||
|
|
||||||
|
int indices = 0;
|
||||||
|
void loop() {
|
||||||
|
// put your main code here, to run repeatedly:
|
||||||
|
|
||||||
|
|
||||||
|
int zvalue = 0;
|
||||||
|
for(int i = 0; i<30;i++){
|
||||||
|
zvalue += dezibot.motionDetection.getAcceleration().z;
|
||||||
|
}
|
||||||
|
zvalue = zvalue/30;
|
||||||
|
if(zvalue < -1700){
|
||||||
|
dezibot.multiColorLight.setLed(ALL,0x00FF00);
|
||||||
|
} else if(zvalue > 1700){
|
||||||
|
dezibot.multiColorLight.setLed(ALL,0xFF0000);
|
||||||
|
} else {
|
||||||
|
dezibot.multiColorLight.turnOffLed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
26
example/Led/ColorCycle/ColorCycle/ColorCycle.ino
Normal file
26
example/Led/ColorCycle/ColorCycle/ColorCycle.ino
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#include "Dezibot.h"
|
||||||
|
|
||||||
|
|
||||||
|
Dezibot dezibot = Dezibot();
|
||||||
|
void setup() {
|
||||||
|
// put your setup code here, to run once:
|
||||||
|
dezibot.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// put your main code here, to run repeatedly:
|
||||||
|
for (int d = 0; d < 255; d++) {
|
||||||
|
dezibot.multiColorLight.setLed(ALL,dezibot.multiColorLight.color(d,0,255-d));
|
||||||
|
delay(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int d = 0; d < 255; d++) {
|
||||||
|
dezibot.multiColorLight.setLed(ALL, dezibot.multiColorLight.color(255-d, d, 0));
|
||||||
|
delay(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int d = 0; d < 255; d++) {
|
||||||
|
dezibot.multiColorLight.setLed(ALL, dezibot.multiColorLight.color(0, 255-d, d));
|
||||||
|
delay(2);
|
||||||
|
}
|
||||||
|
}
|
@ -10,14 +10,12 @@ void MotionDetection::begin(void){
|
|||||||
handler->begin(36,37,35,34);
|
handler->begin(36,37,35,34);
|
||||||
|
|
||||||
handler->beginTransaction(SPISettings(frequency,SPI_MSBFIRST,SPI_MODE0));
|
handler->beginTransaction(SPISettings(frequency,SPI_MSBFIRST,SPI_MODE0));
|
||||||
|
|
||||||
digitalWrite(34,LOW);
|
digitalWrite(34,LOW);
|
||||||
// set Accel and Gyroscop to Low Noise
|
// set Accel and Gyroscop to Low Noise
|
||||||
handler->transfer(0x1F);
|
handler->transfer(0x1F);
|
||||||
handler->transfer(0x0F);
|
handler->transfer(0x0F);
|
||||||
//busy Wait for startup
|
//busy Wait for startup
|
||||||
delayMicroseconds(200);
|
delayMicroseconds(200);
|
||||||
|
|
||||||
digitalWrite(34,HIGH);
|
digitalWrite(34,HIGH);
|
||||||
handler->endTransaction();
|
handler->endTransaction();
|
||||||
};
|
};
|
||||||
@ -32,37 +30,27 @@ void MotionDetection::end(void){
|
|||||||
};
|
};
|
||||||
IMUResult MotionDetection::getAcceleration(){
|
IMUResult MotionDetection::getAcceleration(){
|
||||||
IMUResult result;
|
IMUResult result;
|
||||||
handler->beginTransaction(SPISettings(frequency,SPI_MSBFIRST,SPI_MODE0));
|
|
||||||
digitalWrite(34,LOW);
|
|
||||||
result.x = readRegister(ACCEL_DATA_X_HIGH)<<8;
|
result.x = readRegister(ACCEL_DATA_X_HIGH)<<8;
|
||||||
result.x |= readRegister(ACCEL_DATA_X_LOW);
|
result.x |= readRegister(ACCEL_DATA_X_LOW);
|
||||||
result.y = readRegister(ACCEL_DATA_Y_HIGH)<<8;
|
result.y = readRegister(ACCEL_DATA_Y_HIGH)<<8;
|
||||||
result.y |= readRegister(ACCEL_DATA_Y_LOW);
|
result.y |= readRegister(ACCEL_DATA_Y_LOW);
|
||||||
result.z = readRegister(ACCEL_DATA_Z_HIGH)<<8;
|
result.z = readRegister(ACCEL_DATA_Z_HIGH)<<8;
|
||||||
result.z |= readRegister(ACCEL_DATA_Z_LOW);
|
result.z |= readRegister(ACCEL_DATA_Z_LOW);
|
||||||
digitalWrite(34,HIGH);
|
|
||||||
handler->endTransaction();
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
IMUResult MotionDetection::getRotation(){
|
IMUResult MotionDetection::getRotation(){
|
||||||
IMUResult result;
|
IMUResult result;
|
||||||
handler->beginTransaction(SPISettings(frequency,SPI_MSBFIRST,SPI_MODE0));
|
result.x = readRegister(GYRO_DATA_X_HIGH) <<8;
|
||||||
digitalWrite(34,LOW);
|
result.x |= readRegister(GYRO_DATA_X_LOW);
|
||||||
result.x = handler->transfer16(cmdRead(GYRO_DATA_X_HIGH,GYRO_DATA_X_LOW));
|
result.y = readRegister(GYRO_DATA_Y_HIGH)<<8;
|
||||||
result.y = handler->transfer16(cmdRead(GYRO_DATA_Y_HIGH,GYRO_DATA_Y_LOW));
|
result.y |= readRegister(GYRO_DATA_Y_LOW);
|
||||||
result.z = handler->transfer16(cmdRead(GYRO_DATA_Z_HIGH,GYRO_DATA_Z_LOW));
|
result.z = readRegister(GYRO_DATA_Z_HIGH)<<8;
|
||||||
digitalWrite(34,HIGH);
|
result.z |= readRegister(GYRO_DATA_Z_LOW);
|
||||||
handler->endTransaction();
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
float MotionDetection::getTemperature(){
|
float MotionDetection::getTemperature(){
|
||||||
handler->beginTransaction(SPISettings(frequency,SPI_MSBFIRST,SPI_MODE0));
|
int16_t raw_temperatur = readRegister(REG_TEMP_HIGH)<<8;
|
||||||
digitalWrite(34,LOW);
|
raw_temperatur |= readRegister(REG_TEMP_LOW);
|
||||||
handler -> write(cmdRead(REG_TEMP_HIGH,REG_TEMP_LOW));
|
|
||||||
int16_t raw_temperatur = handler->transfer16(cmdRead(REG_TEMP_HIGH,REG_TEMP_LOW));
|
|
||||||
|
|
||||||
digitalWrite(34,HIGH);
|
|
||||||
handler->endTransaction();
|
|
||||||
return raw_temperatur/128 +25;
|
return raw_temperatur/128 +25;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -70,14 +58,6 @@ int8_t MotionDetection::getWhoAmI(){
|
|||||||
return readRegister(WHO_AM_I);
|
return readRegister(WHO_AM_I);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint16_t MotionDetection::cmdRead(uint8_t regHigh,uint8_t regLow){
|
|
||||||
return (CMD_READ | (regHigh & ADDR_MASK))<<8 & (CMD_READ | regLow & ADDR_MASK);
|
|
||||||
};
|
|
||||||
uint16_t MotionDetection::cmdWrite(uint8_t regHigh,uint8_t regLow){
|
|
||||||
return (CMD_WRITE | (regHigh & ADDR_MASK))<<8 & (CMD_WRITE | regLow & ADDR_MASK);
|
|
||||||
};
|
|
||||||
uint8_t MotionDetection::cmdRead(uint8_t reg){
|
uint8_t MotionDetection::cmdRead(uint8_t reg){
|
||||||
return (CMD_READ | (reg & ADDR_MASK));
|
return (CMD_READ | (reg & ADDR_MASK));
|
||||||
};
|
};
|
||||||
@ -95,7 +75,3 @@ int8_t MotionDetection::readRegister(uint8_t reg){
|
|||||||
handler->endTransaction();
|
handler->endTransaction();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
int16_t MotionDetection::readDoubleRegister(uint8_t lowerReg){
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user