Step 3: Set up the perl script
Here is where you will create the main perl script. Let's begin:
This would be the location of your perl interpreter. More code:
All of these are libraries you need. The first allows you to clock the processor. The next allows you to write to the Serial port, and the last allows you to round numbers.
my $arduino = Device::SerialPort->new("/dev/ttyACM0"); #Should be the port your Arduino is on
$arduino->baudrate(9600); #Should be your Arduino's baud rate
All of these things initialize the connection with the Arduino. You should change what needs to be changed to make it fit your needs.
my $processor = new Unix::Processors; #Your processor
$overallspeed = $processor->max_clock; #Clocks it
$send = ((($overallspeed - 800) / 175.125) + 1); # 800 = minimum clock speed. 175.125 = max clock speed / number of leds
This chunk of code clocks the processor and puts it on a scale between 1 and 7. Some things need to be changed, such as your processors minimum clock speed, and your max divided by the number of leds. For this project, there is 8 leds.
$arduino->write(round($send)); #Rounds the number, and sends it to your Arduino
This code is in charge of sending it to the Arduino.
Save all that code as clockandsend.pl
Now, this will only clock and send one number. You want to create another script to run this one over, and over again. For example:
Just change "/path/" to whatever the path actually is.
I would save that as loop.pl.
That's it for the perl!