In this lab, you will: Construct a prototype
Diff: main.cpp
- Revision:
- 4:7616d6fd81d8
- Parent:
- 3:33cca9e98fbb
- Child:
- 5:7f4dc37352d7
--- a/main.cpp Thu Feb 22 18:04:28 2018 +0000
+++ b/main.cpp Tue Feb 27 15:19:12 2018 +0000
@@ -8,25 +8,25 @@
DigitalOut myled(LED1);
int adxl362_reg_print(int start, int length);
-void adxl362_get_average(int8_t avg[]);
+void adxl362_get_average(int16_t avg[]);
int main() {
pc.printf("Starting program\r\n");
adxl362.reset();
wait_ms(600); // we need to wait at least 500ms after ADXL362 reset
adxl362.set_mode(ADXL362::MEASUREMENT);
- int8_t x,y,z;
- int8_t avg[3]; // Avg values of x,y,z. x = avg[0], y = avg[1] z = avg[2]
+ int16_t x,y,z;
+ int16_t avg[3]; // Avg values of x,y,z. x = avg[0], y = avg[1] z = avg[2]
int countOverThreshHold = 0;
adxl362_reg_print(1,0); // Test of axdl_reg_print
wait_ms(1000); // wait so that values can be seen
- int threshHoldRange = 10; // threshhold difference between avg and read values
+ int threshHoldRange = 50; // threshhold difference between avg and read values
adxl362_get_average(avg);// Generate an average of what x,y,z are.
//pc.printf("xAvg = %d yAvg = %d zAvg = %d\r\n",avg[0],avg[1],avg[2]);
while(1) {
- x=adxl362.scanx_u8();
- y=adxl362.scany_u8();
- z=adxl362.scanz_u8();
+ x=adxl362.scanx();
+ y=adxl362.scany();
+ z=adxl362.scanz();
if (x > (avg[0] + threshHoldRange) || x < (avg[0] - threshHoldRange)
|| y > (avg[1] + threshHoldRange) || y < (avg[1] - threshHoldRange)
@@ -52,7 +52,7 @@
}
}
-void adxl362_get_average(int8_t avg[]) {
+void adxl362_get_average(int16_t avg[]) {
// Generate an average of what x,y,z are.
int numberOfPolls = 10;
// reset average back to zero for each
@@ -63,15 +63,15 @@
avg[0] = 0;
avg[1] = 0;
avg[2] = 0;
- int8_t x,y,z;
+ int16_t x,y,z;
// Poll each value 10 times
for (int i = 0; i < numberOfPolls; i++) {
//pc.printf("x = %d y = %d z = %d\r\n",x,y,z);
- x = adxl362.scanx_u8();
+ x = adxl362.scanx();
tmp[0]+= x;
- y = adxl362.scany_u8();
+ y = adxl362.scany();
tmp[1]+= y;
- z=adxl362.scanz_u8();
+ z=adxl362.scanz();
tmp[2]+= z;
wait_ms(10);
//pc.printf("xAvg = %d yAvg = %d zAvg = %d\r\n",tmp[0],tmp[1],tmp[2]);