hallo, based on this code
#include <Wire.h>
#include <MPU6050.h>
const int Led1 = 11;
const int Led2 = 12;
const int Button1 = 2;
MPU6050 mpu;
void setup()
{
Serial.begin(9600);
Serial.println("Initialize MPU6050");
while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
{
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
delay(500);
}
}
void loop()
{
// Read normalized values
Vector normAccel = mpu.readNormalizeAccel();
// Calculate Pitch & Roll
int pitch = -(atan2(normAccel.XAxis, sqrt(normAccel.YAxis*normAccel.YAxis + normAccel.ZAxis*normAccel.ZAxis))*180.0)/M_PI;
int roll = (atan2(normAccel.YAxis, normAccel.ZAxis)*180.0)/M_PI;
// Output
Serial.print(" Pitch = ");
Serial.print(pitch);
Serial.print(" Roll = ");
Serial.print(roll);
Serial.println();
delay(200);
}
i need:
Detect motion by pitch value change
Case1, highest priority
if pitch not between 40 and -40
Led1 and Led2 blink-fader
Case2
if pitch between 40 and -40
and motion detected by pitch value change
Led1 fade on, keep light on, intensity 50;
Led2 blink-fader;
When motion detected, restart time 30 seconds
After 30 seconds no motion detected, Led1 and Led2 fade off
Case3
if pitch between 40 and -40
and button1 keep pressed
Led2 still blink-fader without restart fade;
Led1 intensity 255;
When button released go to Case2;
Led2 still blink-fader without restart fade