コード例 #1
0
ファイル: Program.cs プロジェクト: KiwiBryn/Longboard-NetNF
        public static void Main()
        {
            Debug.WriteLine("devMobile.Longboard.PwmTest starting");
            Debug.WriteLine(PwmController.GetDeviceSelector());

            try
            {
                PwmController pwm        = PwmController.FromId("TIM5");
                AdcController adc        = AdcController.GetDefault();
                AdcChannel    adcChannel = adc.OpenChannel(0);

                PwmPin pwmPin = pwm.OpenPin(PinNumber('A', 0));
                pwmPin.Controller.SetDesiredFrequency(1000);
                pwmPin.Start();

                while (true)
                {
                    double value = adcChannel.ReadRatio();

                    Debug.WriteLine(value.ToString("F2"));

                    pwmPin.SetActiveDutyCyclePercentage(value);

                    Thread.Sleep(100);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
コード例 #2
0
        private void Update()
        {
            // Read X and Y values
            var x = xChannel.ReadRatio();
            var y = yChannel.ReadRatio();

            // Scale to -1 to 1, and Y needs to be inverted
            x = (x * 2) - 1;
            y = (-y * 2) + 1;

            // Button
            bool pressed = false;

            if (buttonPin != null)
            {
                pressed = (buttonPin.Read() == GpioPinValue.Low);
            }

            // Update current value
            lock (currentReading)
            {
                currentReading = new ThumbstickReading(x, y, pressed);
            }

            // Notify
            readingChangedEvent.Raise(this, new ThumbstickReadingChangedEventArgs(currentReading));
        }
コード例 #3
0
        /// <summary>
        /// Read temperature value of sensor
        /// </summary>
        /// <returns>Get Temperature in Celsius</returns>
        public double ReadTemperature()
        {
            // Per code example from seeed http://wiki.seeed.cc/Grove-Temperature_Sensor_V1.2/
            // Seemes to work fine with 3.3V
            double d           = _channel.ReadRatio() * 1023;
            double r           = 1023.0 / d - 1.0;
            double temperature = 1.0 / (System.Math.Log(r) / 4275 + 1 / 298.15) - 273.15;

            return(temperature);
        }
コード例 #4
0
        private double Read(AdcChannel input)
        {
            double total = 0;

            for (int i = 0; i < this.samples; i++)
            {
                total += input.ReadRatio();
            }

            return(total / this.samples);
        }
コード例 #5
0
ファイル: SoundSensor.cs プロジェクト: winhoals/TinyClrLib
        /// <summary>
        /// Get level of sound
        /// </summary>
        /// <returns>Percentage of sound</returns>
        public double ReadLevel()
        {
            double lastRead = 0;

            for (int i = 0; i < 10; i++)
            {
                double d = _channel.ReadRatio();
                if (d > lastRead)
                {
                    lastRead = d;
                }
            }
            return(lastRead * 100);
        }
コード例 #6
0
        // between 0 and 100
        public double ReadLevel()
        {
            double LastRead = 0;

            for (int i = 0; i < 10; i++)
            {
                double d = Channel.ReadRatio();
                if (d > LastRead)
                {
                    LastRead = d;
                }
            }
            return(LastRead * 100);
        }
コード例 #7
0
        private void Update(bool raiseEvent)
        {
            // Read X and Y values
            var val   = adcChannel.ReadValue();
            var ratio = adcChannel.ReadRatio(); // TODO: Support customized value scaling

            // Update current value
            lock (currentReading)
            {
                currentReading = new AnalogSensorReading(val, ratio);
            }

            // Notify?
            if (raiseEvent)
            {
                readingChangedEvent.Raise(this, new AnalogSensorReadingChangedEventArgs(currentReading));
            }
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: KiwiBryn/Longboard-NetNF
        public static void Main()
        {
            Debug.WriteLine("devMobile.Longboard.ServoTest starting");

            try
            {
                AdcController adc        = AdcController.GetDefault();
                AdcChannel    adcChannel = adc.OpenChannel(0);

#if POSITIONAL
                ServoMotor servo = new ServoMotor("TIM5", ServoMotor.ServoType.Positional, PinNumber('A', 0));
                servo.ConfigurePulseParameters(0.1, 2.3);
#endif
#if CONTINUOUS
                ServoMotor servo = new ServoMotor("TIM5", ServoMotor.ServoType.Continuous, PinNumber('A', 0));
                servo.ConfigurePulseParameters(0.1, 2.3);
#endif

                while (true)
                {
                    double value = adcChannel.ReadRatio();

#if POSITIONAL
                    double position = Map(value, 0.0, 1.0, 0.0, 180);
#endif
#if CONTINUOUS
                    double position = Map(value, 0.0, 1.0, -100.0, 100.0);
#endif
                    Debug.WriteLine($"Value: {value:F2} Position: {position:F1}");

                    servo.Set(position);

                    Thread.Sleep(100);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
コード例 #9
0
        public static void Main()
        {
            string devs = AdcController.GetDeviceSelector();

            Console.WriteLine("devs=" + devs);

            AdcController adc1 = AdcController.GetDefault();

            int max1 = adc1.MaxValue;
            int min1 = adc1.MinValue;

            Console.WriteLine("min1=" + min1.ToString() + " max1=" + max1.ToString());

            AdcChannel ac0 = adc1.OpenChannel(0);

            // the following indexes are valid for STM32F769I-DISCO board
            AdcChannel vref = adc1.OpenChannel(0);
            AdcChannel vbat = adc1.OpenChannel(8);

            // VP
            //AdcChannel ac3 = adc1.OpenChannel(3);
            // VN
            while (true)
            {
                int value     = ac0.ReadValue();
                int valueVref = vref.ReadValue();
                int valueVbat = vbat.ReadValue();

                double percent = ac0.ReadRatio();

                Console.WriteLine("value0=" + value.ToString() + " ratio=" + percent.ToString());
                Console.WriteLine("verf" + valueVref.ToString() + " ratio=" + percent.ToString());
                Console.WriteLine("vbat" + valueVbat.ToString() + " ratio=" + percent.ToString());

                Thread.Sleep(1000);
            }
        }
コード例 #10
0
        public static void Main()
        {
            Debug.WriteLine("devMobile.Longboard.AdcTest starting");
            Debug.WriteLine(AdcController.GetDeviceSelector());

            try
            {
                AdcController adc        = AdcController.GetDefault();
                AdcChannel    adcChannel = adc.OpenChannel(0);

                while (true)
                {
                    double value = adcChannel.ReadRatio();

                    Debug.WriteLine($"Value: {value:F2}");

                    Thread.Sleep(100);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
コード例 #11
0
 // between 0 and 100
 public double ReadLightLevel()
 {
     return(Channel.ReadRatio() * 100);
 }
コード例 #12
0
 // between 0 and 100
 public double GetAngle()
 {
     return(Channel.ReadRatio() * 100);
 }
コード例 #13
0
 public static double BatteryVoltage() => voltage.ReadRatio() * 3.3 / 0.6;
コード例 #14
0
 // between 0 and 100
 /// <summary>
 /// Get the percentage of value of position
 /// </summary>
 /// <returns>Get percentage of value</returns>
 public double GetPercentage()
 {
     return(_channel.ReadRatio() * 100);
 }
コード例 #15
0
 public static double BatteryVoltage()
 {
     return(voltage.ReadRatio() * 3.3 / 0.6);
 }
コード例 #16
0
 /// <summary>
 /// Read the light value of sensor
 /// </summary>
 /// <returns>Percentage of light value between 0 and 100.</returns>
 public double ReadPercentageLightLevel()
 {
     return(_channel.ReadRatio() * 100);
 }
コード例 #17
0
        private static double ReadAnalogSensor(int pAin)
        {
#if !UseTestValues
            // Use values read from the analogInput ports

            double theRead = 999.9;
            switch (pAin)
            {
            case 0:
            {
                theRead = analog0.ReadRatio();
            }
            break;

            case 1:
            {
                theRead = analog1.ReadRatio();
            }
            break;

            case 2:
            {
                theRead = analog2.ReadRatio();
            }
            break;

            case 3:
            {
                theRead = analog3.ReadRatio();
            }
            break;
            }

            return(theRead * 10.0);
#else
            // Only as an example we here return values which draw a sinus curve
            // Console.WriteLine("entering Read analog sensor");
            int frequDeterminer = 4;
            int y_offset        = 1;
            // different frequency and y_offset for aIn_0 to aIn_3
            if (pAin == 0)
            {
                frequDeterminer = 4; y_offset = 1;
            }
            if (pAin == 1)
            {
                frequDeterminer = 8; y_offset = 10;
            }
            if (pAin == 2)
            {
                frequDeterminer = 12; y_offset = 20;
            }
            if (pAin == 3)
            {
                frequDeterminer = 16; y_offset = 30;
            }


            int secondsOnDayElapsed = DateTime.Now.Second + DateTime.Now.Minute * 60 + DateTime.Now.Hour * 60 * 60;

            if (pAin == 3)
            {
                return(Math.Round((double)(uploadCounter % 100)) / 10);
            }
            else
            {
                return(Math.Round(25f * (double)Math.Sin(Math.PI / 2.0 + (secondsOnDayElapsed * ((frequDeterminer * Math.PI) / (double)86400)))) / 10 + y_offset);
            }
#endif
        }
コード例 #18
0
ファイル: Potentiometer.cs プロジェクト: winhoals/TinyClrLib
 /// <summary>Gets the current position of the potentiometer between 0.0 and 1.0.</summary>
 public double ReadProportion()
 {
     return(_input.ReadRatio());
 }