Just messing around with my new FEZ Domino board and I thought I’d post up a quick tutorial on how to use a motion sensor with your board. First thing you will want to understand is interrupt ports. An interrupt port is a port that is listening and waiting for something to happen. For instance voltage levels going up or going down. In this tutorial I use a motion sensor that I got from parallax here. This is a very basic sensor that has voltage tolerance of 3-5v and has one pin that outputs high or low voltage levels. High means its sensed motion. The next part of this project involves a small speaker that outputs a tone to let you know its sensed motion. Nothing loud or anything but just for demonstration purpose. You can get the driver for the tone generation here: http://www.tinyclr.com/downloads/Component/FEZ_Components_Piezo.cs. So here’s the code:
#region motion sensor Thread.Sleep(30000); tone = new FEZ_Components.Piezo(FEZ_Pin.PWM.Di5); InterruptPort motion = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh); motion.OnInterrupt += new NativeEventHandler(motion_OnInterrupt); Thread.Sleep(-1); #endregion static void motion_OnInterrupt(uint data1, uint data2, DateTime time) { tone.Play(400, 1000); }