| 1 | #!/usr/local/bin/perl -w | ||
| 2 | |||
| 3 | use RPi::MultiPCA9685 qw(init_PWM setChannelPWM); | ||
| 4 | |||
| 5 | #-------------------------------------------------------------- | ||
| 6 | # prepare the array reference containing the PWM values. | ||
| 7 | # 1st value = PWM start | ||
| 8 | # 2nd value = pwm stop - in a range of 4096 steps | ||
| 9 | # 3rd Value = the same like 1st, but for the next servo or LED. | ||
| 10 | # 4th value = like 2nd, but for the next servo or LED. | ||
| 11 | # and so on ... | ||
| 12 | |||
| 13 | my $mref=[0,100,0,200,0,300,0,400,0,500,0,600,0,700,0,800,0,900,0,1000, | ||
| 14 | 0,1100,0,1200,0,1300,0,1400,0,1500,0,1600,0,1700,0,1800,0,1900, | ||
| 15 | 0,2000,0,2100,0,2200,0,2300,0,2400,0,2500,0,2600,0,2700,0,2800, | ||
| 16 | 0,2900,0,3000,0,3100,0,3200,0,3300,0,3400,0,3500,0,3600,0,3700, | ||
| 17 | 0,3800,0,3900,0,4000]; | ||
| 18 | #-------------------------------------------------------------- | ||
| 19 | |||
| 20 | my $num_servos=40; # make sure the number of value pairs in the array does not exceed this value | ||
| 21 | my $i2c_freq=50; # The frequency of the PWM signal in Hz | ||
| 22 | my $i2cport="/dev/i2c-0"; # The I2C port device | ||
| 23 | my $i2c_address=0x40; # The I2C address of the first PCA9685 Chip. If you exceed the number of addressable Channels per chip, | ||
| 24 | # the next chip will be used (i2c_address + 1) | ||
| 25 | my $currentservo=0; # The first servo or LED where you want to change the PWM. Can be any number from 0 to $num_servos. | ||
| 26 | # If you don't want to start with 0, make sure the number of array element does not exceed the last servo or LED | ||
| 27 | |||
| 28 | #-------------------------------------------------------------- | ||
| 29 | |||
| 30 | # init the PCA9685 devices # needs to be run only once at startup | ||
| 31 | init_PWM($i2cport,$i2c_address,$i2c_freq,$num_servos); | ||
| 32 | |||
| 33 | # send the PWM values to the various PCA96585 Chips | ||
| 34 | setChannelPWM($currentservo,$mref); # the nuber of array elements define the number of Servos to be set. |