Exemple #1
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);
            }