Exemplo n.º 1
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;
     }
 }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
            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);
            }
Exemplo n.º 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);
     }
 }