Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

change color with a gesture 1D



  • Hi all,
    i have this situation:

    void Luce::gesture(int result)
    {
    
        int valore[1000]= {0};
        for (int i = 0;i< 1001;i++) {
          valore[i] = result;
        }
    
         int primo = valore[0];
         int ultimo = valore[999];
         qDebug()<< primo << ultimo << endl;
         if (primo != ultimo)
         {
           on_pushButton_released();
         }
    
         else {
             return;
         }
    }
    
    

    I create this program that receives data (result) from a serial port.
    i want to create this gesture:
    if result is a decreasing data (so 'primo', the first value, is higher than 'ultimo', the last data of my array) my led has to change color. It should appears like a hand that get close and closer to the range sensor.
    I wrote this and compiled, but the program close forcefully and crashed.
    Any idea of why and how can i resolve it?
    Thanks to everybody.



  • i worked on it and i change the code:

    int valore[100]= {0};
    int prev = 0 ;
    int next= 0 ;
    
    for (int i = 0;i< 100;i++)
        {
            if(i == 0)
                {
                    next= prev;
                    valore[i] = 0;
                   //qDebug()<< "this is  if"<<endl;
                }
            else {
                valore[i] = result;  
                prev = valore[i-1];
                next = valore[i];             // qDebug()<< " this is else"<<endl;
    
                    if( prev > next)
                    {
                        qDebug()<<"this is my if 2"<<endl;
                        on_pushButton_released();
                    }
            }
        }
    

Log in to reply