GPIO Quirk

10 views
Skip to first unread message

James Lynes

unread,
Jun 22, 2020, 3:54:50 PM6/22/20
to HiPi Perl
Noticed today while running a series of test scripts that if I CTRL-C out of a script, the GPIO pins hold their last state. I ended up with LEDs on that shouldn't be. I guess this could be an issue if the pin is driving some actuator.

I don't see this as an error, but I guess I get to learn how to trap this interrupt and set all the outputs off before exiting.

James

James Lynes

unread,
Jun 22, 2020, 7:40:11 PM6/22/20
to HiPi Perl
SOLUTION
---------------

$SIG{INT} = \&trapcc                                 # Trap CTRL-C Signal

sub trapcc {
    $led1->value(RPI_LOW);                       # Force the LEDs off
    $led2->value(RPI_LOW);
    $led3->value(RPI_LOW);
    die "Terminated by CTRL-C Signal\n\n"  # Kill the script
}


James
Reply all
Reply to author
Forward
0 new messages