Example #1
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 #2
0
        public float ObterDistancia()
        {
            RmtCommand[] response = null;

            _rxChannel.Start(true);

            // Send 10us pulse
            _txChannel.Send(false);

            // Try 5 times to get valid response
            for (int count = 0; count < 5; count++)
            {
                response = _rxChannel.GetAllItems();
                if (response != null)
                {
                    break;
                }

                // Retry every 60 ms
                Thread.Sleep(60);
            }

            _rxChannel.Stop();

            if (response == null)
            {
                return(-1);
            }

            // Echo pulse width in micro seconds
            int duracao = response[0].Duration0;

            var distancia = duracao / 58;

            return(distancia);

            // Calculate distance in meters
            // Distance calculated as  (speed of sound) * duration(meters) / 2
            //return _speedOfSound * duration / (1000000 * 2);
        }