private static void test()
        {   // per test Adc: definizione del convertitore analogico digitale
            DigitalConverterMCP3208 adc = new DigitalConverterMCP3208();

            // per test IO digitale: definizione di canali di IO digitale
            const int chanLed1    = 40;
            const int chanLed2    = 38;
            const int chanButton1 = 37;
            const int chanButton2 = 35;
            DigitalIO pinIn1      = new DigitalIO(chanButton1, GpioPinDriveMode.Input);
            DigitalIO pinIn2      = new DigitalIO(chanButton2, GpioPinDriveMode.Input);
            DigitalIO pinOut1     = new DigitalIO(chanLed1, GpioPinDriveMode.Output);
            DigitalIO pinOut2     = new DigitalIO(chanLed2, GpioPinDriveMode.Output);
            // si può anche fare così:
            //DigitalIO pinIn1 = new DigitalIO(ConnectorPin.P1Pin37, GpioPinDriveMode.Input);
            //DigitalIO pinOut1 = new DigitalIO(ConnectorPin.P1Pin40, GpioPinDriveMode.Output);
            //DigitalIO pinIn2 = new DigitalIO(ConnectorPin.P1Pin35, GpioPinDriveMode.Input);
            //DigitalIO pinOut2 = new DigitalIO(ConnectorPin.P1Pin38, GpioPinDriveMode.Output);

            // definizioni per test output digitali su shift register
            OutShiftRegister  shift      = new OutShiftRegister(16, 25, 24, 23);
            Device_OnOffShift irrigator  = new Device_OnOffShift(shift, 8);   // ottavo pin dello shift register
            Device_OnOffShift humidifier = new Device_OnOffShift(shift, 2);   // secondo pin dello shift register

            //TestAllDigitalInputs(pinTuttiIn);
            //return;

            while (true)
            {
                Console.CursorTop = 0;
                Console.Clear();

                ReadAllAdc();

                // test two digital inputs
                Console.WriteLine("Canale bottone 1: {0}, Canale bottone 2: {1} ",
                                  chanButton1, chanButton2);
                Console.WriteLine("Bottone 1: {0}, Bottone 2: {1} ",
                                  pinIn1.Read().ToString(), pinIn2.Read().ToString());
                // test two digital outputs
                Console.WriteLine("\r\nCanale LED 1: {0}, Canale LED 2: {1} ",
                                  chanLed1, chanLed2);
                pinOut1.Write(pinIn1.Read());
                pinOut2.Write(pinIn2.Read());

                ActuateShiftRegister();

                Thread.Sleep(500);
            }
        }
        private static void datalog()
        {
            while (true)
            {
                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);

                //_timer = new DispatcherTimer();
                //_timer.Interval = TimeSpan.FromMilliseconds(1000);
                //_timer.Tick += Timer_Tick;
                //if (_pin != null)
                //{
                //    _timer.Start();
                //}
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            const int NUM_BITS  = 16;
            const int DATA_PIN  = 16;
            const int CLOCK_PIN = 16;
            const int LATCH_PIN = 16;

            const int ONOFFSHIFT_BIT = 16;

            OutShiftRegister  reg    = new OutShiftRegister(NUM_BITS, DATA_PIN, CLOCK_PIN, LATCH_PIN);
            Device_OnOffShift tester = new Device_OnOffShift(reg, ONOFFSHIFT_BIT);

            tester.On();
            Console.WriteLine("Tester on");
            Task.Delay(1000);
            tester.Off();
            Console.WriteLine("Tester off");
            Task.Delay(500);
            Console.WriteLine("Tester on for 2 seconds");
            tester.TimeOn(2000);
            Task.Delay(2000);
            Console.WriteLine("Test termined");
        }