-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccel.cpp
More file actions
40 lines (34 loc) · 731 Bytes
/
accel.cpp
File metadata and controls
40 lines (34 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#define F_CPU 16000000L
#include "ADXL345/Accel.h"
#include "USART/USART.h"
#include "Motors/Motors.h"
#include <avr/delay.h>
#include <string.h>
int main(void){
USART uart;
Accel acc;
int mp[4] ={1,2,3,4};
char raw[6];
float a[3];
char strnum [8];
acc.Enter_meas_mode();
DDRD |= (1<<DDD2);
while(1){
//uart.put_str("\nX=");
PORTD = 1<<2;
//UDR0=(a);
acc.GetAccels(a);
float roll = atan2(a[1], a[2]) * 180/3.14;
float pitch = atan2(-a[0], sqrt(a[1]*a[1] + a[2]*a[2])) * 180/3.14;
char str[10];
dtostrf(roll,6,4,str);
uart.put_str(" roll:");
uart.put_str(str);
dtostrf(pitch,6,4,str);
uart.put_str(" pitch:");
uart.put_str(str);
uart.put_str("\n");
PORTD = 0<<2;
_delay_ms(500);
}
}