/// <summary> /// Rotazione oraria apre la persiana paralume. Rotazione anti-oraria chiude la persiana paralume /// </summary> /// <param name="portaA1"></param> /// <param name="portaA2"></param> /// <param name="portaB1"></param> /// <param name="portaB2"></param> /// <param name="portaEndStopOrario"></param> /// <param name="portaEndStopAntiOrario"></param> /// <param name="portaOnOffLuce"></param> public LightDevice( OutShiftRegister shift, int bitA1, int bitA2, int bitB1, int bitB2, int bitLampada, int portaEndStopOrario, int portaEndStopAntiOrario) : base(shift, bitA1, bitA2, bitB1, bitB2, portaEndStopOrario, portaEndStopAntiOrario) { _shift = shift; _bitLampada = bitLampada; shift[bitLampada] = false; shift.OutBits(); //Conta numero di step fra un fine-corsa e l'altro PosizionaFineCorsaAntiOrario(); //Si posiziona a fine-corsa anti oraria apre completamente la persiana paralume _stepTotali = 0; while (StepOrario(1)) { _stepTotali++; //Conta il numero di step fra i due finecorsa e chiude la persiana paralume } _posizioneAttualeInStep = 0; //Aggiorna la posizione attuale _percentuale = 0; //Aggiorna la percentuale attuale this.InvokeWriteLog("LightDevice " + _percentuale); Folle(); }
public Device_OnOffShift(OutShiftRegister shift, int numBit) { _shift = shift; _numBit = numBit; _shift[numBit] = false; _shift.OutBits(); }
private int _fase; // Numero di fase /// <summary> /// inizializzazione dispositivo /// </summary> /// <param name="portaEndStopOrario">Porta collegata all fine corsa sulla rotazione oraria false quando premuto</param> /// <param name="portaEndStopAntiOrario">Porta collegata all fine corsa sulla rotazione anti-oraria false quando premuto</param> public StepMotorEndStopShift( OutShiftRegister shift, int bitA1, int bitA2, int bitB1, int bitB2, int portaEndStopOrario, int portaEndStopAntiOrario) { _shift = shift; _bitA1 = bitA1; _bitA2 = bitA2; _bitB1 = bitB1; _bitB2 = bitB2; var gpio = GpioController.GetDefault(); if (gpio == null) { throw new Exception("GPIO Initialization Failed"); } _endStopOr = gpio.OpenPin(portaEndStopOrario); _endStopAn = gpio.OpenPin(portaEndStopAntiOrario); _endStopOr.SetDriveMode(GpioPinDriveMode.InputPullUp); _endStopAn.SetDriveMode(GpioPinDriveMode.InputPullUp); _fase = 0; Folle(); }
public MainPage() { //fileLog = new FileLogger("file.log"); // Crea ed utilizza un ADC. Il codice del ADC utilizzerà un gestore del bus SPI adc = new DigitalConverterMCP3208(); lux = new LightSensor(adc, 0, 3.3); temp = new TemperatureSensor(adc, 1, 3.3); moisture = new SoilMoistureSensor(adc, 2, 3.3); co2 = new CO2Sensor(adc, 3, 4.9); rh = new RelativeHumiditySensor(adc, 4, 5.0); shift = new OutShiftRegister(16, 25, 24, 23); lcd = new LCD1602Shift(shift, 12, 11, 10, 9, 13, 14); irrigator = new Device_OnOffShift(shift, 8); //irrigator.WriteLog += WriteFileLog; humidifier = new Device_OnOffShift(shift, 2); //humidifier.WriteLog += WriteFileLog; //lightDevice = new LightDevice(shift, 3, 4, 5, 6, 7, 21, 20); //lightDevice.PercentualeApertura(50); //irrigator.TimeOn(3000); this.InitializeComponent(); _timer = new DispatcherTimer(); _timer.Interval = TimeSpan.FromMilliseconds(1000); _timer.Tick += Timer_Tick; InitGPIO(); ////////////if (_pin != null) ////////////{ _timer.Start(); //////////} }
public LCD1602Shift( OutShiftRegister shift, int bit0, int bit1, int bit2, int bit3, int enable, int registerSelect) { _shift = shift; _LCDRegisterSelect = registerSelect; _LCDEnable = enable; _LCDBit0 = bit0; _LCDBit1 = bit1; _LCDBit2 = bit2; _LCDBit3 = bit3; shift[_LCDRegisterSelect] = false; shift.OutBits(); // 4 bit data communication //Task.Delay(50); shift[_LCDBit3] = false; shift[_LCDBit2] = false; shift[_LCDBit1] = true; shift[_LCDBit0] = true; shift.OutBits(); shift[_LCDEnable] = true; //Toggle the Enable Pin shift.OutBits(); shift[_LCDEnable] = false; shift.OutBits(); //Task.Delay(50); shift[_LCDBit3] = false; shift[_LCDBit2] = false; shift[_LCDBit1] = true; shift[_LCDBit0] = true; shift.OutBits(); shift[_LCDEnable] = true; //Toggle the Enable Pin shift.OutBits(); shift[_LCDEnable] = false; shift.OutBits(); //Task.Delay(50); shift[_LCDBit3] = false; shift[_LCDBit2] = false; shift[_LCDBit1] = true; shift[_LCDBit0] = true; shift.OutBits(); shift[_LCDEnable] = true; //Toggle the Enable Pin shift.OutBits(); shift[_LCDEnable] = false; shift.OutBits(); //Task.Delay(50); shift[_LCDBit3] = false; shift[_LCDBit2] = false; shift[_LCDBit1] = true; shift[_LCDBit0] = false; shift.OutBits(); shift[_LCDEnable] = true; //Toggle the Enable Pin shift.OutBits(); shift[_LCDEnable] = false; shift.OutBits(); SendCmd(DISP_ON); SendCmd(CLR_DISP); }