private void setRedPin() { try { int newPin = int.Parse(txtRedInput.Text); if (newPin == newGreen || newPin == newBlue) { throw new ArgumentException("Pin already exists!"); } session.SetDigitalPinMode(newPin, PinMode.PwmOutput); newRed = newPin; redPin = newPin; lblRedNumber.Text = redPin.ToString(); txtRedInput.Hide(); pbSubmitRed.Hide(); if (!txtRedInput.Visible && !txtGreenInput.Visible && !txtBlueInput.Visible) { newRed = -1; newGreen = -1; newBlue = -1; btnChangePins.Show(); } } catch (ArgumentException ex) { MessageBox.Show(ex.Message); txtRedInput.Clear(); } catch (Exception) { MessageBox.Show("This is not a correct pin!"); txtRedInput.Clear(); } }
public ArduinoModel(TeamDataModel teamData1, TeamDataModel teamData2) { SetConnection(); if (_comOK) { _session = new ArduinoSession(_connection); _keepAliveTimer = new Timer(Constants.keepAliveInterval) { AutoReset = true }; _keepAliveTimer.Elapsed += _keepAliveTimer_Elapsed; _keepAliveTimer.Start(); //_session.SetSamplingInterval(400); _session.SetDigitalPinMode(Constants.rlimb, PinMode.InputPullup); _session.SetDigitalPinMode(Constants.rlimf, PinMode.InputPullup); _session.SetDigitalPinMode(Constants.blimb, PinMode.InputPullup); _session.SetDigitalPinMode(Constants.blimf, PinMode.InputPullup); _session.SetDigitalReportMode(Constants.limitSwitchPort, true); var tracker = _session.CreateDigitalStateMonitor(Constants.limitSwitchPort); teamData1.TeamControl.BackLimSwitch.Subscribe(tracker); teamData1.TeamControl.FrontLimSwitch.Subscribe(tracker); teamData2.TeamControl.BackLimSwitch.Subscribe(tracker); teamData2.TeamControl.FrontLimSwitch.Subscribe(tracker); //use code below to enable event managed pin updates //_session.DigitalStateReceived += DigitalStateReceivedHandler; } //Subscribe to controllable data changes //Planned: publish sensor updates using TeamSensor object in teamData _teamData1 = teamData1; _teamData1.TeamControl.HoverLed.PropertyChanged += OnLedChanged; _teamData1.TeamControl.Obstacle1Led.PropertyChanged += OnLedChanged; _teamData1.TeamControl.Obstacle2Led.PropertyChanged += OnLedChanged; _teamData1.TeamControl.Platform1Led.PropertyChanged += OnLedChanged; _teamData1.TeamControl.Platform2Led.PropertyChanged += OnLedChanged; _teamData1.TeamControl.StartLed.PropertyChanged += OnLedChanged; _teamData1.TeamControl.Motor.PropertyChanged += OnMotorChanged; _teamData2 = teamData2; _teamData2.TeamControl.HoverLed.PropertyChanged += OnLedChanged; _teamData2.TeamControl.Obstacle1Led.PropertyChanged += OnLedChanged; _teamData2.TeamControl.Obstacle2Led.PropertyChanged += OnLedChanged; _teamData2.TeamControl.Platform1Led.PropertyChanged += OnLedChanged; _teamData2.TeamControl.Platform2Led.PropertyChanged += OnLedChanged; _teamData2.TeamControl.StartLed.PropertyChanged += OnLedChanged; _teamData2.TeamControl.Motor.PropertyChanged += OnMotorChanged; }
public void SetDigitalPinMode(int pinNumber, PinMode pinMode, int sleep = 0) { try { _session.SetDigitalPinMode(pinNumber, pinMode); _sleep(sleep); } catch (Exception e) { String msg = String.Format("Error setting digital pin {0} to mode {1}, {2}: {3} ", pinNumber, pinMode, e.GetType(), e.Message); Tracing?.TraceEvent(TraceEventType.Error, 0, msg); } }
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(); } }