Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <libs/Wire/Wire.h>
- #define POT_ADDR 0x2e
- #define ADXL345_ADDR 0x53
- #define DATAX0 0x32
- void get_pot_data();
- void get_accel_data();
- void format_accel_data(int16_t *x, int16_t *y, int16_t *z);
- void setup_adc();
- int get_adc_data();
- int val = 0;
- int adcPin = A6;
- byte accel_buff[6];
- int16_t adc_out = 0;
- int16_t x = 0;
- int16_t y = 0;
- int16_t z = 0;
- void setup() {
- delay(5000);
- analogReference(DEFAULT);
- Wire.begin();
- Serial.begin(9600);
- setup_adc();
- }
- void setup_adc() {
- Wire.beginTransmission(ADXL345_ADDR);
- Wire.write(0x2D);
- Wire.write(0x08);
- Wire.endTransmission();
- }
- void loop() {
- get_accel_data();
- format_accel_data(&x, &y, &z);
- val = get_adc_data();
- Serial.print(micros());
- Serial.print(";");
- Serial.print(val);
- Serial.print(";");
- Serial.print(x);
- Serial.print(";");
- Serial.print(y);
- Serial.print(";");
- Serial.print(z);
- Serial.print(";");
- Serial.println("");
- }
- void get_accel_data() {
- Wire.beginTransmission(ADXL345_ADDR);
- Wire.write(DATAX0);
- Wire.endTransmission();
- Wire.requestFrom(ADXL345_ADDR, 6);
- int i = 0;
- while (Wire.available()) {
- accel_buff[i] = Wire.read();
- i++;
- }
- }
- void format_accel_data(int16_t *x, int16_t *y, int16_t *z) {
- *x = (((int)accel_buff[1]) << 8) | accel_buff[0];
- *y = (((int)accel_buff[3]) << 8) | accel_buff[2];
- *z = (((int)accel_buff[5]) << 8) | accel_buff[4];
- }
- int get_adc_data() {
- int val = analogRead(adcPin);
- return val;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement