mirror of
https://gitlab.dit.htwk-leipzig.de/phillip.kuehne/dezibot.git
synced 2025-05-19 02:51:47 +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);
|
||||
}
|
||||
}
|
@ -5,19 +5,17 @@ MotionDetection::MotionDetection(){//:handler(FSPI){
|
||||
};
|
||||
|
||||
void MotionDetection::begin(void){
|
||||
pinMode(34,OUTPUT);
|
||||
digitalWrite(34,HIGH);
|
||||
handler->begin(36,37,35,34);
|
||||
|
||||
handler->beginTransaction(SPISettings(frequency,SPI_MSBFIRST,SPI_MODE0));
|
||||
pinMode(34,OUTPUT);
|
||||
digitalWrite(34,HIGH);
|
||||
handler->begin(36,37,35,34);
|
||||
|
||||
handler->beginTransaction(SPISettings(frequency,SPI_MSBFIRST,SPI_MODE0));
|
||||
digitalWrite(34,LOW);
|
||||
// set Accel and Gyroscop to Low Noise
|
||||
handler->transfer(0x1F);
|
||||
handler->transfer(0x0F);
|
||||
//busy Wait for startup
|
||||
delayMicroseconds(200);
|
||||
|
||||
// set Accel and Gyroscop to Low Noise
|
||||
handler->transfer(0x1F);
|
||||
handler->transfer(0x0F);
|
||||
//busy Wait for startup
|
||||
delayMicroseconds(200);
|
||||
digitalWrite(34,HIGH);
|
||||
handler->endTransaction();
|
||||
};
|
||||
@ -32,37 +30,27 @@ void MotionDetection::end(void){
|
||||
};
|
||||
IMUResult MotionDetection::getAcceleration(){
|
||||
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_LOW);
|
||||
result.y = readRegister(ACCEL_DATA_Y_HIGH)<<8;
|
||||
result.y |= readRegister(ACCEL_DATA_Y_LOW);
|
||||
result.z = readRegister(ACCEL_DATA_Z_HIGH)<<8;
|
||||
result.z |= readRegister(ACCEL_DATA_Z_LOW);
|
||||
digitalWrite(34,HIGH);
|
||||
handler->endTransaction();
|
||||
return result;
|
||||
};
|
||||
IMUResult MotionDetection::getRotation(){
|
||||
IMUResult result;
|
||||
handler->beginTransaction(SPISettings(frequency,SPI_MSBFIRST,SPI_MODE0));
|
||||
digitalWrite(34,LOW);
|
||||
result.x = handler->transfer16(cmdRead(GYRO_DATA_X_HIGH,GYRO_DATA_X_LOW));
|
||||
result.y = handler->transfer16(cmdRead(GYRO_DATA_Y_HIGH,GYRO_DATA_Y_LOW));
|
||||
result.z = handler->transfer16(cmdRead(GYRO_DATA_Z_HIGH,GYRO_DATA_Z_LOW));
|
||||
digitalWrite(34,HIGH);
|
||||
handler->endTransaction();
|
||||
result.x = readRegister(GYRO_DATA_X_HIGH) <<8;
|
||||
result.x |= readRegister(GYRO_DATA_X_LOW);
|
||||
result.y = readRegister(GYRO_DATA_Y_HIGH)<<8;
|
||||
result.y |= readRegister(GYRO_DATA_Y_LOW);
|
||||
result.z = readRegister(GYRO_DATA_Z_HIGH)<<8;
|
||||
result.z |= readRegister(GYRO_DATA_Z_LOW);
|
||||
return result;
|
||||
};
|
||||
float MotionDetection::getTemperature(){
|
||||
handler->beginTransaction(SPISettings(frequency,SPI_MSBFIRST,SPI_MODE0));
|
||||
digitalWrite(34,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();
|
||||
int16_t raw_temperatur = readRegister(REG_TEMP_HIGH)<<8;
|
||||
raw_temperatur |= readRegister(REG_TEMP_LOW);
|
||||
return raw_temperatur/128 +25;
|
||||
};
|
||||
|
||||
@ -70,14 +58,6 @@ int8_t MotionDetection::getWhoAmI(){
|
||||
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){
|
||||
return (CMD_READ | (reg & ADDR_MASK));
|
||||
};
|
||||
@ -94,8 +74,4 @@ int8_t MotionDetection::readRegister(uint8_t reg){
|
||||
digitalWrite(34,HIGH);
|
||||
handler->endTransaction();
|
||||
return result;
|
||||
};
|
||||
|
||||
int16_t MotionDetection::readDoubleRegister(uint8_t lowerReg){
|
||||
return 0;
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user