public bool Start() { Console.WriteLine("starting pwm"); if (_working) { return(false); } if (_pinObject != null) { if (_pinObject.Pin != Pin) { if (!_pinObject.IsDisposed) { _pinObject.Dispose(); } _pinObject = new GPIOFile(Pin, GPIODirection.Out); } } else { _pinObject = new GPIOFile(Pin, GPIODirection.Out); } _working = true; new Thread(LoopMethod).Start(); return(true); }
/// <summary> /// Creates a variable of type LiquidCrystal. The display can be controlled using 4 or 8 data lines. If the former, omit the pin numbers for d0 to d3 and leave those lines unconnected. The RW pin can be tied to ground instead of connected to a pin on the Arduino; if so, omit it from this function's parameters. /// </summary> /// <param name="fourBitMode"></param> /// <param name="rs">The number of the CPU pin that is connected to the RS (register select) pin on the LCD.</param> /// <param name="rw">The number of the CPU pin that is connected to the RW (Read/Write) pin on the LCD (optional).</param> /// <param name="enable">the number of the CPU pin that is connected to the enable pin on the LCD.</param> /// <param name="d0"></param> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="d3"></param> /// <param name="d4"></param> /// <param name="d5"></param> /// <param name="d6"></param> /// <param name="d7"></param> public RaspPiGPIOFileLcdTransferProvider(bool fourBitMode, GPIOPins rs, GPIOPins rw, GPIOPins enable, GPIOPins d0, GPIOPins d1, GPIOPins d2, GPIOPins d3, GPIOPins d4, GPIOPins d5, GPIOPins d6, GPIOPins d7) { _fourBitMode = fourBitMode; if (rs == GPIOPins.GPIO_NONE) { throw new ArgumentException("rs"); } _rsPort = new GPIOFile(rs); // we can save 1 pin by not using RW. Indicate by passing GPIO.GPIOPins.GPIO_NONE instead of pin# if (rw != GPIOPins.GPIO_NONE) // (RW is optional) { _rwPort = new GPIOFile(rw); } if (enable == GPIOPins.GPIO_NONE) { throw new ArgumentException("enable"); } _enablePort = new GPIOFile(enable); var dataPins = new[] { d0, d1, d2, d3, d4, d5, d6, d7 }; _dataPorts = new GPIOFile[8]; for (int i = 0; i < 8; i++) { if (dataPins[i] != GPIOPins.GPIO_NONE) { _dataPorts[i] = new GPIOFile(dataPins[i]); } } }
public StepMotor(GPIOFile s1, GPIOFile s2, GPIOFile s3, GPIOFile s4) { S1 = s1; S2 = s2; S3 = s3; S4 = s4; }
/// <summary> /// Creates a variable of type LiquidCrystal. The display can be controlled using 4 or 8 data lines. If the former, omit the pin numbers for d0 to d3 and leave those lines unconnected. The RW pin can be tied to ground instead of connected to a pin on the Arduino; if so, omit it from this function's parameters. /// </summary> /// <param name="fourBitMode"></param> /// <param name="rs">The number of the CPU pin that is connected to the RS (register select) pin on the LCD.</param> /// <param name="rw">The number of the CPU pin that is connected to the RW (Read/Write) pin on the LCD (optional).</param> /// <param name="enable">the number of the CPU pin that is connected to the enable pin on the LCD.</param> /// <param name="d0"></param> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="d3"></param> /// <param name="d4"></param> /// <param name="d5"></param> /// <param name="d6"></param> /// <param name="d7"></param> public RaspPiGPIOFileLcdTransferProvider(bool fourBitMode, GPIOPins rs, GPIOPins rw, GPIOPins enable, GPIOPins d0, GPIOPins d1, GPIOPins d2, GPIOPins d3, GPIOPins d4, GPIOPins d5, GPIOPins d6, GPIOPins d7) { _fourBitMode = fourBitMode; if (rs == GPIOPins.GPIO_NONE) throw new ArgumentException("rs"); _rsPort = new GPIOFile(rs); // we can save 1 pin by not using RW. Indicate by passing GPIO.GPIOPins.GPIO_NONE instead of pin# if (rw != GPIOPins.GPIO_NONE) // (RW is optional) _rwPort = new GPIOFile(rw); if (enable == GPIOPins.GPIO_NONE) throw new ArgumentException("enable"); _enablePort = new GPIOFile(enable); var dataPins = new[] { d0, d1, d2, d3, d4, d5, d6, d7}; _dataPorts = new GPIOFile[8]; for (int i = 0; i < 8; i++) { if (dataPins[i] != GPIOPins.GPIO_NONE) _dataPorts[i] = new GPIOFile(dataPins[i]); } }
static void Main(string[] args) { WebClient wc = new WebClient(); Console.WriteLine("ok"); GPIOFile s1 = new GPIOFile(GPIOPins.V2_Pin_P1_11, GPIODirection.Out); GPIOFile s2 = new GPIOFile(GPIOPins.V2_Pin_P1_12, GPIODirection.Out); GPIOFile s3 = new GPIOFile(GPIOPins.V2_Pin_P1_13, GPIODirection.Out); GPIOFile s4 = new GPIOFile(GPIOPins.V2_Pin_P1_15, GPIODirection.Out); StepMotor m = new StepMotor(s1, s2, s3, s4); while (true) { string json = wc.DownloadString("http://a.wrd.app.fit.ba/home/getcommand?take=1"); WebRezultat[] xArray = JsonConvert.DeserializeObject <WebRezultat[]>(json); var x = xArray[0]; if (x.vrijednost == "Neretva_10_Plavo") { wc.DownloadString("http://a.wrd.app.fit.ba/home?pozicija=Odgovor_na_komandu&vrijednost=Neterva_99_Zeleno"); m.PokreniMotor(400, Direkcija.Naprijed); } else if (x.vrijednost == "Neretva_20_Plavo") { m.PokreniMotor(400, Direkcija.Nazad); } // System.Threading.Thread.Sleep(500); } }
public void Execute(params object[] list) { string MType = ((string)list [0]); switch (MType) { case "READ_TEMPERATURE": GPIOPins X1 = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOFile Sensor1 = new GPIOFile(X1); break; case "READ_LUMINANCE": GPIOPins X2 = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOFile Sensor2 = new GPIOFile(X2); break; case "READ_HUMIDITY": GPIOPins X3 = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOFile Sensor3 = new GPIOFile(X3); break; case "READ_PRESSURE": GPIOPins X4 = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOFile Sensor4 = new GPIOFile(X4); break; case "LEDON": new System.Threading.Thread(delegate() { GPIOPins X = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOMem led = new GPIOMem(X); led.Write(PinState.High); }).Start(); break; case "LEDOFF": new System.Threading.Thread(delegate() { GPIOPins X = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOMem led = new GPIOMem(X); led.Write(PinState.Low); }).Start(); break; case "LEDBLINK_SLOW": new System.Threading.Thread(delegate() { GPIOPins X = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOMem led = new GPIOMem(X); for (int i = 0; i < (int.Parse((string)list [2])); i++) { led.Write(PinState.High); System.Threading.Thread.Sleep(500); led.Write(PinState.Low); System.Threading.Thread.Sleep(500); } }).Start(); break; case "LEDBLINK_FAST": new System.Threading.Thread(delegate() { GPIOPins X = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOMem led = new GPIOMem(X); for (int i = 0; i < (int.Parse((string)list [2])); i++) { led.Write(PinState.High); System.Threading.Thread.Sleep(250); led.Write(PinState.Low); System.Threading.Thread.Sleep(250); led.Write(PinState.High); System.Threading.Thread.Sleep(250); led.Write(PinState.Low); System.Threading.Thread.Sleep(250); } }).Start(); break; case "LEDBLINK_UFAST": new System.Threading.Thread(delegate() { GPIOPins X = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOMem led = new GPIOMem(X); for (int i = 0; i < (int.Parse((string)list [2])); i++) { led.Write(PinState.High); System.Threading.Thread.Sleep(125); led.Write(PinState.Low); System.Threading.Thread.Sleep(125); led.Write(PinState.High); System.Threading.Thread.Sleep(125); led.Write(PinState.Low); System.Threading.Thread.Sleep(125); led.Write(PinState.High); System.Threading.Thread.Sleep(125); led.Write(PinState.Low); System.Threading.Thread.Sleep(125); led.Write(PinState.High); System.Threading.Thread.Sleep(125); led.Write(PinState.Low); System.Threading.Thread.Sleep(125); } }).Start(); break; } }
public static void initRaspberry() { lightReelay = new GPIOFile(GPIOPins.V2_Pin_P1_11, GPIODirection.Out); temperatureSensor = new GPIOFile(GPIOPins.V2_Pin_P1_12, GPIODirection.In); }
public RaspPiGPIOFileLcdTransferProvider(GPIOFile.GPIOPins rs, GPIOFile.GPIOPins rw, GPIOFile.GPIOPins enable, GPIOFile.GPIOPins d0, GPIOFile.GPIOPins d1, GPIOFile.GPIOPins d2, GPIOFile.GPIOPins d3, GPIOFile.GPIOPins d4, GPIOFile.GPIOPins d5, GPIOFile.GPIOPins d6, GPIOFile.GPIOPins d7) : this(false, rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7) { }
public RaspPiGPIOFileLcdTransferProvider(GPIOFile.GPIOPins rs, GPIOFile.GPIOPins rw, GPIOFile.GPIOPins enable, GPIOFile.GPIOPins d4, GPIOFile.GPIOPins d5, GPIOFile.GPIOPins d6, GPIOFile.GPIOPins d7) : this(true, rs, rw, enable, GPIOFile.GPIOPins.GPIO_NONE, GPIOFile.GPIOPins.GPIO_NONE, GPIOFile.GPIOPins.GPIO_NONE, GPIOFile.GPIOPins.GPIO_NONE, d4, d5, d6, d7) { }