Esempio n. 1
0
        public static void Main()
        {
            // write your code here

            BlueSerial ser = new BlueSerial();

            int j = 0;

            while (true)
            {
                Thread.Sleep(500);
                j++;
                ser.Print(j);

            }
        }
Esempio n. 2
0
        public static void Main()
        {
            // write your code here

            BlueSerial ser = new BlueSerial();

            AnalogInput input = new AnalogInput(AnalogChannels.ANALOG_PIN_A0);

            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

            UInt16 j = 0;
            int rawValue = 0;
            UInt16 ll = 0;

            while (true)
            {

                //  0 e 1023 (ADC a 10 bit)
                rawValue = input.ReadRaw();
                Debug.Print(rawValue.ToString());

                ll =  (UInt16)rawValue;

                // ritorna un valore tra 0 ed 1 che va moltiplicato per
                // la ARef per ottenere il valore in Volt della tensione
                //double volt = input.Read() * 3.3;

                if (ll > 4000)
                {
                    led.Write(true);
                }
                else
                {
                    led.Write(false);
                }

                ser.Print(ll);
                Thread.Sleep(5);
            }
        }
Esempio n. 3
0
        public static void Main()
        {
            // write your code here

            UInt32 j = 0;

            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

            BlueSerial ser = new BlueSerial();

            while (true)
            {
                j++;

                //ser.Print(System.Text.Encoding.UTF8.GetBytes("on\n"));   // Brake marker

                ser.Print(j);
                Thread.Sleep(500);
                //led.Write(false);

            }
        }
Esempio n. 4
0
        public static void Main()
        {
            // write your code here

            BlueSerial ser = new BlueSerial();

            AnalogInput input1 = new AnalogInput(AnalogChannels.ANALOG_PIN_A0);  // 2 kN loadcell
            AnalogInput input2 = new AnalogInput(AnalogChannels.ANALOG_PIN_A1);  // 200 kN loadcell

            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

            UInt16 j = 0;
            int rawValue1 = 0;
            int rawValue2 = 0;
            float rawAve1kN = 0;
            float rawAve2kN = 0;
            int rawAve1 = 0;
            int rawAve2 = 0;
            int i = 0;
            UInt16 uintIn1 = 0;
            UInt16 uintIn2 = 0;

            while (true)
            {
                rawValue1 = 0;
                rawValue2 = 0;
                rawAve1 = 0;
                rawAve2 = 0;

                for (i = 1; i <= 50; i++)   // Take an average of 50 samples
                {
                    rawValue1 = input1.ReadRaw();
                    rawAve1 = rawAve1 + rawValue1;
                    rawValue2 = input2.ReadRaw();
                    rawAve2 = rawAve2 + rawValue2;
                    Thread.Sleep(2);
                }

                rawAve1 = rawAve1 / (i-1);
                rawAve2 = rawAve2 / (i-1);

                rawAve1kN = (float)((rawAve1 - 2071) / -943.20518975);  // 2 kN loadcell calibration under "loadcellcalibration.xlsx"
                rawAve2kN = (float)((rawAve2 - 2064) / -13.75116883);  // 200 kN loadcell calibration under "loadcellcalibration.xlsx"

                // Print some values to the output window. This is primative, but works for now.

                Debug.Print("Value 1 Ave: " + rawAve1.ToString() + "    Value 1 Raw: " + rawValue1.ToString() + "    2kN Load Cell Value 1 kN: " + rawAve1kN.ToString() + "    Value 2 Ave: " + rawAve2.ToString() + "    Value 2 Raw: " + rawValue2.ToString() + "    200kN Load Cell Value 2 kN: " + rawAve2kN.ToString());

                uintIn1 = (UInt16)rawAve1;
                uintIn2 = (UInt16)rawAve2;

                // Send the data via bluetooth
                string junk = (uintIn1.ToString() + " " + uintIn2.ToString() + "\n");

                byte[] data = new byte[4] { (byte)(uintIn1 & 0xFF), (byte)((uintIn1 >> 8) & 0xFF), (byte)(uintIn2 & 0xFF), (byte)((uintIn2 >> 8) & 0xFF)};  // Small loadcell first, then large loadcell

               // ser.Print(strain1);
               // Thread.Sleep(5);
                ser.Print(junk);
                //ser.Print(data);
                Thread.Sleep(5);
            }
        }