L(dr) and P(ir) readings
[Arduino] / Desk_LED_dimmer / gamma.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 # Generate an LED gamma-correction table for Arduino sketches.
6 # https://learn.adafruit.com/led-tricks-gamma-correction/the-longer-fix
7
8 my ( $gamma, $max_in, $max_out ) = @ARGV;
9  
10 $gamma   ||= 2.8;       # Correction factor
11 $max_in  ||= 255,       # Top end of INPUT range
12 $max_out ||= 255;       # Top end of OUTPUT range
13
14 print "// gamma.pl $gamma $max_in $max_out\n"; 
15 print "const uint8_t PROGMEM gamma[] = {";
16 foreach my $i ( 0 .. $max_in ) {
17         print "," if $i > 0;
18         print "\n  " if $i % 15 == 0;
19         printf("%3d", int(
20                 ( ($i / $max_in) ** $gamma ) * $max_out + 0.5)
21         );
22 }
23 print " };\n";
24