internal async Task CalcDelay(IBackgroundTaskInstance taskInstance) { // Swarm s = new Swarm(taskInstance, settings.interval); await InitChips(); p.writeGPIOAB(0xffff); p1.writeGPIOAB(0xffff); p2.writeGPIOAB(0xffff); int delay = 0; TimeSpan timeSpan; int totalMilliseconds = 0; int TestTime = 500; DateTime startTime = DateTime.Now; DateTime endTime = DateTime.Now; int stepCount; int spincount = settings.spinCount; bool calculating = true; while (calculating) { stepCount = TestTime / settings.interval; ushort allOn = 0xffff; ushort allOff = 0x0000; ushort value = allOn; startTime = DateTime.Now; for (int i = 0; i < stepCount; i++) { p.writeGPIOAB(value); Spin(spincount); p1.writeGPIOAB(value); Spin(spincount); p2.writeGPIOAB(value); Spin(spincount); value = (value == allOn) ? allOff : allOn; } endTime = DateTime.Now; timeSpan = endTime - startTime; totalMilliseconds = timeSpan.Seconds * 1000 + timeSpan.Milliseconds; if (Math.Abs(TestTime - totalMilliseconds) < 30) { calculating = false; } else { if (totalMilliseconds > TestTime) { spincount -= 1; } else { spincount += 1; } } p.writeGPIOAB(0); p1.writeGPIOAB(0); p2.writeGPIOAB(0); } p = null; p1 = null; p2 = null; GC.Collect(); System.Threading.Tasks.Task.Delay(500).Wait(); settings.spinCount = spincount; }
private void MoveLed() { expander.writeGPIOAB(0); expander.digitalWrite(_currentPin + 8, Mcp23017.Level.HIGH); _currentPin = (_currentPin + 1) % 3; }