Way too much file system work.
use warnings;
use strict;
use RPi::Pin;
use RPi::Const qw(:all);
my $curtain_relay_pin = 5;
my $pin = RPi::Pin->new($curtain_relay_pin);
$pin->mode(OUTPUT);
if (...) {
$pin->write(LOW);
}
elsif ($pin->read == LOW) {
$pin->write(HIGH);
}
Done. That assumes an active low relay. No need for super user access whatsoever. No touching of the file system whatsoever. Executed in fast C code that has access directly to the GPIO registers. No need for the entire RPi::WiringPi either. However, you don't get the pin security and cleanup that's provided by the encompassing distribution, but I digress.
The RPi::Pin module provides access to all related GPIO pin functionality... pull up/down resistors, PWM, interrupts, setting of alternate pin modes etc.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|