I have no experience with time or timers in coding, in fact this is my first project ever. In my project, the goal is to have an accelerometer detect positioning and notify the user when they need to readjust their orientation. By using a circuit playground bluefruit, and a haptic motor, the user can wear the device in their shirt. when the accelerometer reads a value indicating the user is inverted the motor will vibrate. But I need the motor to vibrate if and only if the user is inverted for a certain amount of time. I tried to write the "timers" code, but am lost, confused, and need help. Thank you for taking the time to read my post.
In short: if y > -8 for 10 minutes, drive motor. unless y =< -8 do nothing
FULL CODE:
#include <bluefruit.h>
#include <Adafruit_CircuitPlayground.h>
#include <Wire.h> //connects arduino library i2c
#include "Adafruit_DRV2605.h" //allows you to include the adafruit haptic driver library
Adafruit_DRV2605 drv; //sets the i2c adress to communicate to arduino
float X, Y, Z;
const int interval = 10000;
void setup() {
Serial.begin(9600);
CircuitPlayground.begin();
}
void loop() {
X = CircuitPlayground.motionX();
Y = CircuitPlayground.motionY();
Z = CircuitPlayground.motionZ();
Serial.print("X: ");
Serial.print(X);
Serial.print(" Y: ");
Serial.print(Y);
Serial.print(" Z: ");
Serial.println(Z);
delay(1000);
if ((CircuitPlayground.motionY() < -8 )){
Serial.print ("Inverted");
int startMillis = millis(); // reset the clock
if (millis() - startMillis >= interval) {
Serial.println("Motor");
drv.setWaveform(0, 47);
drv.setWaveform(1, 0);
drv.go(); //gets the vibration motor going22
}
}
}