static void TestIOTimer() { var f = 100; var timer = new IOTimer(5, 0); timer.Frequency = f; //timer.Period = 10; timer.DutyCycle = 0.5; // 设为0,避免Start后就发出脉冲 timer.Count = 0; // 让低电平有效,否则脉冲停止后小车电机一直转动 timer.Invert = true; var timer2 = new IOTimer(5, 1); timer2.Frequency = f; //timer2.Period = 20; timer2.DutyCycle = 0.5; // 设为0,避免Start后就发出脉冲 timer2.Count = 0; // 让低电平有效,否则脉冲停止后小车电机一直转动 timer2.Invert = true; Debug.Print("Timer1:" + Pins.GetName(timer.Pin)); Debug.Print("Timer2:" + Pins.GetName(timer2.Pin)); timer.Start(); timer2.Start(); var dir = new OutputPort(Pins.PA2, false); for (int i = 0; i < 10; i++) { Thread.Sleep(1000); Debug.Print("Timer1:" + timer.Count); // 反向 dir.Write(!dir.Read()); timer.Count = f - f * i / 10; } Thread.Sleep(1000); Debug.Print("Timer1:" + timer.Count); Debug.Print("Timer2:" + timer2.Count); }
static void OnPress(uint data1, uint data2, DateTime time) { Print("Button: " + Pins.GetName((Cpu.Pin)data1) + "," + (data2 == 0 ? "Down" : "Up")); }