spitest.pl - Raspberry Pi / Microchip MCP-4922 DAC

Skapad 2 år sedan, skriven i Perl, med 368 visningar.
URL http://kod.perl.se/view/3bcb7080 Bädda in
Ladda hem koden eller visa koden i råformatVisa bredare version
  1. #!/usr/bin/perl
  2.  
  3. use Device::BCM2835;
  4. use Time::HiRes qw(usleep);
  5. use strict;
  6.  
  7.  
  8. #Device::BCM2835::set_debug(1);
  9. Device::BCM2835::init() || die "Could not init library";
  10.  
  11. Device::BCM2835::spi_begin();
  12. Device::BCM2835::spi_setBitOrder(Device::BCM2835::BCM2835_SPI_BIT_ORDER_MSBFIRST);
  13. Device::BCM2835::spi_setDataMode(Device::BCM2835::BCM2835_SPI_MODE0);
  14. Device::BCM2835::spi_setClockDivider(Device::BCM2835::BCM2835_SPI_CLOCK_DIVIDER_65536);
  15. Device::BCM2835::spi_chipSelect(Device::BCM2835::BCM2835_SPI_CS0);
  16. Device::BCM2835::spi_setChipSelectPolarity(Device::BCM2835::BCM2835_SPI_CS0, 0);
  17.  
  18. my $v = 0;
  19. my $speed = 3.14*2 / 400;
  20. for(;;)
  21. {
  22.     my $h  = 2048 + 2047 * sin($v);
  23.     my $h2 = 2048 + 2047 * abs(sin($v + 0.3));
  24.     $v += $speed;
  25.  
  26.     Device::BCM2835::spi_transfern(pack('S>', $h + 0x3000));
  27.     Device::BCM2835::spi_transfern(pack('S>', $h2 + 0xB000));
  28.     usleep(500);
  29. }

Svara på "spitest.pl - Raspberry Pi / Microchip MCP-4922 DAC"

Här kan du skriva ett svar till kodsnutten ovan