Multiple case - Fade without delay

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

I am not sure what you are askin, it appears you want for somebody to write your code. There is a section here where you can pay somebody to do it. If you want help with your code you will need to post it with questions as to what is happening and what you need help with.

Ok please transfer this thread in paid section

Click on the flag icon below the post, you will get a window to send a moderator a request to move it.

2 Likes

Moved as requested.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.