Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perl Example #4

Open
gevrey opened this issue May 7, 2015 · 1 comment
Open

Perl Example #4

gevrey opened this issue May 7, 2015 · 1 comment

Comments

@gevrey
Copy link

gevrey commented May 7, 2015

# !/usr/bin/perl
# test1.pl

use wiringpi;
use constant {
    OUTPUT=>1,
    INPUT=>0,
    HIGH=>1,
    LOW=>0
};

$SIG{'INT'}=&safe_exit;
$SIG{'QUIT'}=&safe_exit;
$SIG{**DIE**}=&safe_exit;

print("Raspberry Pi wiringPi test program\n");
if( wiringpi::wiringPiSetup()==-1 ){
    die 1;
}

for( my $pin=0;$pin<8;++$pin ){
    wiringpi::pinMode($pin,OUTPUT);
}

wiringpi::pinMode(8,INPUT);

@data=(
        [0,1,1],
        [1,1,1],
    [0,0,0],[2,1,1],
    [1,0,0],[3,1,1],
    [2,0,0],[4,1,1],
    [3,0,0],[5,1,1],
    [4,0,0],[6,1,1],
    [5,0,0],[7,1,1],
    [6,0,1],
    [7,0,1],
        [7,1,1],
        [6,1,1],
    [7,0,0],[5,1,1],
    [6,0,0],[4,1,1],
    [5,0,0],[3,1,1],
    [4,0,0],[2,1,1],
    [3,0,0],[1,1,1],
    [2,0,0],[0,1,1],
    [1,0,1],
    [0,0,1],
    [9,9,9]
);

my $inc=0;

while( 1==1 ){
    my( $pin,$state,$duration )=@{$data[$inc]};
    if( $pin+$state+$duration==27 ){
        $inc=0;
        next;
    }
    wiringpi::digitalWrite($pin,$state);
    if( wiringpi::digitalRead(8)==LOW ){
        wiringpi::delay($duration_10);
    }else{
        wiringpi::delay( $duration_100 );
    }
    ++$inc;
}
# this just turns off all the LEDs when you exit the script

sub safe_exit{
    for( my $pin=0;$pin<8;++$pin ){
        wiringpi::digitalWrite($pin,LOW);
    }
    exit 1;
}
@Gadgetoid
Copy link
Member

This is super useful, thank you. I've tweaked your comment to wrap the code in Syntax highlighting markup so it looks all nice here ;)

Gadgetoid added a commit that referenced this issue Oct 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants