Example #1
0
 protected void ConfigureTransmitter(TransmitterChannel commandList)
 {
     commandList.CarrierEnabled = false;
     commandList.ClockDivider   = ClockDivider;
     commandList.SourceClock    = SourceClock.APB;
     commandList.IdleLevel      = false;
     commandList.IsChannelIdle  = true;
 }
Example #2
0
 private void SerializeColor(byte b, TransmitterChannel commandList)
 {
     for (var i = 0; i < 8; ++i)
     {
         commandList.AddCommand(((b & (1u << 7)) != 0) ? OnePulse : ZeroPulse);
         b <<= 1;
     }
 }
Example #3
0
        public NeopixelChain(byte gpioPin, ushort size)
        {
            _gpioPin            = gpioPin;
            _transmitterChannel = new TransmitterChannel(_gpioPin);
            ConfigureTransmitter(_transmitterChannel);

            _nrOfLeds = size;
            var nrOfAllBits = 24 * _nrOfLeds;

            _ledData   = new byte[(nrOfAllBits + 1) * 4];
            _onePulse  = new byte[] { (byte)(0.7 / MinPulse), 128, (byte)(0.6 / MinPulse), 0 };
            _zeroPulse = new byte[] { (byte)(0.35 / MinPulse), 128, (byte)(0.8 / MinPulse), 0 };
            _resPulse  = getResPulse(MinPulse);
        }
Example #4
0
 public void Update()
 {
     using (var commandList = new TransmitterChannel(_gpioPin))
     {
         ConfigureTransmitter(commandList);
         for (uint pixel = 0; pixel < Pixels.Length; ++pixel)
         {
             SerializeColor(Pixels[pixel].G, commandList);
             SerializeColor(Pixels[pixel].R, commandList);
             SerializeColor(Pixels[pixel].B, commandList);
         }
         commandList.AddCommand(ResCommand);                 // RET
         commandList.Send(true);
     }
 }
Example #5
0
        public HCSR04(int TxPin, int RxPin)
        {
            _txChannel = new TransmitterChannel(TxPin);

            _txPulse = new RmtCommand(10, true, 10, false);
            _txChannel.AddCommand(_txPulse);
            _txChannel.AddCommand(new RmtCommand(20, true, 15, false));

            _txChannel.ClockDivider   = 80;
            _txChannel.CarrierEnabled = false;
            _txChannel.IdleLevel      = false;

            // The received echo pulse width represents the distance to obstacle
            // 150us to 38ms
            _rxChannel = new ReceiverChannel(RxPin);

            _rxChannel.ClockDivider = 80;       // 1us clock ( 80Mhz / 80 ) = 1Mhz
            _rxChannel.EnableFilter(true, 100); // filter out 100Us / noise
            _rxChannel.SetIdleThresold(40000);  // 40ms based on 1us clock
            _rxChannel.ReceiveTimeout = new TimeSpan(0, 0, 0, 0, 60);
        }
            public void Config(int TxPin, int RxPin)
            {
                // Set-up TX & RX channels
                // We need to send a 10us pulse to initiate measurement
                _txChannel = new TransmitterChannel(TxPin);
                _txPulse   = new RmtCommand(10, true, 10, false);
                _txChannel.AddCommand(_txPulse);
                _txChannel.AddCommand(new RmtCommand(20, true, 15, false));

                _txChannel.ClockDivider   = 80;
                _txChannel.CarrierEnabled = false;
                _txChannel.IdleLevel      = false;

                // The received echo pulse width represents the distance to obstacle
                // 150us to 38ms for HC-SR04
                _rxChannel = new ReceiverChannel(RxPin);

                _rxChannel.ClockDivider = 80;       // 1us clock ( 80Mhz / 80 ) = 1Mhz
                _rxChannel.EnableFilter(true, 100); // filter out 100Us / noise
                _rxChannel.SetIdleThresold(40000);  // 40ms based on 1us clock
                _rxChannel.ReceiveTimeout = new TimeSpan(0, 0, 0, 0, 60);
            }