PINE64-MAX7219

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

	#endless KnightRider effect!
	for(;;){
		$max->bullets_lrmid(1);
		$max->bullets_rlmid(1);
	}#end for

=head1 DESCRIPTION

This module is a driver for 8-digit seven-segment MAX7219 displays. It
is implemented as bit-banged SPI.  Using the object's methods, you can
set the intensity of the display, print words, and cascade multiple 
displays. It also comes with several built-in effects.  

Only three GPIO pins are required: SPI clk, SPI data, and SPI chip 
select.  This modules uses the PINE64::GPIO numbering scheme. 

=head1 METHODS

=head2 new($clock,$data,$chip_select)

Takes the GPIO pin numbers that will be used to inplement the bit-bang
SPI interface to the MAX7219 as arguments.  Returns an object to
control an 8-digit display.  

=head2 shift_in($leds, $digit, $n_cascaded, $delay, $latch_flag)

This method is only used internally.  It takes an array of a single
seven-segment's LEDs, the digit position, the number of cascaded
MAX7219 displays, a delay in usec (between SPI clock pulses), and a
latch flag.  Each individual letter of a word is shifted in one at
a time.  Once all the letters are shifted in, the latch_flag is set
high, and displays the word.  

=head2 load()

This method is only used internally. It manipulates the chip select
line, aka latch pin.  When called, it will render what has been
shifted into the display. 

=head2 print_sentence($sentence, $delay, $clear_flag)

Perhaps the most useful method.  Takes a string, however long, and
displays each word for $delay micro seconds.  $sentence could be the 
text of an entire book.  $clear_flag is not required.  

=head2 print_interleaved($string1, $string2)

This method is for use with two 8-digit displays cascaded.  $string1
will be displayed in the first display, $string2 in the cascaded
display. 

=head2 turn_on($num_cascaded)

Turns on the MAX7219 chip by writing to the turn on register.  Takes
the number of cascaded displays as an argument. Enter 1 if only 
using one display. 

=head2 set_scanlimit($num_cascaded)

Writes to the scan-limit register.  Sets it up to use all 8-digits
of the display.  Takes number of cascaded displays an arg. 

=head2 set_intensity($intensity); 

Adjusts the brightness of the display.  Takes a string as an arg.
Valid vlaues are: min, dim, mid, bright, max.  

=head2 all_off($num_cascaded)  

Turns off all digits.  Takes number of cascaded displays as an arg. 

=head2 disp_teston()

Turns on all segments on all digits.  

=head2 disp_testoff()

Turns off all segments on all digits. 

=head2 clockwise_circles($number_iterations)

lib/PINE64/MAX7219.pm  view on Meta::CPAN


#routines to control a MAX7219 8-digit LED
#display driver.  
#This is implemented as bit-banged SPI.
#data is shifted into regs on rising edge of CLK, 
#output displayed on rising edge of LOAD

#NOTES:
#This version supports cascading several 7219's.  I have
#noticed that even with programs that assume only one
#7219, that if there is another cascaded, the exact same
#output is mirrored on subsequent displays. 

#I assume that turn_on, set_intenisty, set_scanlimit, etc
#all get shifted into the next chip anyway, however, 
#these subroutines take the number of cascaded 7219s as
#an argument and shift in and latch the necessary
#controls to use the display.  


#global vars for gpio init function
#$clk 	SPI clock
#$ds	SPI data
#$load	SPI chip select
my ($clk, $ds, $load);

lib/PINE64/MAX7219.pm  view on Meta::CPAN

sub shift_in{
	#data is shifted in with 16 bit packets: 8-bit segment,
	#4-bit digit address, 4-bit dont care bits

	#used by internal methods only

	#array ref seg data
	my $leds = $_[0];
	#array ref seg addr
	my $addr = $_[1];
	#number cascaded 7219s
	my $ncas = $_[2];
	#delay in milliseconds
	my $delay = $_[3];
	#latch flag
	my $lf = $_[4];

	#high flag for data gpio line
	my $hf = 0;

	#my $ncp = $ncas * 32;	#min number 32 for 16 clock pulses

lib/PINE64/MAX7219.pm  view on Meta::CPAN


	foreach my $digit (@rev_segs){
		shift_in($alphanums{$s2[$ln]}, $digit, 1, 250, 0 );
		shift_in($alphanums{$s1[$ln]}, $digit, 1, 250, 0 );
		load();
		$ln++;
	}#end for
}#end print_interleaved

sub turn_on{
	#ncas is number of cascaded MAX7219 displays
	my $ncas = $_[1];
	if(defined($ncas)){
		#print "tu ncas defined\n";
		for(my $ni=0;$ni<$ncas;$ni++){
			shift_in(\@turn_on, \@sdreg, $ncas, 250, 0);
			if($ni ==($ncas-1)){
				#print "tu load\n";
				load();
			}#end if
		}#end for
	}#end if multiple 7219's
	else{#just one
		#set shutdown register to normal operation
		shift_in(\@turn_on, \@sdreg, 1, 250, 1);
	}#end else
}#end turn_on

sub turn_off{
	#ncas is number of cascaded MAX7219 displays
	my $ncas = $_[1];
	if(defined($ncas)){
		for(my $ni=0;$ni<$ncas;$ni++){
			shift_in(\@turn_off, \@sdreg, $ncas, 250, 0);
			if($ni ==($ncas-1)){
				load();
			}#end if
		}#end for
	}#end if multiple 7219's
	else{#just one
		#set shutdown register to off
		shift_in(\@turn_off, \@sdreg, 1, 250, 1);
	}#end else
}#end turn_off

sub set_scanlimit{
	#ncas is number of cascaded MAX7219 displays
	my $ncas = $_[1];
	if(defined($ncas)){
		#print "sl ncas defined\n";
		for(my $ni=0;$ni<$ncas;$ni++){
			shift_in(\@slregall, \@slimreg, $ncas, 250, 0);
			if($ni ==($ncas-1)){
				load();
				#print "sl load\n";
			}#end if
		}#end for

lib/PINE64/MAX7219.pm  view on Meta::CPAN

	#endless KnightRider effect!
	for(;;){
		$max->bullets_lrmid(1);
		$max->bullets_rlmid(1);
	}#end for

=head1 DESCRIPTION

This module is a driver for 8-digit seven-segment MAX7219 displays. It
is implemented as bit-banged SPI.  Using the object's methods, you can
set the intensity of the display, print words, and cascade multiple 
displays. It also comes with several built-in effects.  

Only three GPIO pins are required: SPI clk, SPI data, and SPI chip 
select.  This modules uses the PINE64::GPIO numbering scheme. 

=head1 METHODS

=head2 new($clock,$data,$chip_select)

Takes the GPIO pin numbers that will be used to inplement the bit-bang
SPI interface to the MAX7219 as arguments.  Returns an object to
control an 8-digit display.  

=head2 shift_in($leds, $digit, $n_cascaded, $delay, $latch_flag)

This method is only used internally.  It takes an array of a single
seven-segment's LEDs, the digit position, the number of cascaded
MAX7219 displays, a delay in usec (between SPI clock pulses), and a
latch flag.  Each individual letter of a word is shifted in one at
a time.  Once all the letters are shifted in, the latch_flag is set
high, and displays the word.  

=head2 load()

This method is only used internally. It manipulates the chip select
line, aka latch pin.  When called, it will render what has been
shifted into the display. 

=head2 print_sentence($sentence, $delay, $clear_flag)

Perhaps the most useful method.  Takes a string, however long, and
displays each word for $delay micro seconds.  $sentence could be the 
text of an entire book.  $clear_flag is not required.  

=head2 print_interleaved($string1, $string2)

This method is for use with two 8-digit displays cascaded.  $string1
will be displayed in the first display, $string2 in the cascaded
display. 

=head2 turn_on($num_cascaded)

Turns on the MAX7219 chip by writing to the turn on register.  Takes
the number of cascaded displays as an argument. Enter 1 if only 
using one display. 

=head2 set_scanlimit($num_cascaded)

Writes to the scan-limit register.  Sets it up to use all 8-digits
of the display.  Takes number of cascaded displays an arg. 

=head2 set_intensity($intensity); 

Adjusts the brightness of the display.  Takes a string as an arg.
Valid vlaues are: min, dim, mid, bright, max.  

=head2 all_off($num_cascaded)  

Turns off all digits.  Takes number of cascaded displays as an arg. 

=head2 disp_teston()

Turns on all segments on all digits.  

=head2 disp_testoff()

Turns off all segments on all digits. 

=head2 clockwise_circles($number_iterations)



( run in 0.501 second using v1.01-cache-2.11-cpan-49f99fa48dc )