void pattern0(int msec) { if (pin0.Read()) { pin0.Write(false); pin1.Write(true); } else if (pin1.Read()) { pin1.Write(false); pin2.Write(true); } else if (pin2.Read()) { pin2.Write(false); pin3.Write(true); } else if (pin3.Read()) { pin3.Write(false); pin4.Write(true); } else if (pin4.Read()) { pin4.Write(false); pin0.Write(true); } Thread.Sleep(msec); }
// Fonction de déplacement de l'ascenseur // Cette fonction va gérer l'ascenseur jusqu'à ce qu'il arrive à l'étage demander public static void aLetage() { int oldMoyenne = 0; int moyenne = calculeHauteur(); // Démarage de l'ascenseur UpOrDown(moyenne); StopStart(false); oldMoyenne = calculeHauteur(); while (!arrive) { moyenne = calculeHauteur(); if (moyenne <= oldMoyenne && sensRotation.Read()) { Debug.Print("Descend : moyenne " + moyenne); oldMoyenne = moyenne; } if (moyenne >= oldMoyenne && !sensRotation.Read()) { Debug.Print("Monte : moyenne " + moyenne); oldMoyenne = moyenne; } arrive = arriverALetage(oldMoyenne); } StopStart(true); goEtage.Suspend(); }
static void Button_StateChanged(object sender, AutoRepeatEventArgs e) { // We will only change when the button gets pressed if (Button.Read()) { return; } // Toggles Red Red.Write(!Red.Read()); // Makes green invert Red Green.Write(!Red.Read()); }
static void TestPWM() { var pin = HardwareProvider.HwProvider.GetPwmPinForChannel(Cpu.PWMChannel.PWM_0); Debug.Print("PwmPinForChannel:" + pin); var count = HardwareProvider.HwProvider.GetPWMChannelsCount(); Debug.Print("PWMChannelsCount:" + count); //如果通道共用同一时钟,则周期以第一个的设置为准 var pwm0 = new PWM(Cpu.PWMChannel.PWM_0, 500, 250, PWM.ScaleFactor.Microseconds, false); // 可以得到稳定的1M输出,注意调整逻辑分析仪的采样频率 //var pwm1 = new PWM(Cpu.PWMChannel.PWM_4, 1000000, 0.5, false); var pwm1 = new PWM(Cpu.PWMChannel.PWM_4, 2, 1, PWM.ScaleFactor.Microseconds, false); Debug.Print("Period:" + pwm0.Period); Debug.Print("Duration:" + pwm0.Duration); var led = new OutputPort(ledPins[0], true); for (uint i = 1; i < 100; i++) { led.Write(!led.Read()); Debug.Print("pwm0 Start"); //pwm0.Duration = 5; pwm0.Start(); Thread.Sleep(500); Debug.Print("pwm0 Stop"); pwm0.Stop(); Debug.Print("pwm1 Start"); //pwm1.Duration = i; pwm1.Start(); Thread.Sleep(500); Debug.Print("pwm1 Stop"); pwm1.Stop(); Thread.Sleep(300); } //pwm1.Start(); while (true) { var b = led.Read(); led.Write(!b); Thread.Sleep(100); } //pwm0.Stop(); //pwm1.Stop(); }
void timer_Tick(GT.Timer timer) { //Debug.Print("PH :" + phSensor.PhValue); //Debug.Print("Tds 1 :" + Tds1.tdsValue); //Debug.Print("Temp 1 :" + Temp1.ConvertAndReadTemperature()); //Debug.Print("Temp 2 :" + Temp2.ConvertAndReadTemperature()); //Debug.Print("Temp 3 :" + Temp3.ConvertAndReadTemperature()); var data = new SensorData() { Ph = phSensor.PhValue, Relay1 = relay1.Read(), Relay2 = relay2.Read(), Tds1 = Tds1.tdsValue, Tds2 = Tds2.tdsValue, Temp1 = Temp1.TempValue, //.ConvertAndReadTemperature(), Temp2 = Temp2.TempValue, //.ConvertAndReadTemperature(), //Temp3 = Temp3.ConvertAndReadTemperature(), WaterDist = WaterDist }; var jsonStr = Json.NETMF.JsonSerializer.SerializeObject(data); Debug.Print("kirim :" + jsonStr); xBeeAdapter.Port.WriteLine(jsonStr); /* * //USING LORA * //PrintToLcd("send count: " + counter); * sendData(jsonStr); * Thread.Sleep(5000); * byte[] rx_data = new byte[20]; * * if (UART.CanRead) * { * var count = UART.Read(rx_data, 0, rx_data.Length); * if (count > 0) * { * Debug.Print("count:" + count); * var hasil = new string(System.Text.Encoding.UTF8.GetChars(rx_data)); * Debug.Print("read:" + hasil); * * //mac_rx 2 AABBCC * } * } * var TimeStr = DateTime.Now.ToString("dd/MM/yy HH:mm"); * //insert to db */ }
public string GetStatus() { string s = "STAT" + " X:" + AbsoluteXSteps + " Y:" + AbsoluteYSteps + " Z:" + AbsoluteZSteps + " DirX:" + (XDirectionPort.Read() ? '1' : '0') + " DirY:" + (YDirectionPort.Read() ? '1' : '0') + " MS1:" + (MicroStep1Port.Read() ? '1' : '0') + " MS2:" + (MicroStep2Port.Read() ? '1' : '0') + " FeedRate: " + XYStepInterval + "ms/step" + "\r\n"; return(s); }
static void OnTime(Object state) { var flag = port.Read(); port.Write(!flag); port2.Write(flag); }
public int GetAbsoluteSteps(int steps, OutputPort directionPort) { bool ms1 = MicroStep1Port.Read(); bool ms2 = MicroStep2Port.Read(); bool dir = directionPort.Read(); int multiplier = 1; if (ms1 && ms2) { multiplier = 1; } if (!ms1 && ms2) { multiplier = 2; } if (ms1 && !ms2) { multiplier = 4; } if (!ms1 & !ms2) { multiplier = 8; } if (dir == NegativeAxisDirection) { multiplier = -multiplier; } return(steps * multiplier); }
public static void Main() { int cnt = 0; int PauzaNeMiliSekonda = 50; /* Pin.Led = PA5 = D13 on Nucleo */ OutputPort LED = new OutputPort(Pin.Led, true); while (true) { LED.Write(!LED.Read()); // Rezultati inverz Thread.Sleep(PauzaNeMiliSekonda); // Prit pake ... Debug.Print("cnt = " + cnt.ToString()); cnt++; if ((cnt % 2) == 0) { Debug.Print("Div with 0"); } else { Debug.Print("No dived with 0"); } } }
private static void ControlLED() { while (true) { switch (state) { case LEDState.Initializing: ledPort.Write(true); Thread.Sleep(1000); ledPort.Write(false); Thread.Sleep(1000); break; case LEDState.Ready: if (!ledPort.Read()) { ledPort.Write(true); } Thread.Sleep(50); break; case LEDState.Playing: ledPort.Write(true); Thread.Sleep(500); ledPort.Write(false); Thread.Sleep(500); break; default: break; } } }
static void blueTask(object state) { if (!hold || reset) { Blue.Write(!Blue.Read()); return; } // Blue.Write(!Blue.Read()); firstOrSecond += 1; switch (firstOrSecond) { case 1: Red.Write(true); serialPort1.Write(buffer, 0, buffer.Length); Red.Write(false); break; case 2: Orange.Write(true); serialPort2.Write(buffer, 0, buffer.Length); Orange.Write(false); break; case 3: Blue.Write(true); serialPort3.Write(buffer, 0, buffer.Length); Blue.Write(false); firstOrSecond = 0; break; default: firstOrSecond = 0; break; } }
static void hal_OnInterrupt(uint data1, uint data2, DateTime time) { GlobalVariables.halTime = time.Ticks / 10000000.0d; GlobalVariables.hertz = (Int16)(1000.0d / (GlobalVariables.halTime - GlobalVariables.halTimeOld)); GlobalVariables.halTimeOld = GlobalVariables.halTime; green.Write(!green.Read()); }
private static void PowerUp() { if (_resetPin.Read() == false) { _resetPin.Write(true); } ReadRegisters(); _shadowRegisters[REGISTER_TEST] = 0x8100; //Enable the oscillator and yes, that what SI calls this register. UpdateRegisters(); Thread.Sleep(500); // Wait for clock to settle - from AN230 Datasheet ReadRegisters(); _shadowRegisters[REGISTER_POWERCFG] = 0x4001; _shadowRegisters[REGISTER_SYSCONFIG1] |= (1 << BIT_RDS); _shadowRegisters[REGISTER_SYSCONFIG2] &= 0xFFCF; _shadowRegisters[REGISTER_SYSCONFIG2] &= 0xFFCF; _shadowRegisters[REGISTER_SYSCONFIG2] &= 0xFF3F; _shadowRegisters[REGISTER_SYSCONFIG2] &= 0xFFF0; _shadowRegisters[REGISTER_SYSCONFIG2] |= 0x001F; UpdateRegisters(); Thread.Sleep(110); }
public static void Main() { //Start the server time setting thread. new Thread(() => NTP.UpdateTime()).Start(); while (!NTP.timeSet) { Thread.Sleep(100); } Thread.Sleep(100); PowerManagment.SetPeripheralState(Peripheral.PowerLED, false); //Start the server itself. ServerConfiguration = new Configuration(8081); ServerCredential = new Credential(new string[] { "Test" }, "/auth.htm", new string[] { "/auth.htm", "/img/Log-In.png", "/css/main.css", "/lib/GetInTemp.js", "/lib/Login.js" }); Server = new HttpServer(ServerConfiguration, ServerCredential, 1024, 1024, @"\SD\htdocs"); Server.OnServerError += new OnServerErrorDelegate(Server_OnServerError); AC = new ACStatus(Pins.GPIO_PIN_D9, Pins.GPIO_PIN_D10); commander = new IRCommands(IR, commands); timers = new Timers(AC, tempSensor, commander); handler = new requestHandler(@"\SD\htdocs", commander, tempSensor, AC, timers, ServerCredential); Server.OnRequestReceived += new OnRequestRecievedDelegate(handler.processRequest); Server.Start(); //Start the temp management thread. new Thread(timers.tempControl).Start(); //Blink LED three times to show we're up and running. for (int i = 0; i < 6; i++) { led.Write(!led.Read()); Thread.Sleep(350); } led.Write(false); }
private static void DoProtocol(USBH_RawDevice.Pipe inPipe, USBH_RawDevice.Pipe outPipe) { var inBuffer = new byte[inPipe.PipeEndpoint.wMaxPacketSize]; var outBuffer = new byte[outPipe.PipeEndpoint.wMaxPacketSize]; int bytesTransferred; OutputPort LED = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, false); InputPort button = new InputPort((Cpu.Pin)FEZ_Pin.Digital.LDR, false, Port.ResistorMode.PullUp); while (true) { bytesTransferred = inPipe.TransferData(inBuffer, 0, 1); if (bytesTransferred > 0) { Debug.Print("Received " + inBuffer[0]); switch ((FezUsbCommands)inBuffer[0]) { case FezUsbCommands.LedOff: LED.Write(false); break; case FezUsbCommands.LedOn: LED.Write(true); break; default: break; } outBuffer[0] = (byte)((LED.Read() ? FezUsbResponse.LedOn : 0) | ((!button.Read()) ? FezUsbResponse.ButtonDown : 0)); outPipe.TransferData(outBuffer, 0, 1); } } }
public static void AButtonIsPressed() { interuptCounter++; Debug.Print(interuptCounter.ToString()); ledSpider.Write(!ledSpider.Read()); }
/** Control a LED */ private byte[] PrepareResponseV3LED(HttpListenerContext context) { bool isLedButtonPressed = false; if (context.Request.HttpMethod == "POST") { // from submitted form we get "buttonTwo=Button+Two+%3A%28" if second button is pressed String contentstring = this.GetContentString(context.Request); isLedButtonPressed = contentstring.IndexOf("led_button") != -1; } // TODO extract to resources String responseString = @"<html> <title>-= LED Controller 3000 =-</title> <body> <form action= """" method=""post""> <hl>This comes from FEZ Panda II</hl> <div>This is some text</div>"; if (isLedButtonPressed) { ToggleLed(); } responseString += @"<div style=""color:"; if (led.Read()) { // LED is on responseString += @"green"">LED is ON"; } else { // LED is off responseString += @"red"">LED is OFF"; } responseString += "</div>"; responseString += @" <div><input type=""submit"" name=""led_button"" value=""Toggle LED""/></div> </form> </body> </html>"; return(Encoding.UTF8.GetBytes(responseString)); }
public static void Main() { while (true) { Thread.Sleep(5000); relay.Write(true); greenLed.Write(!greenLed.Read()); redLed.Write(!redLed.Read()); // Debug.Print("ON"); Thread.Sleep(10000); relay.Write(false); greenLed.Write(!greenLed.Read()); redLed.Write(!redLed.Read()); // Debug.Print("OFF"); Thread.Sleep(5000); } }
private void OnReceive(byte[] data) { led.Write(!led.Read()); string message = new String(Encoding.UTF8.GetChars(data)); Debug.Print("Receive " + message);; }
static void redTask(object state) { if (hold) { return; } Red.Write(!Red.Read()); }
static void orangeTask(object state) { if (hold) { return; } Orange.Write(!Orange.Read()); }
private static void DoWatchDogLight() { while (true) { watchDogLight.Write(!watchDogLight.Read()); Thread.Sleep(800); } }
/// <summary> /// Funcion para indicar a través de un led que etamos en modo combate. /// </summary> private static void blink() { while (Datos.competi) { led.Write(!led.Read()); Thread.Sleep(500); } led.Write(false); }
private static void SwitchPortOnOnInterrupt(uint data1, uint data2, DateTime time) { var message = "NetDuino's led is " + _ledPort.Read(); if (data2 == 1) { _client.Publish("sensor/info", Encoding.UTF8.GetBytes(message)); } }
private static void blink() { while (true) { Thread.Sleep(2000); led.Write(!led.Read()); //Debug.Print(voltagePort.Read().ToString()); } }
static void dataReady_OnInterrupt(uint data1, uint data2, DateTime time) { ulong ticksOut = (ulong)time.Ticks; led.Write(!led.Read()); acc.getValues(ref x, ref y, ref z); acc.clearInterrupt(); Debug.Print(ticksOut.ToString() + " " + x.ToString()); }
public static void Main() { OutputPort outputPort = new OutputPort(Cpu.Pin.GPIO_Pin0, true); while (true) { Thread.Sleep(500); outputPort.Write(!outputPort.Read()); //toggle port } }
public static void _turnon() { //only redlight _red.Write(true); Thread.Sleep(_timeout); //redlight + yellowlight + turnoff redlight if (_red.Read() == true) { _yellow.Write(true); Thread.Sleep(_p); _red.Write(false); Thread.Sleep(_p); } bool _ON1 = false; //go from yellowlight too greeenlight if (_ON1 == false) { _green.Write(true); _yellow.Write(false); Thread.Sleep(_timeout); } bool _ON2 = false; //go from greenlight to yellowlight if (_ON2 == false) { _yellow.Write(true); _green.Write(false); Thread.Sleep(_timeout); } bool _ON3 = false; //go from ywllowlight to redlight if (_ON3 == false) { _red.Write(true); _yellow.Write(false); Thread.Sleep(_timeout); } bool _OFF = false; //make a timeout before restart if (_OFF == false) { _red.Write(false); Thread.Sleep(_timeout); _ON1 = true; _ON2 = true; _ON3 = true; _OFF = true; } }
private void controlAliveLed(object state) { try { led.Write(!led.Read()); } catch (Exception e) { Logging.LogMessageToFile(this.ToString() + "-" + e.Message, "ALL"); } }
public void BlinkOn(int period) { if (_ledTimer == null) { _ledTimer = new Timer(s => _led.Write(!_led.Read()), null, 0, period); } else { _ledTimer.Change(0, period); } }