Exemplo n.º 1
0
 private void audioTimer_Tick(object sender, EventArgs e) // Draws the audio
 {
     if (cbDevices.SelectedItem != null)
     {
         var   device      = (MMDevice)cbDevices.SelectedItem;
         float deviceValue = device.AudioMeterInformation.MasterPeakValue * hardness;
         deviceValue = deviceValue > 100 ? 100 : deviceValue; // Sets max of 100 for float deviceValue
         if (session != null)
         {
             session.SetDigitalPin(redPin, btnColor.BackColor.R / 100 * (long)deviceValue);
             session.SetDigitalPin(greenPin, btnColor.BackColor.G / 100 * (long)deviceValue);
             session.SetDigitalPin(bluePin, btnColor.BackColor.B / 100 * (long)deviceValue);
         }
     }
 }
Exemplo n.º 2
0
 //Commands Arduino to toggle pin state
 public void ToggleLed(LedModel led)
 {
     if (_comOK && led.PinNumber >= 0)
     {
         led.Value = !led.Value;
         try
         {
             _session.SetDigitalPin(led.PinNumber, led.Value);
         }
         catch
         {
             _comOK    = false;
             led.Value = false;
         }
     }
 }
Exemplo n.º 3
0
        private void findArduino() // Try finding the arduino
        {
            ISerialConnection connection = EnhancedSerialConnection.Find();

            if (connection != null)
            {
                session            = new ArduinoSession(connection);
                lblConnection.Text = "Arduino found!";
                session.SetDigitalPinMode(redPin, PinMode.PwmOutput);
                session.SetDigitalPinMode(greenPin, PinMode.PwmOutput);
                session.SetDigitalPinMode(bluePin, PinMode.PwmOutput);
                session.SetDigitalPin(redPin, btnColor.BackColor.R);
                session.SetDigitalPin(greenPin, btnColor.BackColor.G);
                session.SetDigitalPin(bluePin, btnColor.BackColor.B);
                btnRetry.Hide();
            }
            else
            {
                lblConnection.Text = "The arduino was not found...";
                btnRetry.Show();
            }
        }
Exemplo n.º 4
0
 public void SetDigitalPin(int pinNumber, bool value, int sleep = 0)
 {
     try
     {
         _session.SetDigitalPin(pinNumber, value);
         _sleep(sleep);
     }
     catch (Exception e)
     {
         String msg = String.Format("Error setting digital pin {0} to value {1}, {2}: {3} ", pinNumber, value, e.GetType(), e.Message);
         Tracing?.TraceEvent(TraceEventType.Error, 0, msg);
     }
 }