public App() { // instantiate all of our peripherals _doorServo = new ContinuousRotationServo(N.PWMChannels.PWM_PIN_D6, NamedServoConfigs.IdealContinuousRotationServo); _button = new PushButton((H.Cpu.Pin) 0x15, CircuitTerminationType.Floating); _openEndStopSwitch = new PushButton(N.Pins.GPIO_PIN_D2, CircuitTerminationType.CommonGround); _closeEndStopSwitch = new PushButton(N.Pins.GPIO_PIN_D3, CircuitTerminationType.CommonGround); // set our end stop trigger events _openEndStopSwitch.PressStarted += (s, e) => { _openEndStopTriggered = true; _doorState = DoorState.Open; Debug.Print("open end stop triggered"); }; _openEndStopSwitch.PressEnded += (s, e) => { _openEndStopTriggered = false; }; _closeEndStopSwitch.PressStarted += (s, e) => { _closeEndStopTriggered = true; _doorState = DoorState.Closed; Debug.Print("close end stop triggered"); }; _closeEndStopSwitch.PressEnded += (s, e) => { _closeEndStopTriggered = false; }; // wire up our button click for door open/close _button.Clicked += (object sender, EventArgs e) => { Debug.Print("Button Clicked"); ToggleDoor(); }; }
public static void Main() { _servo = new ContinuousRotationServo(N.PWMChannels.PWM_PIN_D9, NamedServoConfigs.IdealContinuousRotationServo); _button = new PushButton((H.Cpu.Pin) 0x15, CircuitTerminationType.Floating); _button.Clicked += (object sender, Microsoft.SPOT.EventArgs e) => { Debug.Print("Button Clicked"); ToggleServo(); }; Thread.Sleep(Timeout.Infinite); }
protected void InitializePeripherals() { // display //_display = new Lcd2004(new MCP23008()); _display = new Lcd2004(N.Pins.GPIO_PIN_D8, N.Pins.GPIO_PIN_D9, N.Pins.GPIO_PIN_D10, N.Pins.GPIO_PIN_D11, N.Pins.GPIO_PIN_D12, N.Pins.GPIO_PIN_D13); _display.Clear(); _display.WriteLine("Display up!", 0); // rotary encoder _encoder = new RotaryEncoderWithButton(N.Pins.GPIO_PIN_D4, N.Pins.GPIO_PIN_D5, N.Pins.GPIO_PIN_D7, CircuitTerminationType.CommonGround); // door stuff _doorServo = new ContinuousRotationServo(N.PWMChannels.PWM_PIN_D6, NamedServoConfigs.IdealContinuousRotationServo); _openEndStopSwitch = new PushButton(N.Pins.GPIO_PIN_D2, CircuitTerminationType.CommonGround); _closeEndStopSwitch = new PushButton(N.Pins.GPIO_PIN_D3, CircuitTerminationType.CommonGround); _display.WriteLine("Door stuff up!", 1); // temp stuff _heatLampRelay = new SoftPwm(N.Pins.GPIO_PIN_D0, 0, 1f / 60f); _tempSensor = new AnalogTemperature(N.AnalogChannels.ANALOG_PIN_A0, AnalogTemperature.KnownSensorType.LM35, updateInterval: 5000, temperatureChangeNotificationThreshold: 1.0f); _display.WriteLine("Temp stuff up!", 2); //==== now wire up all the peripheral events // Analog Temp Sensor. Setup to notify at half a degree changes _tempSensor.TemperatureChanged += (object sender, SensorFloatEventArgs e) => { _currentTemp = e.CurrentValue; Debug.Print("Current Temp: " + _currentTemp.ToString("N1")); UpdateInfoScreen(); }; _encoder.Clicked += (s, e) => { // if the menu isn't displayed, display it. otherwise // encoder click events are handled by menu if (!_inMenu) { this.DisplayMenu(); } }; Debug.Print("Peripherals initialized."); }
public DoorController(IContinuousRotationServo doorServo, PushButton openEndStopSwitch, PushButton closeEndStopSwitch) { // instantiate all of our peripherals _doorServo = doorServo; _openEndStopSwitch = openEndStopSwitch; _closeEndStopSwitch = closeEndStopSwitch; // set our end stop trigger events _openEndStopSwitch.PressStarted += (s, e) => { _openEndStopTriggered = true; _doorState = DoorStateType.Open; Debug.Print("open end stop triggered"); }; _openEndStopSwitch.PressEnded += (s, e) => { _openEndStopTriggered = false; }; _closeEndStopSwitch.PressStarted += (s, e) => { _closeEndStopTriggered = true; _doorState = DoorStateType.Closed; Debug.Print("close end stop triggered"); }; _closeEndStopSwitch.PressEnded += (s, e) => { _closeEndStopTriggered = false; }; // load our initial state from the physical state this._doorState = PhysicalState; }