public Generator (double updateFrequency = DefaultUpdateFrequency) : base (updateFrequency) { startTicks = DateTime.UtcNow.Ticks; Output = AddOutput ("Output", Units.Scalar, 0); }
TurnMotorAtPowerAsync(OutputPort ports, int power) { return TurnMotorAtPowerAsyncInternal(ports, power) #if WINRT .AsAsyncAction() #endif ; }
TurnMotorAtSpeedAsync(OutputPort ports, int speed) { return TurnMotorAtSpeedAsyncInternal(ports, speed) #if WINRT .AsAsyncAction() #endif ; }
StepMotorAtPowerAsync(OutputPort ports, int power, uint steps, bool brake) { return StepMotorAtPowerAsyncInternal(ports, power, 0, steps, 0, brake) #if WINRT .AsAsyncAction() #endif ; }
public CelsiusToFahrenheit () { Celsius = AddInput ("Celsius", Units.Temperature); Fahrenheit = AddOutput ("Fahrenheit", Units.Scalar); Celsius.ValueChanged += (s, e) => { Fahrenheit.Value = 9.0 / 5.0 * Celsius.Value + 32; }; }
public LookupTable () { Input = AddInput ("Input", Units.Scalar); Output = AddOutput ("Output", Units.Scalar, 0); Input.ValueChanged += (s, e) => SetOutput (); SetOutput (); }
public Memsic2125() { XPwmInput = AddInput ("XPwmInput", Units.Digital); YPwmInput = AddInput ("YPwmInput", Units.Digital); XAccelerationOutput = AddOutput ("XAcceleration", Units.EarthGravity); YAccelerationOutput = AddOutput ("YAcceleration", Units.EarthGravity); CreateProcessor (XPwmInput, XAccelerationOutput); CreateProcessor (YPwmInput, YAccelerationOutput); }
public DutyCycleMeter () { upTime = Time (); downTime = upTime; PwmInput = AddInput ("PwmInput", Units.Digital); DutyCycleOutput = AddOutput ("DutyCycleOutput", Units.Ratio); FrequencyOutput = AddOutput ("FrequencyOutput", Units.Frequency); PwmInput.ValueChanged += PwmInput_ValueChanged; }
// From http://www.sharpsma.com/webfm_send/1203 public SharpGP2D12 () { AnalogInput = new InputPort (this, "AnalogInput", Units.Ratio); DistanceOutput = new OutputPort (this, "DistanceOutput", Units.Distance, 0); lookup = new LookupTable { { 0.0912, 0.7904 }, { 0.1086, 0.6472 }, { 0.1476, 0.4352 }, { 0.2094, 0.2912 }, { 0.2976, 0.196 }, { 0.3876, 0.1456 }, { 0.528, 0.0976 }, }; lookup.Input.ConnectTo (AnalogInput); lookup.Output.ConnectTo (DistanceOutput); }
public HBridgeMotor (IPwm pwm = null) { CalibrationInput = AddInput ("CalibrationInput", Units.Ratio, 1); SpeedInput = AddInput ("SpeedInput", Units.Ratio, 0); IsNeutralInput = AddInput ("IsNeutralInput", Units.Boolean, 0); A1Output = AddOutput ("A1Output", Units.Digital, 0); A2Output = AddOutput ("A2Output", Units.Digital, 0); PwmFrequencyOutput = AddOutput ("PwmFrequencyOutput", Units.Frequency, DefaultFrequency); PwmDutyCycleOutput = AddOutput ("PwmDutyCycleOutput", Units.Ratio, SpeedInput.Value); // This is a direct connection. SpeedInput.ValueChanged += (s, e) => Update (); IsNeutralInput.ValueChanged += (s, e) => Update (); if (pwm != null) { PwmFrequencyOutput.ConnectTo (pwm.FrequencyInput); PwmDutyCycleOutput.ConnectTo (pwm.DutyCycleInput); } }
/// <summary> /// Step the motor connected to the specified port or ports at the specified speed for the specified number of steps. /// </summary> /// <param name="ports">A specific port or Ports.All.</param> /// <param name="speed">The speed at which to turn the motor (-100% to 100%).</param> /// <param name="steps"></param> /// <param name="brake">Apply brake to motor at end of routine.</param> public void StepMotorAtSpeed(OutputPort ports, int speed, uint steps, bool brake) { StepMotorAtSpeed(ports, speed, 0, steps, 0, brake); }
public Relay(Cpu.Pin pin, string name) : base(name, ActuatorType.Relay) { relay = new OutputPort(pin, false); }
/// <summary> /// Append the Set Polarity command to an existing Command object /// </summary> /// <param name="ports">Port or ports to change polarity</param> /// <param name="polarity">The new polarity (direction) value</param> public void SetMotorPolarity(OutputPort ports, Polarity polarity) { AddOpcode(Opcode.OutputPolarity); AddParameter(0x00); AddParameter((byte)ports); AddParameter((byte)polarity); }
/// <summary> /// Step the motor connected to the specified port or ports at the specified speed for the specified number of steps. /// </summary> /// <param name="ports">A specific port or Ports.All.</param> /// <param name="speed">The speed at which to turn the motor (-100% to 100%).</param> /// <param name="rampUpSteps"></param> /// <param name="constantSteps"></param> /// <param name="rampDownSteps"></param> /// <param name="brake">Apply brake to motor at end of routine.</param> public void StepMotorAtSpeed(OutputPort ports, int speed, uint rampUpSteps, uint constantSteps, uint rampDownSteps, bool brake) { if(speed < -100 || speed > 100) throw new ArgumentException("Speed must be between -100 and 100 inclusive.", "speed"); AddOpcode(Opcode.OutputStepSpeed); AddParameter(0x00); // layer AddParameter((byte)ports); // ports AddParameter((byte)speed); // speed AddParameter(rampUpSteps); // step1 AddParameter(constantSteps); // step2 AddParameter(rampDownSteps); // step3 AddParameter((byte)(brake ? 0x01 : 0x00)); // brake (0 = coast, 1 = brake) }
internal void AddOutput() { var output = new OutputPort("Output" + Brain.KB.Sources.GetOutputPorts().Count); Brain.KB.Sources.AddOutputPort(output); LoadOutputs(); ui.listBoxOutputs.SelectedIndex = OutputPorts.Count - 1; LoadSignals(); }
public static void Main() { //distance sensor //triger (12), echo (13), 5V + G HC_SR04 sensor = new HC_SR04(Pins.GPIO_PIN_D12, Pins.GPIO_PIN_D13); //buzzer OutputPort Klakson = new OutputPort(Pins.GPIO_PIN_D0, false); //motor driver HBridge MotorDriver = new HBridge(SecretLabs.NETMF.Hardware.Netduino.PWMChannels.PWM_PIN_D5, Pins.GPIO_PIN_D4, SecretLabs.NETMF.Hardware.Netduino.PWMChannels.PWM_PIN_D6, Pins.GPIO_PIN_D7); //led indicator if there is an object in the front of robot OutputPort WarningLed = new OutputPort(Pins.GPIO_PIN_D1, false); OutputPort GoLed = new OutputPort(Pins.GPIO_PIN_D2, false); //waiting till connect... if (!Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IsDhcpEnabled) { // using static IP while (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) { ; // wait for network connectivity } } else { // using DHCP while (IPAddress.GetDefaultLocalAddress() == IPAddress.Any) { ; // wait for DHCP-allocated IP address } } //Debug print our IP address Debug.Print("Device IP: " + Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress); // create mqtt client instance client = new MqttClient(IPAddress.Parse(MQTT_BROKER_ADDRESS)); string clientId = Guid.NewGuid().ToString(); client.Connect(clientId); SubscribeMessage(); PublishMessage("/robot/state", "ONLINE"); while (true) { long ticks = sensor.Ping(); if (ticks > 0L) { double inches = sensor.TicksToInches(ticks); Debug.Print("jarak ke object :" + inches); if (inches < 4) { jalan = Arah.Berhenti; Klakson.Write(true); WarningLed.Write(true); GoLed.Write(false); PublishMessage("/robot/status", "Watchout there is an object in the front of robot!"); } else { Klakson.Write(false); WarningLed.Write(false); GoLed.Write(true); } } //stop first before change direction or turn if (lastDirection != jalan) { //stop before start new direction MotorDriver.SetState(HBridge.Motors.Motor1, 0); MotorDriver.SetState(HBridge.Motors.Motor2, 0); } switch (jalan) { case Arah.Maju: MotorDriver.SetState(HBridge.Motors.Motor1, Speed); MotorDriver.SetState(HBridge.Motors.Motor2, Speed); break; case Arah.Mundur: MotorDriver.SetState(HBridge.Motors.Motor1, (sbyte)(-Speed)); MotorDriver.SetState(HBridge.Motors.Motor2, (sbyte)(-Speed)); break; case Arah.Kiri: MotorDriver.SetState(HBridge.Motors.Motor1, -50); MotorDriver.SetState(HBridge.Motors.Motor2, 50); break; case Arah.Kanan: MotorDriver.SetState(HBridge.Motors.Motor1, 50); MotorDriver.SetState(HBridge.Motors.Motor2, -50); break; case Arah.Berhenti: MotorDriver.SetState(HBridge.Motors.Motor1, 0); MotorDriver.SetState(HBridge.Motors.Motor2, 0); break; } lastDirection = jalan; } }
public async Task TurnMotorAsync(OutputPort port, int power, double seconds) { await Brick.DirectCommand .TurnMotorAtPowerForTimeAsync(port, power, (uint)(seconds * 1000), false); }
public void TurnMotor(OutputPort port, int power, double seconds) { Task.Run(() => TurnMotorAsync(port, power, seconds)); Thread.Sleep((int)(seconds * 1000)); }
// Constructor public Led(Microsoft.SPOT.Hardware.Cpu.Pin LedPin) { physicalLed = new OutputPort(LedPin, false); lockObject = new Object(); this.Off(); }
private void CheckHoveringAndSelection() { if (_isLayoutEvent) { return; } ResetHover(); bool isDraggingGrid = _currentActivity == Activity.DraggingGrid; Rect selectionRect = _selectionRect; Vector2 mousePosition = _mousePosition; List <Object> boxSelected = new List <Object>(); //TODO Investigate reverse recognition not working!? //Never mind it works, it's just my architecture works bottom-top, //instead of top-bottom-or-stop //Why? Cause hovering //TODO Investigate alternatives for conversion for (int i = 0; i < Graph.NodeCount; i++) { Node node = Graph.GetNode(i); NodeEditor nodeEditor = NodeEditor.GetEditor(node); Vector2 size; if (_nodeSizes.TryGetValue(node, out size)) { Rect nodeRect = new Rect(node.Position, size); nodeRect = GridToWindowRect(nodeRect); if (nodeRect.Contains(mousePosition)) { _hoveredNode = node; } if (isDraggingGrid && nodeRect.Overlaps(selectionRect)) { boxSelected.Add(node); } } //Check hovering over ports var inputNode = node as IInput; if (inputNode != null) { InputPort input = inputNode.InputPort; Rect inputRect = nodeEditor.GetPortRect(input); //inputRect.position += node.Position; inputRect = GridToWindowRect(inputRect); if (inputRect.Contains(mousePosition)) { HoveredPort = input; } } IOutput sOutputNode = node as IOutput; if (sOutputNode != null) { OutputPort output = sOutputNode.OutputPort; Rect outputRect = nodeEditor.GetPortRect(output); //outputRect.position += node.Position; outputRect = GridToWindowRect(outputRect); if (outputRect.Contains(mousePosition)) { HoveredPort = output; } } IMultipleOutput mOutputNode = node as IMultipleOutput; if (mOutputNode != null) { var outputs = mOutputNode.GetOutputs(); foreach (OutputPort output in outputs) { Rect outputRect = nodeEditor.GetPortRect(output); //outputRect.position += node.Position; outputRect = GridToWindowRect(outputRect); if (outputRect.Contains(mousePosition)) { HoveredPort = output; } } } } for (int i = 0; i < Graph.ConnectionCount; i++) { Connection connection = Graph.GetConnection(i); if (connection == null) { Debug.Log("Null connection at index " + i); OnNull(Graph); continue; } Vector2 start = NodeEditor.FindPortRect(connection.Start).center; Vector2 end = NodeEditor.FindPortRect(connection.End).center; start = GridToWindowPosition(start); end = GridToWindowPosition(end); //if (OtherUtilities.PointOverlapBezier(mousePosition, start, end, NodePreferences.CONNECTION_WIDTH)) if (LineSegment.WideLineSegmentPointCheck(mousePosition, start, end, NodePreferences.CONNECTION_WIDTH * 2 / Zoom)) { _hoveredConnection = connection; } //DONE: Add range percentage overlap check, as just overlapping might be too annoying. if (isDraggingGrid && LineSegment.LineRectOverlapPercentageCheck(selectionRect, start, end) > 0.3f) { boxSelected.Add(connection); } Rect[] modifierRects; if (!_connectionModifierRects.TryGetValue(connection, out modifierRects)) { continue; } for (int j = 0; j < connection.InstructionCount; j++) { Instruction mod = connection.GetInstruction(j); Rect rect = GridToWindowRect(modifierRects[j]); if (rect.Contains(mousePosition)) { _hoveredInstruction = mod; } if (isDraggingGrid && rect.Overlaps(selectionRect)) { boxSelected.Add(mod); } } } //return; if (isDraggingGrid) { if (_cachedEvent.control || _cachedEvent.shift) { boxSelected.AddRange(_cachedSelectedObjects); } Selection.objects = boxSelected.ToArray(); } else { _selectionRect = Rect.zero; } }
public static void Main() { //////////////////////////////////////////////////////// // BEGIN Computer variables //////////////////////////////////////////////////////// Utility.SetLocalTime(new DateTime(2011, 01, 01, 12, 0, 0, 0)); // Blink board LED bool blinkLEDState = false; // test blink led OutputPort blinkLED = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, blinkLEDState); // Sensor port InterruptPort IntSensorButton = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di1, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow); // add an interrupt handler to the pin IntSensorButton.OnInterrupt += new NativeEventHandler(IntSensorButton_OnInterrupt); // Switch displey on/off port InterruptPort IntDisplayOnOffButton = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di2, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow); // add an interrupt handler to the pin IntDisplayOnOffButton.OnInterrupt += new NativeEventHandler(IntDisplayOnOffButton_OnInterrupt); FEZ_Shields.KeypadLCD.Initialize(); bikeData.IsDisplayOn = true; DisplayController display = new DisplayController(bikeData); ///////////////////////////////////////////////////////// // END Computer variables ///////////////////////////////////////////////////////// // Main loop while (true) { // |0123456789012345 // 0|99 km/h 99:99:99 // 1|99.999 km 99:99 // Edit 1 Wheel size: 999> // Edit 2 Time: 99:99:99 > // Reset speedometer if (display.CanEditLine()) { bikeData.lastDisplayUsed = DateTime.Now; } else { TimeSpan lastDisplayUsedSpan = DateTime.Now - bikeData.lastDisplayUsed; if (lastDisplayUsedSpan.Seconds > 5) { bikeData.lastSpeedCheck = DateTime.MinValue; bikeData.CurrentSpeed = 0; bikeData.IsDisplayOn = false; } } // Reset trip timer TimeSpan lastTripCheckSpan = DateTime.Now - bikeData.lastTripCheck; if (lastTripCheckSpan.Minutes > 30) { bikeData.IsStartTripSet = false; bikeData.StartTrip = DateTime.MinValue; } // Sleep for 500 milliseconds Thread.Sleep(500); display.DisplayLines(); FEZ_Shields.KeypadLCD.Keys KeyPressed = FEZ_Shields.KeypadLCD.GetKey(); if (KeyPressed != FEZ_Shields.KeypadLCD.Keys.None) { if (!bikeData.IsDisplayOn) { bikeData.IsDisplayOn = true; } else { display.ProcessKey(KeyPressed); } } // toggle LED state blinkLEDState = !blinkLEDState; blinkLED.Write(blinkLEDState); } }
internal async Task SetMotorPolarityAsyncInternal(OutputPort ports, Polarity polarity) { Command c = new Command(CommandType.DirectNoReply); c.SetMotorPolarity(ports, polarity); await _brick.SendCommandAsyncInternal(c); }
public void LoadOutput(int i) { //Detach trigger from every available event! Brain.KB.Sources.DetachAllEvents(this.Trigger); if (i < 0 || i >= ui.listBoxOutputs.Items.Count) return; CurrentPort = OutputPorts[i]; var port = CurrentPort; ui.comboBoxSignal.SelectedIndex = signals.IndexOf(port.Signal); ui.comboBoxEvent.SelectedIndex = events.IndexOf(port.Event); ui.comboBoxCrosstalk.SelectedIndex = -1; ui.textBoxName.Text = port.Name; ui.checkBoxEnabled.Checked = port.Enabled; ui.textBoxMidiChannel.Text = port.MidiChannel.ToString(); ui.textBoxCCNumber.Text = port.CCNumber.ToString(); ui.checkBoxIsNote.Checked = port.IsNote; ui.comboBoxFilterSignal.SelectedIndex = (port.Filter != null) ? signals.IndexOf(port.Filter) : -1; ui.checkBoxFilterEnabled.Checked = port.FilterEnabled; ui.textBoxFilterMin.Text = port.FilterMin.ToString(); ui.textBoxFilterMax.Text = port.FilterMax.ToString(); ui.velocityMapControl.Map = new AudioLib.VelocityMap(port.VelocityMap); // Attach the trigger that updates the view if (port.Event != null) port.Event.Add(this.Trigger, null); LoadCrosstalk(); }
/// <summary>Puts a pin high for a short amount of time</summary> /// <param name="Pin">The pin to put high</param> private void _PinTick(OutputPort Pin) { Pin.Write(true); Pin.Write(false); }
public Esp8266WifiDevice(SerialPort port, OutputPort powerPin, OutputPort resetPin) { _powerPin = powerPin; _resetPin = resetPin; Initialize(port); }
public Lid(BaseMotorController lidMotor, InputPort lidSwitch, OutputPort lidSwitchled) { m_lidMotor = lidMotor; m_lidSwitch = lidSwitch; m_lidSwitchled = lidSwitchled; }
/// <summary> /// Turn the motor connected to the specified port or ports at the specified speed for the specified times. /// </summary> /// <param name="ports">A specific port or Ports.All.</param> /// <param name="speed">The power at which to turn the motor (-100% to 100%).</param> /// <param name="milliseconds">Number of milliseconds to run at constant speed.</param> /// <param name="brake">Apply brake to motor at end of routine.</param> /// <returns></returns> public void TurnMotorAtSpeedForTime(OutputPort ports, int speed, uint milliseconds, bool brake) { TurnMotorAtSpeedForTime(ports, speed, 0, milliseconds, 0, brake); }
//public static void Main() //{ // using (var a1 = new AnalogInput(Cpu.AnalogChannel.ANALOG_1)) // { // var last = 0.0d; // while (Debugger.IsAttached) // { // var reading = a1.Read(); // if (reading != last) // { // Debug.Print(reading.ToString()); // last = reading; // } // } // } //} public static void Main() { var wiiChuck = new WiiChuck(true); var debugMode = Debugger.IsAttached; _redLed = new OutputPort(Pins.GPIO_PIN_D13, false); _greenLed = new OutputPort(Pins.GPIO_PIN_A0, false); _pot = new AnalogInput(Cpu.AnalogChannel.ANALOG_1); //_speaker = new PWM(Pins.GPIO_PIN_D9); //_speakerThread = new Thread(PlaySound); //_speakerThread.Start(); //_servo1 = new ServoController(Mshield.Servo1, 600, 2400, startDegree: 90); _robot = new TankRobot(); while (!debugMode || Debugger.IsAttached) { // try to read the data from nunchucku if (wiiChuck.GetData()) { CheckButtons(wiiChuck.CButtonDown, wiiChuck.ZButtonDown); if (Recording) { _iteration++; SetMotorSpeed(_robot, wiiChuck); } else if (PlayingBack) { if (_currentPlaybackIndex >= _record.Count) { PlayingBack = false; _currentPlaybackIndex = 0; } else { _iteration++; var record = (DataPoint)_record[_currentPlaybackIndex]; if (record.Iterations == _iteration) { _currentPlaybackIndex++; _robot.Move(record.LeftSpeed, record.RightSpeed); } } } else { SetMotorSpeed(_robot, wiiChuck); } //var degrees = ((int) (90+(-90*wiiChuck.AccelerationXGs))/2)*2; //if (degrees < 0) // degrees = 0; //else if (degrees > 180) // degrees = 180; //_servo1.Rotate(degrees); //Debug.Print("AccelX = " + wiiChuck.AccelerationXGs + " AccelY=" + wiiChuck.AccelerationYGs); } } wiiChuck.Dispose(); _robot.Dispose(); //_speaker.Dispose(); //_speaker = null; //_servo1.Dispose(); _redLed.Dispose(); _greenLed.Dispose(); _pot.Dispose(); }
/// <summary> /// Append the Stop Motor command to an existing Command object /// </summary> /// <param name="ports">Port or ports to stop</param> /// <param name="brake">Apply the brake at the end of the command</param> public void StopMotor(OutputPort ports, bool brake) { AddOpcode(Opcode.OutputStop); AddParameter(0x00); // layer AddParameter((byte)ports); // ports AddParameter((byte)(brake ? 0x01 : 0x00)); // brake (0 = coast, 1 = brake) }
public Rich() { _richPin = new OutputPort(Pins.GPIO_PIN_D6, false); _richPin.Write(false); }
public override void OpenPorts() { _inPort = OpenInput("IN"); _confPort = OpenInput("CONF"); _outPort = OpenOutput("OUT"); }
/// <summary> /// Actually starts the demo /// </summary> /// <param name="Server">Reference to the Telnet Server</param> public static void Start(TelnetServer Server) { // Configures the onboard button. If this fails, it's probably already in use by another app. InputPort Button = null; try { Button = new InputPort(ONBOARD_SW1, false, Port.ResistorMode.Disabled); } catch (Exception e) { Server.Color(TelnetServer.Colors.LightRed); Server.Print("Exception " + e.Message + " given. Were the onboard Button already configured?"); Server.Color(TelnetServer.Colors.White); return; } // Configures the onboard LED. If this fails, it's probably already in use by another app. OutputPort Led = null; try { Led = new OutputPort(ONBOARD_LED, false); } catch (Exception e) { Button.Dispose(); // The button is already defined Server.Color(TelnetServer.Colors.LightRed); Server.Print("Exception " + e.Message + " given. Were the onboard LED already configured?"); Server.Color(TelnetServer.Colors.White); return; } // Disables echoing of keypresses Server.EchoEnabled = false; // Clears the screen Server.ClearScreen(); // Draws a Netduino Plus in ANSI/ASCII art Server.Print("\xda\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xbf"); Server.Print("\xb3 \xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe \xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xb3"); Server.Print("\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb \xdc \xb3"); Server.Print("\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb NETDUINO \xb3"); Server.Print("\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb PLUS \xb3"); Server.Print("\xb3 ..\xb3"); Server.Print("\xdb\xdb \xdb\xdb ::\xb3"); Server.Print("\xb3 \xdb\xdb\xdb\xdb\xdb\xdb \xb3"); Server.Print("\xdb\xdb\xdb\xdb\xdb \xdb\xdb\xdb\xdb\xdb\xdb \xb3"); Server.Print("\xdb\xdb\xdb\xdb\xdb \xdb\xdb\xdb\xdb\xdb\xdb \xfe\xfe\xfe\xfe\xfe\xfe \xfe\xfe\xfe\xfe\xfe\xfe\xb3"); Server.Print("\xc0\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xdb\xdb\xdb\xdb\xdb\xdb\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xd9"); Server.Print("", true); Server.Print("Push the Netduino Plus onboard button, or press a key to close this app"); // We only update the screen if the LastState is different from the current state bool LastState = false; while (Server.IsConnected && Server.Input(1, false) == "") { // We need to update if (Button.Read() == LastState) { // Lets record the last state LastState = !Button.Read(); Led.Write(LastState); // Draws the button if (LastState) { Server.Color(TelnetServer.Colors.HighIntensityWhite); } else { Server.Color(TelnetServer.Colors.Gray); } Server.Locate(7, 26, true); Server.Print("\xdb\xdb", true, true); // Draws the LED if (LastState) { Server.Color(TelnetServer.Colors.LightBlue); } else { Server.Color(TelnetServer.Colors.Gray); } Server.Locate(3, 29, true); Server.Print("\xdc", true); // Brings back the cursor to the last line Server.Locate(14, 1); } } // Releases the pins Button.Dispose(); Led.Dispose(); // Enables echo again and clears the screen if (Server.IsConnected) { Server.EchoEnabled = true; Server.ClearScreen(); } }
public FileNode(Graph g) : base("File", g, InputPort.CreateMany(), OutputPort.CreateMany(OutputPort.Create("Out", PortDataType.Array))) { _portOut = (DataOutputPort)OutputPorts[0]; }
/// <summary> /// Initializes a new instance of the <see cref="AdafruitV1MotorShield" /> class. /// </summary> /// <param name="latch">The latch store register clock pin (STCP).</param> /// <param name="enable">The latch output enable pin (OE).</param> /// <param name="data">The latch serial data pin (DS).</param> /// <param name="clock">The latch shift register clock pin (SHCP).</param> public AdafruitV1MotorShield(OutputPort latch, OutputPort enable, OutputPort data, OutputPort clock) { this.latch = latch; this.enable = enable; this.data = data; this.clock = clock; serialShiftRegister = new SerialShiftRegister(enable, clock, data, latch); }
/// <summary> /// Turn the motor connected to the specified port or ports at the specified power for the specified times. /// </summary> /// <param name="ports">A specific port or Ports.All.</param> /// <param name="power">The power at which to turn the motor (-100% to 100%).</param> /// <param name="milliseconds">Number of milliseconds to run at constant power.</param> /// <param name="brake">Apply brake to motor at end of routine.</param> /// <returns></returns> public void TurnMotorAtPowerForTime(OutputPort ports, int power, uint milliseconds, bool brake) { TurnMotorAtPowerForTime(ports, power, 0, milliseconds, 0, brake); }
/// <summary> /// Step the motor connected to the specified port or ports at the specified power for the specified number of steps. /// </summary> /// <param name="ports">A specific port or Ports.All.</param> /// <param name="power">The power at which to turn the motor (-100% to 100%).</param> /// <param name="steps">The number of steps to turn the motor.</param> /// <param name="brake">Apply brake to motor at end of routine.</param> public void StepMotorAtPower(OutputPort ports, int power, uint steps, bool brake) { StepMotorAtPower(ports, power, 0, steps, 10, brake); }
/// <summary> /// Start the motor(s) based on previous commands /// </summary> /// <param name="ports">Port or ports to apply the command to.</param> public void StartMotor(OutputPort ports) { AddOpcode(Opcode.OutputStart); AddParameter(0x00); // layer AddParameter((byte)ports); // ports }
internal async Task StartMotorAsyncInternal(OutputPort ports) { Command c = new Command(CommandType.DirectNoReply); c.StartMotor(ports); await _brick.SendCommandAsyncInternal(c); }
/// <summary> /// Turn the specified motor at the specified speed. /// </summary> /// <param name="ports">Port or ports to apply the command to.</param> /// <param name="speed">The speed to apply to the specified motors (-100% to 100%).</param> public void TurnMotorAtSpeed(OutputPort ports, int speed) { if(speed < -100 || speed > 100) throw new ArgumentException("Speed must be between -100 and 100 inclusive.", "speed"); AddOpcode(Opcode.OutputSpeed); AddParameter(0x00); // layer AddParameter((byte)ports); // ports AddParameter((byte)speed); // speed }
public void LoadOutputs() { // Outputs OutputPorts = Brain.KB.Sources.GetOutputPorts(); ui.listBoxOutputs.Items.Clear(); foreach (var port in OutputPorts) { // show in the list on the left side ui.listBoxOutputs.Items.Add(port.Name); } // reload selected index try { ui.listBoxOutputs.SelectedIndex = SelectedIndex; } catch (Exception e) { ui.listBoxOutputs.SelectedIndex = 0; CurrentPort = Brain.KB.Sources.GetOutputPorts()[0]; } }
/// <summary> /// Step the motor connected to the specified port or ports at the specified power for the specified number of steps. /// </summary> /// <param name="ports">A specific port or Ports.All.</param> /// <param name="power">The power at which to turn the motor (-100% to 100%).</param> /// <param name="rampUpSteps"></param> /// <param name="constantSteps"></param> /// <param name="rampDownSteps"></param> /// <param name="brake">Apply brake to motor at end of routine.</param> public void StepMotorAtPower(OutputPort ports, int power, uint rampUpSteps, uint constantSteps, uint rampDownSteps, bool brake) { if(power < -100 || power > 100) throw new ArgumentException("Power must be between -100 and 100 inclusive.", "power"); AddOpcode(Opcode.OutputStepPower); AddParameter(0x00); // layer AddParameter((byte)ports); // ports AddParameter((byte)power); // power AddParameter(rampUpSteps); // step1 AddParameter(constantSteps); // step2 AddParameter(rampDownSteps); // step3 AddParameter((byte)(brake ? 0x01 : 0x00)); // brake (0 = coast, 1 = brake) }
public void main() { // オンボードLEDの点滅 OutputPort boardLed = new OutputPort(Pins.ONBOARD_LED, false); boardLed.Write(true); InputPort btn = new InputPort(Pins.ONBOARD_BTN, false, Port.ResistorMode.Disabled); int pat = 0; pin0 = new OutputPort(Pins.GPIO_PIN_D0, false); pin1 = new OutputPort(Pins.GPIO_PIN_D1, false); pin2 = new OutputPort(Pins.GPIO_PIN_D2, false); pin3 = new OutputPort(Pins.GPIO_PIN_D3, false); pin4 = new OutputPort(Pins.GPIO_PIN_D4, false); pin0.Write(false); pin1.Write(false); pin2.Write(false); pin3.Write(false); pin4.Write(false); Action[] patterns = new Action[] { pattern01, pattern02, pattern03, pattern11, pattern12, pattern13, pattern2, pattern3, pattern4 }; // LEDを光らせるスレッド new Thread(() => { pin0.Write(true); Thread.Sleep(500); while (true) { patterns[pat](); } }).Start(); // ボタン待ちのスレッド bool preBtn = false; new Thread(() => { while (true) { if (btn.Read()) { if (preBtn == false) { pat++; if (pat >= patterns.Length) { pat = 0; } // リレーのために pin0 だけ付けておく pin0.Write(true); } preBtn = true; } else { preBtn = false; } Thread.Sleep(50); } }).Start(); // メインスレッドを終了させるとプログラムが終了するので無限に停止 Thread.Sleep(Timeout.Infinite); }
/// <summary> /// Wait for the specificed output port(s) to be ready for the next command /// </summary> /// <param name="ports">Port(s) to wait for</param> /// <returns></returns> public void OutputReady(OutputPort ports) { AddOpcode(Opcode.OutputReady); AddParameter(0x00); // layer AddParameter((byte)ports); // ports }
public Constant (double value) { Output = AddOutput ("Output", Units.Scalar, value); }
// Constructor public Led(Microsoft.SPOT.Hardware.Cpu.Pin LedPin) { physicalLed = new OutputPort(LedPin, false); currentStateLocker = new Object(); this.Off(); }
/// <summary> /// Turns the specified motor at the specified power /// </summary> /// <param name="ports">Port or ports to apply the command to.</param> /// <param name="power">The amount of power to apply to the specified motors (-100% to 100%).</param> public void TurnMotorAtPower(OutputPort ports, int power) { if(power < -100 || power > 100) throw new ArgumentException("Power must be between -100 and 100 inclusive.", "power"); AddOpcode(Opcode.OutputPower); AddParameter(0x00); // layer AddParameter((byte)ports); // ports AddParameter((byte)power); // power }
static Display() { _rs = new OutputPort((Cpu.Pin)rs, false); _reset = new OutputPort((Cpu.Pin)reset, false); _backlight = new OutputPort((Cpu.Pin)backlight, true); _spi_con = new SPI.Configuration((Cpu.Pin)cs, false, 0, 0, false, true, 12000, SPI.SPI_module.SPI2); _spi = new SPI(_spi_con); Reset(); //------------------------------------------------------------------// //--------------------------Software Reset--------------------------// //------------------------------------------------------------------// WriteCommand(0x11);//Sleep exit Thread.Sleep(120); // ST7735R Frame Rate WriteCommand(0xB1); WriteData(0x01); WriteData(0x2C); WriteData(0x2D); WriteCommand(0xB2); WriteData(0x01); WriteData(0x2C); WriteData(0x2D); WriteCommand(0xB3); WriteData(0x01); WriteData(0x2C); WriteData(0x2D); WriteData(0x01); WriteData(0x2C); WriteData(0x2D); WriteCommand(0xB4); // Column inversion WriteData(0x07); // ST7735R Power Sequence WriteCommand(0xC0); WriteData(0xA2); WriteData(0x02); WriteData(0x84); WriteCommand(0xC1); WriteData(0xC5); WriteCommand(0xC2); WriteData(0x0A); WriteData(0x00); WriteCommand(0xC3); WriteData(0x8A); WriteData(0x2A); WriteCommand(0xC4); WriteData(0x8A); WriteData(0xEE); WriteCommand(0xC5); // VCOM WriteData(0x0E); WriteCommand(0x36); // MX, MY, RGB mode WriteData(MADCTL_MX | MADCTL_MY | MADCTL_BGR); // ST7735R Gamma Sequence WriteCommand(0xe0); WriteData(0x0f); WriteData(0x1a); WriteData(0x0f); WriteData(0x18); WriteData(0x2f); WriteData(0x28); WriteData(0x20); WriteData(0x22); WriteData(0x1f); WriteData(0x1b); WriteData(0x23); WriteData(0x37); WriteData(0x00); WriteData(0x07); WriteData(0x02); WriteData(0x10); WriteCommand(0xe1); WriteData(0x0f); WriteData(0x1b); WriteData(0x0f); WriteData(0x17); WriteData(0x33); WriteData(0x2c); WriteData(0x29); WriteData(0x2e); WriteData(0x30); WriteData(0x30); WriteData(0x39); WriteData(0x3f); WriteData(0x00); WriteData(0x07); WriteData(0x03); WriteData(0x10); WriteCommand(0x2a); WriteData(0x00); WriteData(0x00); WriteData(0x00); WriteData(0x7f); WriteCommand(0x2b); WriteData(0x00); WriteData(0x00); WriteData(0x00); WriteData(0x9f); WriteCommand(0xF0); //Enable test command WriteData(0x01); WriteCommand(0xF6); //Disable ram power save mode WriteData(0x00); WriteCommand(0x3A); //65k mode WriteData(0x05); // rotate WriteCommand(ST7735_MADCTL); WriteData((byte)(MADCTL_MV | MADCTL_MY | (isBgr ? MADCTL_BGR : 0))); WriteCommand(0x29); //Display on Thread.Sleep(50); }
public static void Main() { // shield-specific setup. Uncomment one of the shield #define lines above. #if UseOnboardLedForDiagnostics Led = new OutputPort(Pins.ONBOARD_LED, false); #endif #if AdafruitV1Shield var adafruitMotorShieldV1 = new AdafruitV1MotorShield(); adafruitMotorShieldV1.InitializeShield(); StepperM1M2 = adafruitMotorShieldV1.GetMicrosteppingStepperMotor(MicrostepsPerStep, 1, 2); StepperM3M4 = adafruitMotorShieldV1.GetFullSteppingStepperMotor(3, 4); #elif AdafruitV2Shield var adafruitMotorShieldV2 = new SparkfunArdumoto(); // use shield at default I2C address. adafruitMotorShieldV2.InitializeShield(); StepperM1M2 = adafruitMotorShieldV2.GetMicrosteppingStepperMotor(MicrostepsPerStep, 1, 2); StepperM3M4 = adafruitMotorShieldV2.GetMicrosteppingStepperMotor(MicrostepsPerStep, 3, 4); #elif SparkfunArduMotoShield var shield = new SparkfunArdumoto(); shield.InitializeShield(); var phase1 = shield.GetHBridge(Connector.A, TargetDevice.Netduino); var phase2 = shield.GetHBridge(Connector.B, TargetDevice.Netduino); StepperM1M2 = shield.GetMicrosteppingStepperMotor(MicrostepsPerStep, phase1, phase2); #elif LedSimulatorShield var StepperM1M2 = LedMotorSimulator.GetSimulatedStepperMotor(Pins.GPIO_PIN_D0, PWMChannels.PWM_ONBOARD_LED, Pins.GPIO_PIN_D1, PWMChannels.PWM_PIN_D6); #else throw new ApplicationException("Uncomment one of the shield #define statements"); #endif // Create the stepper motor axes and link them to the shield driver. axis1 = new InstantaneousStepperMotor(LimitOfTravel, StepperM1M2) { MaximumSpeed = MaxSpeed //RampTime = RampTime }; axis1.BeforeStep += UpdateDiagnosticLed; speed = 1.0; direction = +1; var fasterButton = new InterruptPort(Pins.GPIO_PIN_D1, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow); var slowerButton = new InterruptPort(Pins.GPIO_PIN_D2, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow); var reverseButton = new InterruptPort(Pins.GPIO_PIN_D13, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow); fasterButton.OnInterrupt += fasterButton_OnInterrupt; slowerButton.OnInterrupt += slowerButton_OnInterrupt; reverseButton.OnInterrupt += reverseButton_OnInterrupt; SetMotorVelocity(); Thread.Sleep(Timeout.Infinite); }
/* * public override object[] Introspect() * { * return new object[] { * "Read a chunk of text from IN, write words to OUT, rejects to OUTN.", * "Set attributes: Text=input text, Offset=word offset in text", * "Non-looper. 1->N" * }; * } */ public override void OpenPorts() { _inp = OpenInput("IN"); _outp = OpenOutput("OUT"); _outpn = OpenOutput("OUTN"); }
//Constructors public LCD(OutputPort rs, OutputPort e, OutputPort bl, OutputPort d7, OutputPort d6, OutputPort d5, OutputPort d4) { this.registerSelect = rs; this.enable = e; this.BackLight = bl; this.d7 = d7; this.d6 = d6; this.d5 = d5; this.d4 = d4; InitLCD(); }
/// <summary> /// Turn the motor connected to the specified port or ports at the specified speed for the specified times. /// </summary> /// <param name="ports">A specific port or Ports.All.</param> /// <param name="speed">The power at which to turn the motor (-100% to 100%).</param> /// <param name="msRampUp">Number of milliseconds to get up to speed.</param> /// <param name="msConstant">Number of milliseconds to run at constant speed.</param> /// <param name="msRampDown">Number of milliseconds to slow down to a stop.</param> /// <param name="brake">Apply brake to motor at end of routine.</param> /// <returns></returns> public void TurnMotorAtSpeedForTime(OutputPort ports, int speed, uint msRampUp, uint msConstant, uint msRampDown, bool brake) { if(speed < -100 || speed > 100) throw new ArgumentException("Speed must be between -100 and 100 inclusive.", "speed"); AddOpcode(Opcode.OutputTimeSpeed); AddParameter(0x00); // layer AddParameter((byte)ports); // ports AddParameter((byte)speed); // power AddParameter(msRampUp); // step1 AddParameter(msConstant); // step2 AddParameter(msRampDown); // step3 AddParameter((byte)(brake ? 0x01 : 0x00)); // brake (0 = coast, 1 = brake) }
public IOutConnection GetMpegPlayerConnection() { var fileSourceOutput = new OutputPort("Output"); var fileSource = new OutConnection("File Source (Async.)") { OutputPins = new List <OutputPort> { fileSourceOutput } }; var mpeg2DemultiplexerInput = new InputPort("MPEG-2 Stream"); var mpeg2DemultiplexerVideoOut = new OutputPort("Video"); var mpeg2DemultiplexerAc3Out = new OutputPort("AC-3"); var mpeg2Demultiplexer = new InOutConnection("MPEG-2 Demultiplexer") { InputPins = new List <InputPort> { mpeg2DemultiplexerInput }, OutputPins = new List <OutputPort> { mpeg2DemultiplexerVideoOut, mpeg2DemultiplexerAc3Out } }; fileSourceOutput.ConnectedPort = mpeg2DemultiplexerInput; var ffdshowVideoDecoderInput = new InputPort("In"); var ffdshowVideoDecoderOutput = new OutputPort("Out"); var ffdshowVideoDecoder = new InOutConnection("ffdshow Video Decoder") { InputPins = new List <InputPort> { ffdshowVideoDecoderInput }, OutputPins = new List <OutputPort> { ffdshowVideoDecoderOutput } }; mpeg2DemultiplexerVideoOut.ConnectedPort = ffdshowVideoDecoderInput; var videoRendererInput = new InputPort("VMR Input0"); var videoRenderer = new InOutConnection("Video Renderer") { InputPins = new List <InputPort> { videoRendererInput } }; ffdshowVideoDecoderOutput.ConnectedPort = videoRendererInput; var ffdshowAudioDecoderInput = new InputPort("In"); var ffdshowAudioDecoderOutput = new OutputPort("Out"); var ffdshowAudioDecoder = new InOutConnection("ffdshow Audio Decoder") { InputPins = new List <InputPort> { ffdshowAudioDecoderInput } }; mpeg2DemultiplexerAc3Out.ConnectedPort = ffdshowAudioDecoderInput; var audioRendererInput = new InputPort("Audio Input pin (rendered)"); var audioRenderer = new InConnection("Default DirectSound Device") { InputPins = new List <InputPort> { audioRendererInput } }; ffdshowAudioDecoderOutput.ConnectedPort = audioRendererInput; return(fileSource); }
/// <summary> /// Synchronize timing of motors. /// </summary> /// <param name="ports">The port or ports to which the stop command will be sent.</param> /// <param name="speed">Speed to turn the motor(s). (-100 to 100)</param> /// <param name="turnRatio">The turn ratio to apply. (-200 to 200)</param> /// <param name="time">The time to turn the motor(s).</param> /// <param name="brake">Brake or coast at the end.</param> /// <returns></returns> public void TimeMotorSync(OutputPort ports, int speed, short turnRatio, uint time, bool brake) { if(speed < -100 || speed > 100) throw new ArgumentException("Speed must be between -100 and 100", "speed"); if(turnRatio < -200 || turnRatio > 200) throw new ArgumentException("Turn ratio must be between -200 and 200", "turnRatio"); AddOpcode(Opcode.OutputTimeSync); AddParameter(0x00); AddParameter((byte)ports); AddParameter((byte)speed); AddParameter(turnRatio); AddParameter(time); AddParameter((byte)(brake ? 0x01 : 0x00)); // brake (0 = coast, 1 = brake) }
public IOutConnection GetAviPlayerConnection() { var fileSourceOutput = new OutputPort("Output"); var fileSource = new OutConnection("File Source (Async.)") { OutputPins = new List <OutputPort> { fileSourceOutput } }; var aviSplitterInput = new InputPort("input pin"); var aviSplitterVideoStream = new OutputPort("Stream 00"); var aviSplitterAudioStream = new OutputPort("Stream 01"); var aviSplitter = new InOutConnection("AVI Splitter") { InputPins = new List <InputPort> { aviSplitterInput }, OutputPins = new List <OutputPort> { aviSplitterVideoStream, aviSplitterAudioStream } }; fileSourceOutput.ConnectedPort = aviSplitterInput; var mpegDecoderDmoInput = new InputPort("in0"); var mpegDecoderDmoOutput = new OutputPort("out0"); var mpegDecoderDmo = new InOutConnection("Mpeg4s Decoder DMO") { InputPins = new List <InputPort> { mpegDecoderDmoInput }, OutputPins = new List <OutputPort> { mpegDecoderDmoOutput } }; aviSplitterVideoStream.ConnectedPort = mpegDecoderDmoInput; var videoRendererInput = new InputPort("VMR Input0"); var videoRenderer = new InOutConnection("Video Renderer") { InputPins = new List <InputPort> { videoRendererInput } }; mpegDecoderDmoOutput.ConnectedPort = videoRendererInput; var audioRendererInput = new InputPort("Audio Input pin (rendered)"); var audioRenderer = new InOutConnection("Default WaveOut Device") { InputPins = new List <InputPort> { audioRendererInput } }; aviSplitterAudioStream.ConnectedPort = audioRendererInput; return(fileSource); }
public void StartController() { CoffeeState = CoffeeState.Standby; ControllerMode = ControllerMode.Automatic; ControllerModeTimer = new Timer(IncreaseUptimeTimer, null, 1000, Timeout.Infinite); // write your code here // setup the LED and turn it off by default Led = new OutputPort(Pins.ONBOARD_LED, false); // configure the port # (the standard web server port is 80) int port = 80; // wait a few seconds for the Netduino Plus to get a network address. Thread.Sleep(5000); // display the IP address NetworkInterface networkInterface = NetworkInterface.GetAllNetworkInterfaces()[0]; Debug.Print("my ip address: " + networkInterface.IPAddress); // create a socket to listen for incoming connections and the listener end point var listenerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint listenerEndPoint = new IPEndPoint(IPAddress.Any, port); // bind to the listening socket listenerSocket.Bind(listenerEndPoint); // and start listening for incoming connections listenerSocket.Listen(1); // listen for and process incoming requests while (true) { // wait for a client to connect Socket clientSocket = listenerSocket.Accept(); // wait for data to arrive bool dataReady = clientSocket.Poll(5000000, SelectMode.SelectRead); // if dataReady is true and there are bytes available to read, // then you have a good connection. if (dataReady && clientSocket.Available > 0) { var buffer = new byte[clientSocket.Available]; int bytesRead = clientSocket.Receive(buffer); var request = new string(System.Text.Encoding.UTF8.GetChars(buffer)); if (request.IndexOf("START") >= 0 && ControllerMode == ControllerMode.Automatic) { this.TurnOnCoffee(); this.GetStatusCoffee(clientSocket); } else if (request.IndexOf("STOP") >= 0 && ControllerMode == ControllerMode.Automatic) { this.TurnOffCoffee(null); this.GetStatusCoffee(clientSocket); Thread.Sleep(2000); PowerState.RebootDevice(false); } else if (request.IndexOf("STATUS") >= 0) { this.GetStatusCoffee(clientSocket); } else if (request.IndexOf("MANUAL") >= 0 && ControllerMode == ControllerMode.Automatic) { this.TurnManualModeOn(); this.GetStatusCoffee(clientSocket); } else if (request.IndexOf("AUTOMATIC") >= 0 && ControllerMode == ControllerMode.Manual) { ControllerMode = ControllerMode.Automatic; this.GetStatusCoffee(clientSocket); Thread.Sleep(2000); PowerState.RebootDevice(false); } } // important: close the client socket clientSocket.Close(); } }