Edzelf / ESP32-Radio

Internet radio based on ESP32, VS1053 and a TFT screen.
GNU General Public License v3.0
987 stars 229 forks source link

High active Sensor how to / STOP after time #298

Open p1mike opened 4 years ago

p1mike commented 4 years ago

Hi Ed, my idea is, to use a motion control sensor to switch the radio on for 10-15minutes or better to switch between STOP and PLAY mode. But my motion sensor is HIGH active and I'm not sure how to change your default procedures for LOW active GPIOs. So I wish a suggestion for this and if you have: best point in code to change the radio mode after time and also for change to play mode. Sending ESP32 into deep sleep is (for now) not an option, because boot time is too long (15s). Best Mike

Edzelf commented 4 years ago

Look for the function "scandigital". It should be near line 3096. Change the part in line 3118-3130:

    level = ( digitalRead ( pinnr ) == HIGH ) ;             // Sample the pin
    if ( level != progpin[i].cur )                          // Change seen?
    {
      progpin[i].cur = level ;                              // And the new level
      if ( level )                                         // LOW to HIGH change?
      {
        dbgprint ( "GPIO_%02d is now HIGH, execute %s",
                   pinnr, progpin[i].command.c_str() ) ;
        reply = analyzeCmd ( progpin[i].command.c_str() ) ; // Analyze command and handle it
        dbgprint ( reply ) ;                                // Result for debugging
      }
    }

So: "If ( !level )" changes to "if ( level )" and "LOW" in de dbgprint line changes to "HIGH".

p1mike commented 4 years ago

Hi Ed, thank you. I have changed pin initialising in setup and it works:

for ( i = 0 ; (pinnr = progpin[i].gpio) >= 0 ; i++ ) // Check programmable input pins { if (pinnr == motion_pin) pinMode ( pinnr, INPUT ) ; // Input for motion control sensor else pinMode ( pinnr, INPUT_PULLUP ) ; // Input for control button delay ( 10 ) ;