using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino; namespace KidBit { public class Program { //IO pins static InputPort fakeConnection = new InputPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.PullUp); static OutputPort led = new OutputPort(Pins.GPIO_PIN_D6, false); static OutputPort led1 = new OutputPort(Pins.ONBOARD_LED, false); static OutputPort led2 = new OutputPort(Pins.GPIO_PIN_D1, false); static PWM piezo1 = new PWM(Pins.GPIO_PIN_D5); //variables static int i = 0; //counter static int critical = 4; //number of fails to trigger alarm static uint tone = 1000000 / 212 ; //212 Hz is middle c static bool fC = false; public static void Main() { //Stop the piezo so it's not buzzing when the program starts piezo1.SetPulse(0, 0); led.Write(false); led1.Write(false); led2.Write(false); while (true) { led1.Write(!led1.Read()); fC = fakeConnection.Read(); led2.Write(fC); //If connection is good if (fC == true) //true = within range, false = out of range { i = 0; //remotely written overriding count below } ++i; //Increase counter by 1 if (i > critical) //if connection is broke, counter will go above 1, when counter hits value in critical, set alarm { piezo1.SetPulse(tone, tone/2); //set alarm piezo while (i > critical) //set alarm led { led.Write(!led.Read()); //Toggle the LED by setting it to the opposite of its current state if (tone < 0) //If loop to pulse tone { tone = 0; } else { tone = 1000000 / 212; } //Check to see if we're still in an alarm state if (fC == true) { i = 0; } else { Thread.Sleep(200); } } //The alarm has stopped piezo1.SetPulse(0, 0); led.Write(false); } Thread.Sleep(200); //loop sleep for 200 ms } } } }