From ae2b94d7690059849ee4678c58dac624ea9ccda3 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sun, 10 Apr 2016 08:44:57 +0200 Subject: new version Signed-off-by: Olivier Gayot --- sketch_apr09a/sketch_apr09a.ino | 82 +++++++++++++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 12 deletions(-) (limited to 'sketch_apr09a/sketch_apr09a.ino') diff --git a/sketch_apr09a/sketch_apr09a.ino b/sketch_apr09a/sketch_apr09a.ino index 284a2a1..249ee1c 100644 --- a/sketch_apr09a/sketch_apr09a.ino +++ b/sketch_apr09a/sketch_apr09a.ino @@ -1,6 +1,35 @@ +#include +#include #include "Belt.h" #include "logs.h" +// Belt sensors +int PhotoSenspin1 = 0; // premier photo sensor +int PhotoSensReading1; //premier photo sensor +int PhotoSenspin2 = 1; // deuxieme photo sensor +int PhotoSensReading2; //deuxieme photo sensor + +//Object that for the sensor +NAxisMotion mySensor; + +//Flag to indicate if an interrupt was detected +bool intDetected = false; + +//At a Range of 4g, the threshold +//is set at 39.05mg or 0.3830m/s2. +//This Range is the default for NDOF Mode +int threshold = 5; + +//At a filter Bandwidth of 62.5Hz, +//the duration is 8ms. +//This Bandwidth is the default for NDOF Mode +int duration = 1; +bool anyMotion = true; + +//To store the last streamed time stamp +unsigned long lastStreamTime = 0; +const int streamPeriod = 500; + Belt::Belt() { _pin_pressure_bottom = 0; @@ -38,11 +67,6 @@ void Belt::read_angle_z() static Belt belt; -void setup() -{ - Serial.begin(9600); -} - static void send_pressure_bottom(int pressure) { serial_printf("PRESSURE_BOTTOM:%d\n", pressure); @@ -68,9 +92,27 @@ static void send_angle_z(int angle) serial_printf("ANGLE_Z:%d\n", angle); } +void setup() +{ + Serial.begin(115200); //Initialize the Serial Port to view information on the Serial Monitor + I2C.begin(); //Initialize I2C communication to the let the library communicate with the sensor. + mySensor.initSensor(); //The I2C Address can be changed here inside this function in the library + mySensor.setOperationMode(OPERATION_MODE_NDOF); //Can be configured to other operation modes as desired + mySensor.setUpdateMode(MANUAL); //The default is AUTO. Changing to MANUAL requires calling the relevant update functions prior to calling the read functions + //Setting to MANUAL requires fewer reads to the sensor +} + void loop() { - delay(500); + if ((millis() - lastStreamTime) < streamPeriod) { + return; + } + + lastStreamTime = millis(); + mySensor.updateEuler(); //Update the Euler data into the structure of the object + mySensor.updateCalibStatus(); //Update the Calibration Status + PhotoSensReading1 = analogRead(PhotoSenspin1); + PhotoSensReading2 = analogRead(PhotoSenspin2); /* fetch the values from the sensors */ belt.read_pressure_bottom(); @@ -80,10 +122,26 @@ void loop() belt.read_angle_y(); belt.read_angle_z(); - serial_printf("PRESSURE_BOTTOM: bottom:%d\n", belt.get_pressure_bottom()); - serial_printf("PRESSURE_TOP:%d\n", belt.get_pressure_top()); - serial_printf("FLEXION:%d\n", belt.get_flexion()); - serial_printf("ANGLE_X:%d\n", belt.get_angle_x()); - serial_printf("ANGLE_Y:%d\n", belt.get_angle_y()); - serial_printf("ANGLE_Z:%d\n", belt.get_angle_z()); + int heading = mySensor.readEulerHeading(); + int pitch = mySensor.readEulerPitch(); + int roll = mySensor.readEulerRoll(); + + serial_printf("pitch: [%d]\n", pitch); + //pitch = map(pitch, 1, 1023, 90, 270); + serial_printf("pitch_mapped: [%d]\n", pitch); + serial_puts("-------"); + serial_printf("roll: [%d]\n", roll); + //roll = map(roll, 1, 1023, 90, 270); + serial_printf("roll_mapped: [%d]\n", roll); + serial_puts("-------"); + serial_printf("heading: [%d]\n", heading); + //heading = map(heading, 1, 1023, 90, 270); + serial_printf("heading_mapped: [%d]\n", heading); + + serial_printf("ANGLE_X:%d\n", pitch); + serial_printf("ANGLE_Y:%d\n", roll); + serial_printf("ANGLE_Z:%d\n", heading); + + serial_printf("PRESSURE_TOP:%d\n", PhotoSenspin1); + serial_printf("PRESSURE_BOTTOM:%d\n", PhotoSenspin1); } -- cgit v1.2.3