Skip to content
Snippets Groups Projects
Commit e1c28133 authored by 13035516's avatar 13035516
Browse files

added i2c communication and acceleration comms

parent 0f581c35
No related merge requests found
......@@ -64,6 +64,18 @@ typedef struct {
};
} uint16_vec;
/* typedef union */
typedef struct {
union {
int vals[3];
struct {
int val1;
int val2;
int val3;
};
};
} int_vec;
// Packed attribute specifies each member of the structure or union is placed
// to minimize the memory required.
// 1 byte is 16 bits
......
......@@ -6,6 +6,10 @@
#include "Accelerometer.h"
#include "SerialCommunication.h"
#include <Wire.h>
#include <Adafruit_MMA8451.h>
#include <Adafruit_Sensor.h>
#include <stdio.h>
#include <stdlib.h>
......@@ -26,9 +30,20 @@ Potentiometer ShaftPot(POT1_PIN);
DIPSwitch DSwitch[3] = {SWITCH_PIN1, SWITCH_PIN2, SWITCH_PIN3};
SerialCommunication SerCom;
Accelerometer Accel[3] = {XACC_PIN, YACC_PIN, ZACC_PIN};
Adafruit_MMA8451 mma = Adafruit_MMA8451();
void setup() {
SerCom.Serial_Setup();
// I2C setup
if (!mma.begin()) {
Serial.println("couldn't start i2c");
while(1);
} else {
Serial.println("MMA8451 found!");
mma.setRange(MMA8451_RANGE_2_G);
}
Pot.Set_Pin_Mode();
ShaftPot.Set_Pin_Mode();
VibeMotor.Set_Pin_Mode();
......@@ -50,6 +65,16 @@ void loop() {
DSwitch[i].Read_DIPSwitch();
Accel[i].Read_Accelerometer();
}
// Read the 'raw' data in 14-bit counts
mma.read();
pkt_out.acc_val.pin_vals[0] = (uint16_t)mma.x;
pkt_out.acc_val.pin_vals[1] = (uint16_t)mma.y;
pkt_out.acc_val.pin_vals[2] = (uint16_t)mma.z;
/* Serial.print("X(raw): \t"); Serial.println(mma.x); */
/* Serial.print("X: \t"); Serial.println(pkt_out.acc_val.pin_vals[0]); */
Pot.Read_Potentiometer();
pot_val = Pot.Get_Val();
......@@ -77,7 +102,7 @@ void loop() {
for (int j = 0 ; j < 3; j++) {
pkt_out.dip_val.pin_vals[j] = (uint16_t)DSwitch[j].Get_Val();
pkt_out.acc_val.pin_vals[j] = Accel[j].Get_Accel();
/* pkt_out.acc_val.pin_vals[j] = Accel[j].Get_Accel(); */
}
pkt_out.pot_val = Pot.Get_Val();
pkt_out.shaftpot_val = ShaftPot.Get_Val();
......@@ -99,7 +124,7 @@ void loop() {
Serial.print("bytes_sent: ");
Serial.println(bytes_sent);
*/
/* Serial.println(shaftpot_val); */
bytes_sent = SerCom.Send_Packet();
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment