contrôler vlc

bonjour, j'ai suivi ce tutoriel : Amazing Control Computer Using Hand Motion and Arduino et avec du temps et de l'aide sur ce forum j'ai réussi à le contrôler !

Maintenant voilà, j'aimerai créer un espace vidéo interactif où la vidéo se met en pause quand on est à moins d'un mettre d'elle et se remet en route une fois dépassé cette zone. Si vous avez des idées je suis preneur ! voilà mon code python :

import serial #Serial imported for Serial communication
import time #Required to use delay functions
import pyautogui   #Required to to perform actions


ArduinoSerial = serial.Serial('com3',9600) #Create Serial port object called arduinoSerialData
time.sleep(2) #wait for 2 seconds for the communication to get established


while 1:
    incoming = str (ArduinoSerial.readline()) #read the serial data and print it as line
    print(incoming)
    
    if 'Play/Pause' in incoming:
        pyautogui.typewrite(['space'], 0.2)


    if 'Rewind' in incoming:
        pyautogui.hotkey('ctrl', 'left')  


    if 'Forward' in incoming:
        pyautogui.hotkey('ctrl', 'right') 


    if 'Volume Incresaed' in incoming:
        pyautogui.hotkey('ctrl', 'down')
        


    if 'Volume Decreased' in incoming:
        pyautogui.hotkey('ctrl', 'up')


    incoming = "";

et mon code arduino :

const int trigger1 = 2; //Trigger pin of 1st Sesnor
const int echo1 = 3; //Echo pin of 1st Sesnor
const int trigger2 = 4; //Trigger pin of 2nd Sesnor
const int echo2 = 5;//Echo pin of 2nd Sesnor

long time_taken;
int dist,distL,distR;

 

void setup() {
Serial.begin(9600); 
  
pinMode(trigger1, OUTPUT); 
pinMode(echo1, INPUT); 
pinMode(trigger2, OUTPUT); 
pinMode(echo2, INPUT); 
}

/*###Function to calculate distance###*/
void calculate_distance(int trigger, int echo)
{
digitalWrite(trigger, LOW);
delayMicroseconds(2);
digitalWrite(trigger, HIGH);
delayMicroseconds(10);
digitalWrite(trigger, LOW);

time_taken = pulseIn(echo, HIGH);
dist= time_taken*0.034/2;
if (dist>60)
dist = 60;
}

void loop() { //infinite loopy
calculate_distance(trigger1,echo1);
distL =dist; //get distance of left sensor

calculate_distance(trigger2,echo2);
distR =dist; //get distance of right sensor



//Pause Modes -Hold
if ((distL >40 && distR>40) && (distL <60 && distR<60)) //Detect both hands
{Serial.println("Play/Pause"); delay (500);}

calculate_distance(trigger1,echo1);
distL =dist;

calculate_distance(trigger2,echo2);
distR =dist;

 

//Control Modes
//Lock Left - Control Mode
if (distL>=13 && distL<=17)
{
  delay(100); //Hand Hold Time
  calculate_distance(trigger1,echo1);
  distL =dist;
  if (distL>=13 && distL<=17)
  {
    Serial.println("Left Locked");
    while(distL<=40)
    {
      calculate_distance(trigger1,echo1);
      distL =dist;
      if (distL<10) //Hand pushed in 
      {Serial.println ("Volume Increased"); delay (300);}
      if (distL>20) //Hand pulled out
      {Serial.println ("Volume Decreased"); delay (300);}
    }
  }
}

//Lock Right - Control Mode
if (distR>=13 && distR<=17)
{
  delay(100); //Hand Hold Time
  calculate_distance(trigger2,echo2);
  distR =dist;
  if (distR>=13 && distR<=17)
  {
    Serial.println("Right Locked");
    while(distR<=40)
    {
      calculate_distance(trigger2,echo2);
      distR =dist;
      if (distR<10) //Right hand pushed in
      {Serial.println ("Rewind"); delay (300);}
      if (distR>20) //Right hand pulled out
      {Serial.println ("Forward"); delay (300);}
  }
}
}

delay(200);
}

la vidéo se met en pause quand on est à moins d'un mètre d'elle et se remet en route une fois dépassé cette zone.

Vous avez déjà plein de code qui teste des distances... c'est à peu près similaire sauf qu'il faut mémoriser l'état dans lequel vous êtes pour ne pas déclencher des ordres tant que vous êtes trop près