Digital IR Sonar Code

In creating a simple digital IR detector using an IR LED and Panasonic OR Remote detector, need to drive LED with 38,500 KHz for 0.25 to 1 millisecond, while checking the detector for signal status… I coded the following that uses the GHI Piezo Drive for the IR LEd and Button Driver for the IR Detector. 1) With this code, would the Piezo frequency stay on so the detector would see it, and 2) how could the IR LED "On Time be set less, down to 0.25 ms.

/* Digital IR Sonar

  • uses GHI “Piezo Driver” set for 38,500 hz, for 1 second t(or less) to drive an IR LED on pin
  • Di5
  • uses GHI “Button Driver” to detect state of an IR receiver on pin Di4, every 1/10 sec.
    */

ing System;
using Microsoft.SPOT;
using System.Threading;
using GHIElectronics.NETMF.FEZ;

public class Program
{
public static void Main()
{
// Create Button object assigned to a Button Component connected to Di4
FEZ_Components.Button myButton = new FEZ_Components.Button(FEZ_Pin.Digital.Di4);

	// Create Piezo (speaker) object assigned to the a Piezo Component connected to Di5 with PWM feature
	FEZ_Components.Piezo myPiezo = new FEZ_Components.Piezo(FEZ_Pin.PWM.Di5);
	
	while (true)
	{
		// Play a 38500 kHz. tone for 1 mSecond
		myPiezo.Play(38500, 1);
		
		if (myButton.GetState() == FEZ_Components.Button.ButtonState.Pressed)
		{
			Debug.Print("Detected");
		}
		else
		{
			Debug.Print("Not Detected");
		}
			Thread.Sleep(1);
	}
	
	Thread.Sleep(100);		
}  // public static void Main

} // public class Program

Please use “code” tags so the code is readable

Sorry on the Format. Is this how to do it?

no :frowning:
You need code not quote :slight_smile: Look it your code…isn’t it much easier to read now?

Sorry on the Format. Is this how to do it?

/* Digital IR Sonar
*  uses GHI "Piezo Driver" set for 38,500 hz, for 1 second to drive an IR LED on pin Di5
*  uses GHI "Button Driver" to detect state of an IR receiver on pin Di4
*/

ing System;
using Microsoft.SPOT;
using System.Threading;
using GHIElectronics.NETMF.FEZ;

public class Program
{
	public static void Main()
	{
		// Create Button object assigned to a Button Component connected to Di4
		FEZ_Components.Button myButton = new FEZ_Components.Button(FEZ_Pin.Digital.Di4);
		
		// Create Piezo (speaker) object assigned to the a Piezo Component connected to Di5 with PWM feature
		FEZ_Components.Piezo myPiezo = new FEZ_Components.Piezo(FEZ_Pin.PWM.Di5);
		
		while (true)
		{
			// Play a 38500 kHz. tone for 1 mSecond
			myPiezo.Play(38500, 1);
			
			if (myButton.GetState() == FEZ_Components.Button.ButtonState.Pressed)
			{
				Debug.Print("Detected");
			}
			else
			{
				Debug.Print("Not Detected");
			}
				Thread.Sleep(1);
		}
		
		Thread.Sleep(100);		
	}  // public static void Main
}  // public class Program