protected LedCube(byte size, Cpu.Pin[] levelPins, Cpu.Pin[] ledPins, CubeOrientations orientation = CubeOrientations.ZPos ) { Size = size; Orientation = orientation; Levels = new OutputPort[Size]; Leds = new OutputPort[Size*Size]; // Make sure we have the correct number of level pins. if(levelPins.Length != size) { throw new ArgumentOutOfRangeException("levelPins", "You must define " + Size + " level pins."); } // Make sure we have the correct number of LED pins. if (ledPins.Length != size * size) { throw new ArgumentOutOfRangeException("ledPins", "You must define " + Size*Size + " led pins."); } // Create level ports. for (byte lvl = 0; lvl < Size; lvl++ ) { Levels[lvl] = new OutputPort(levelPins[lvl], false); } // Create LED ports. for (byte led = 0; led < Size*Size; led++) { Leds[led] = new OutputPort(ledPins[led], false); } }
private OutputPort stcpPort; // Storage Register Clock pin #endregion Fields #region Constructors /// <summary> /// Constructor /// </summary> /// <param name="ds">Pin Serial Data</param> /// <param name="shcp">Pin Shift Register Clock</param> /// <param name="stcp">Pin Storage Register Clock</param> /// <param name="mr">Pin Master Reset</param> /// <param name="oe">Pin Output Enable</param> /// <param name="bitOrder">Bit order during transferring</param> public ShiftRegister74HC595(Cpu.Pin ds, Cpu.Pin shcp, Cpu.Pin stcp, Cpu.Pin mr, Cpu.Pin oe, BitOrder bitOrder) { // Serial Data (DS) pin is necessary if (ds == Cpu.Pin.GPIO_NONE) throw new ArgumentException("Serial Data (DS) pin is necessary"); this.dsPort = new OutputPort(ds, false); // Shift Register Clock (SHCP) pin is necessary if (shcp == Cpu.Pin.GPIO_NONE) throw new ArgumentException("Shift Register Clock (SHCP) pin is necessary"); this.shcpPort = new OutputPort(shcp, false); // you can save 1 pin connecting STCP and SHCP together if (stcp != Cpu.Pin.GPIO_NONE) this.stcpPort = new OutputPort(stcp, false); // you can save 1 pin connecting MR pin to Vcc (no reset) if (mr != Cpu.Pin.GPIO_NONE) this.mrPort = new OutputPort(mr, true); // you can save 1 pin connecting OE pin to GND (shift register output pins are always enabled) if (oe != Cpu.Pin.GPIO_NONE) this.oePort = new OutputPort(oe, false); this.bitOrder = bitOrder; }
public static void Main() { var thdLed = new Thread(HandleLed); thdLed.Start(); var digitalSensor = new DigitalSensor { InputPin = Pins.GPIO_PIN_D12 }; var analogSensor = new AnalogSensor { InputPin = Pins.GPIO_PIN_A1, MinValue = 0.0, MaxValue = 3.3 }; var lowPort = new OutputPort(Pins.GPIO_PIN_A0, false); var highPort = new OutputPort(Pins.GPIO_PIN_A2, true); var ledActuator = new DigitalActuator { OutputPin = Pins.GPIO_PIN_D13 }; //need to create HTTP PUTs! var webServer = new HttpServer { RelayDomain = "gsiot-bcjp-yj88", RelaySecretKey = "HDMvyM11hAu6H6cxIaT50dL9ALWc81MYB8H/UFhV", RequestRouting = { { "GET /hello*", HandleHello }, //This accepts a lot of URLs { "GET /on", HandleOn }, { "GET /off", HandleOff }, { "POST /on", HandlePostOn }, { "POST /off", HandlePostOff }, { "GET /d12", new MeasuredVariable{ FromSensor=digitalSensor.HandleGet}.HandleRequest}, { "GET /a1", new MeasuredVariable{ FromSensor=analogSensor.HandleGet}.HandleRequest}, { "PUT /d13", new ManipulatedVariable{ FromHttpRequest=CSharpRepresentation.TryDeserializeBool,ToActuator=ledActuator.HandlePut}.HandleRequest}, } }; webServer.Run(); }
public static void Main() { OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); led.Write(true); VoltageDivider voltageReader = new VoltageDivider(Pins.GPIO_PIN_A1, 470000, 4700); Acs712 currentReader = new Acs712(Pins.GPIO_PIN_A2, Acs712.Range.ThirtyAmps); EmonCmsProxy.Start(); MpptOptimizer.Start(); led.Write(false); led.Dispose(); GC.WaitForPendingFinalizers(); //Random r = new Random((int) DateTime.Now.Ticks); while (true) { double current = //r.NextDouble() / double.MaxValue * 10; currentReader.Read(); double voltage = //r.NextDouble() / double.MaxValue * 3; voltageReader.Read(); EmonCmsProxy.Push(current, voltage); MpptOptimizer.Push(current, voltage); Thread.Sleep(50); } }
static void Main() { var lowPort = new OutputPort(Parameters.LowPin, false); var highPort = new OutputPort(Parameters.HighPin, true); var voltageSensor = new AnalogSensor { InputPin = Parameters.AnalogPin, MinValue = 0.0, MaxValue = 3.3 }; var webServer = new HttpServer { RelayDomain = Parameters.RelayDomain, RelaySecretKey = Parameters.RelaySecretKey, RequestRouting = { { "GET /voltage/actual", new MeasuredVariable { FromSensor = voltageSensor.HandleGet }.HandleRequest } } }; webServer.Run(); }
public Stepper(Cpu.Pin pinCoil1A, Cpu.Pin pinCoil1B, Cpu.Pin pinCoil2A, Cpu.Pin pinCoil2B, uint stepsPerRevolution, string name) : base(name, "stepper") { // remember the steps per revolution this.StepsPerRevolution = stepsPerRevolution; // reset the step-counter this.currentStep = 0; // determine correct pins for the coils; turn off all motor pins this.portCoil1A = new OutputPort(pinCoil1A, false); Util.Delay(500); this.portCoil1B = new OutputPort(pinCoil1B, false); Util.Delay(500); this.portCoil2A = new OutputPort(pinCoil2A, false); Util.Delay(500); this.portCoil2B = new OutputPort(pinCoil2B, false); // set the maximum speed SetSpeed(120); }
public void Connect(Cpu.Pin pinTrig, Cpu.Pin pinEcho) { _portOut = new OutputPort(pinTrig, false); _interIn = new InterruptPort(pinEcho, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow); _interIn.OnInterrupt += new NativeEventHandler(interIn_OnInterrupt); Reset(); }
public LEDStrip(Cpu.Pin clockPin, Cpu.Pin dataPin) { NumOfLEDs = 32; _clock = new OutputPort(clockPin, false); _data = new OutputPort(dataPin, false); post_frame(); }
static Config() { Latch = new OutputPort(Pins.GPIO_PIN_D9, false); Device = new SPI.Configuration( ChipSelect_Port: Pins.GPIO_NONE, // SS-pin = slave select, not used ChipSelect_ActiveState: false, // SS-pin active state ChipSelect_SetupTime: 0, // The setup time for the SS port ChipSelect_HoldTime: 0, // The hold time for the SS port Clock_IdleState: true, // The idle state of the clock Clock_Edge: true, // The sampling clock edge Clock_RateKHz: 30000, // The SPI clock rate in KHz ==> enough to start with, let's see how high we can take this later on SPI_mod: SPI.SPI_module.SPI1 // The used SPI bus (refers to a MOSI MISO and SCLK pinset) => default pins, also the ones used on the pwm shield // specifically: sin = 11, (netduino send, tlc in) and sclck = 13 ); // better to pass in the pins, and let the ports and pwms be managed insode the device Blank = new PWM(Pins.GPIO_PIN_D10); Gsclk = new PWM(Pins.GPIO_PIN_D6); LayerPorts=new[] { new OutputPort(Pins.GPIO_PIN_D5, false), new OutputPort(Pins.GPIO_PIN_D4, false), new OutputPort(Pins.GPIO_PIN_D3, false), new OutputPort(Pins.GPIO_PIN_D2, false), new OutputPort(Pins.GPIO_PIN_D7, false), new OutputPort(Pins.GPIO_PIN_D8, false) }; SideLength = 6; TlcChannelCount = 112; }
public static void DisplayAmmo(OutputPort ammoOut0, OutputPort ammoOut1, OutputPort ammoOut2, OutputPort ammoOut3) { switch (playerAmmo) { case 0: ammoOut0.Write(false); ammoOut1.Write(false); ammoOut2.Write(false); ammoOut3.Write(false); break; case 1: ammoOut0.Write(true); ammoOut1.Write(false); ammoOut2.Write(false); ammoOut3.Write(false); break; case 2: ammoOut0.Write(false); ammoOut1.Write(true); ammoOut2.Write(false); ammoOut3.Write(false); break; case 3: ammoOut0.Write(true); ammoOut1.Write(true); ammoOut2.Write(false); ammoOut3.Write(false); break; case 4: ammoOut0.Write(false); ammoOut1.Write(false); ammoOut2.Write(true); ammoOut3.Write(false); break; case 5: ammoOut0.Write(true); ammoOut1.Write(false); ammoOut2.Write(true); ammoOut3.Write(false); break; case 6: ammoOut0.Write(false); ammoOut1.Write(true); ammoOut2.Write(true); ammoOut3.Write(false); break; case 7: ammoOut0.Write(true); ammoOut1.Write(true); ammoOut2.Write(true); ammoOut3.Write(false); break; case 8: ammoOut0.Write(false); ammoOut1.Write(false); ammoOut2.Write(false); ammoOut3.Write(true); break; } }
public MidiDriver(Cpu.Pin resetPin, string serialPortName = Serial.COM2) { _resetPinPort = new OutputPort(resetPin, false); _serialPort = new SerialPort(serialPortName, 31250, Parity.None, 8, StopBits.One); _serialPort.Open(); }
public Motor(MotorShield shield, OutputPort port, byte bitmaskUp, byte bitmaskDown) { _shield = shield; _bitmaskUp = bitmaskUp; _bitmaskDown = bitmaskDown; _port = port; }
//private OutputPort _commitPin; public ShiftRegisterWriter(Cpu.Pin clock, Cpu.Pin reset, Cpu.Pin data, Cpu.Pin commit) { _clockPin = new OutputPort(clock, false); _dataPin = new OutputPort(data, false); _resetPin = new OutputPort(reset, false); _commitPin = new OutputPort(commit, false); }
public HandleClients(Socket clientSocket, OutputPort led) { this.clientSocket = clientSocket; this.led = led; clientIP = clientSocket.RemoteEndPoint as IPEndPoint; clientEndPoint = clientSocket.RemoteEndPoint; }
public static void Main() { // write your code here int anaIn = 250; // ADC is 12-bit Resolution //SecretLabs.NETMF.Hardware.AnalogInput pinA4 = new Microsoft.NETMF.Hardware.AnalogInput(Cpu.AnalogChannel.ANALOG_4); SecretLabs.NETMF.Hardware.AnalogInput pinA4 = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A4); OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); //PWM led2 = new PWM(Cpu.PWMChannel.PWM_0, 100, 100, 0); PWM servo = new PWM(Cpu.PWMChannel.PWM_0,20000,1500,PWM.ScaleFactor.Microseconds, false); servo.Start(); servo.DutyCycle = 0; servo.Duration = (uint)1500; while (true) { double anaRead = pinA4.Read(); anaIn = (int)anaRead; //LED stuff //led.Write(true); // turn on the LED //Thread.Sleep(anaIn); // sleep for 250ms //led.Write(false); // turn off the LED //Thread.Sleep(anaIn); // sleep for 250ms servo.Duration = (uint)((1000+anaRead)); } }
// Use IButton (interface of button) as the type of the passed button in constructor public LightTrigger(int clicks) { this.TriggerAfter = clicks; Led = new OutputPort(Pins.ONBOARD_LED, false); // In larger applications, create a class that encapsulates the hardware components. It should // configure the hardware once and behind the scenes so that the rest of the program doesn't have those details. // (E.g. set what pins are being used). Also, it makes for sense for the rest of the program to // refer to a "button" object instead of an InterruptPort object // Define a button interface, create a class for a particular button, instantiate button in main and pass it to // the constructor of the managing class (Dependency injection) // Configuration is done up top, passed into the application Button = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth); // PullUp resistor setting causes netduino to create a voltage at the pin // PullDown resistor setting is used when you supply a voltage to the pin Reset = new InterruptPort(Pins.GPIO_PIN_D13, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow); //Type typeOfOutputPort = led.GetType(); // Hold an instance of this delegate in a name so you can subscribre or unsubscribe easily and neatly // Set handler for trigger button var handlerDelegate = new NativeEventHandler(button_onInterrupt); // NativeEventHandler h = button_onInterrupt; Button.OnInterrupt += handlerDelegate; // Set handler for reset button var del = new NativeEventHandler(reset_onInterrupt); Reset.OnInterrupt += del; }
public OLED_sh1106(Cpu.Pin csPin, OutputPort dcPin, OutputPort rsPin) { displayStr = ""; spiDevice = new SPI(new SPI.Configuration(csPin, false, 0, 0, false, true, 10000, SPI.SPI_module.SPI1)); dataCommandPin = dcPin; resetOutputPort = rsPin; }
public static void Main() { OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); MorseCode mc = new MorseCode(led, 150); mc.parseMorse("Hello World"); }
public static void Main() { // Setup GoBus ports led1 = new NetduinoGo.RgbLed(GoSockets.Socket8); led2 = new NetduinoGo.RgbLed(GoSockets.Socket7); led3 = new NetduinoGo.RgbLed(GoSockets.Socket6); button1 = new NetduinoGo.Button(GoSockets.Socket1); button2 = new NetduinoGo.Button(GoSockets.Socket3); InterruptPort settingButton = new InterruptPort(Pins.Button, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow); settingButton.OnInterrupt += new NativeEventHandler(settingButton_OnInterrupt); OutputPort powerlight = new OutputPort(Pins.PowerLed, false); #if !mute buzzer = new NetduinoGo.PiezoBuzzer(); #endif // Set Scale SetScale(); // Register Buttons button1.ButtonPressed += new NetduinoGo.Button.ButtonEventHandler(button1_ButtonPressed); button2.ButtonPressed += new NetduinoGo.Button.ButtonEventHandler(button2_ButtonPressed); led2.SetColor(0, 0, 255); // Main thread sleep time Thread.Sleep(Timeout.Infinite); }
public static void Main() { //NetworkInterface.GetAllNetworkInterfaces()[0].EnableDhcp(); NetworkInterface.GetAllNetworkInterfaces()[0].EnableStaticIP("192.168.0.16","255.255.255.0","192.168.0.1"); // NetworkInterface.GetAllNetworkInterfaces()[0].RenewDhcpLease(); // var ipAddress = NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress; Thread.Sleep(1000); Debug.Print("Dirs: "); Debug.Print(Directory.GetCurrentDirectory()); Directory.SetCurrentDirectory(@"\SD"); string[] dirs = Directory.GetDirectories(@"\SD"); var webServer = new Server.WebServer {WebFolder = WebFolder, Port = 80}; webServer.Start(); var led = new OutputPort(Pins.ONBOARD_LED, false); while (true) { // Blink LED to show we're still responsive led.Write(!led.Read()); Thread.Sleep(2000); } }
public static void Main() { var led = new OutputPort(Pins.ONBOARD_LED, false); while(true) { led.Write(false); var requestUri = "http://dev3.aquepreview.com/helicoptersurface"; Debug.Print("Setup"); using (var request = (HttpWebRequest)WebRequest.Create(requestUri)) { request.Method = "GET"; Debug.Print("Requesting"); // send request and receive response using (var response = (HttpWebResponse)request.GetResponse()) { HttpStatusCode status = response.StatusCode; if (status == HttpStatusCode.OK) { var pwm = new PWM(Pins.GPIO_PIN_D5); Debug.Print("200, all ok"); pwm.SetDutyCycle(1000); led.Write(true); } } } Thread.Sleep(2000); } }
public static void Main() { // Create three colors, all LEDs off RGB first = new RGB(0, 0, 0); RGB second = new RGB(0, 0, 0); RGB third = new RGB(0, 0, 0); // Put them into an array RGB[] colors = { first, second, third }; // Use D6 for CIN and D7 for DIN (Grove Base Shield v1.2 header #6) OutputPort cin = new OutputPort(Pins.GPIO_PIN_D6, false); OutputPort din = new OutputPort(Pins.GPIO_PIN_D7, false); // Create our chainable RGB led object using the ports from above ChainableRGBLed leds = new ChainableRGBLed(cin, din); // Loop forever while (true) { // Set the colors leds.setColors(colors); // Randomize each color randomize(first); randomize(second); randomize(third); } }
public XBeeDevice(SerialPort port, Cpu.Pin resetPin, Cpu.Pin sleepPin) { _resetPort = new OutputPort(resetPin, true); _sleepPort = new OutputPort(sleepPin, false); _serialPort = port; new Thread(ReadThread).Start(); }
public void Run() { outputs[0] = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di30, false); outputs[1] = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di31, false); outputs[2] = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di32, false); outputs[3] = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di33, false); outputs[4] = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di34, false); outputs[5] = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di35, false); outputs[6] = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di36, false); outputs[7] = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di37, false); CopyToBuffer(); DisableAll(); Thread.Sleep(1000); while (true) for (int i = 0; i < 8; i++) { outputs[i].Write(true); CopyToBuffer(); DisableAll(); Thread.Sleep(100); } }
public SiliconLabsSI7005(byte deviceId = DeviceIdDefault, int clockRateKHz = ClockRateKHzDefault, int transactionTimeoutmSec = TransactionTimeoutmSecDefault) { this.deviceId = deviceId; this.clockRateKHz = clockRateKHz; this.transactionTimeoutmSec = transactionTimeoutmSec; using (OutputPort i2cPort = new OutputPort(Pins.GPIO_PIN_SDA, true)) { i2cPort.Write(false); Thread.Sleep(250); } using (I2CDevice device = new I2CDevice(new I2CDevice.Configuration(deviceId, clockRateKHz))) { byte[] writeBuffer = { RegisterIdDeviceId }; byte[] readBuffer = new byte[1]; // The first request always fails I2CDevice.I2CTransaction[] action = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(writeBuffer), I2CDevice.CreateReadTransaction(readBuffer) }; if( device.Execute(action, transactionTimeoutmSec) == 0 ) { // throw new ApplicationException("Unable to send get device id command"); } } }
private readonly byte[] _shadowBuffers; // Will store the pixel data for each display #endregion Fields #region Constructors public MatrixDisplay32x8( byte numDisplays, Cpu.Pin clkPin, Cpu.Pin dataPin, bool buildShadow ) { _backBufferSize = BACKBUFFER_SIZE; DisplayCount = numDisplays; // set data & clock pin modes _clkPin = new OutputPort( clkPin, true ); _dataPin = new OutputPort( dataPin, true ); // allocate RAM buffer for display bits // 32 columns * 8 rows / 8 bits = 32 bytes int sz = DisplayCount * _backBufferSize; _displayBuffers = new byte[sz]; if( buildShadow ) { // allocate RAM buffer for display bits _shadowBuffers = new byte[sz]; } // allocate a buffer for pin assignments _displayPins = new OutputPort[numDisplays]; }
public string handleCommand(OutputPort sol, string command) { if (command == "ON") { sol.Write(true); int uselessCounter = 0; //for (int i = 0; i < SPIN_CONSTANT; ++i) //{ // /*if (i == 35) // { // this.sol_under.Write(true); // } // else if (i == 42) // { // this.sol_under.Write(false); // }*/ // uselessCounter++; //} //Thread.Sleep(DELAY); //sol.Write(false); return "on " + uselessCounter; } else if (command == "OFF") { sol.Write(false); return "off"; } return "invalid command"; }
public static void Main() { // Instantiate the communications // port with some basic settings SerialPort port = new SerialPort( "COM1", 9600, Parity.None, 8, StopBits.One); // Open the port for communications port.Open(); OutputPort ledPort = new OutputPort(Pins.ONBOARD_LED, false); byte[] buffer = new byte[message.Length]; buffer = System.Text.Encoding.UTF8.GetBytes(message); try { while (true) { ledPort.Write(true); Thread.Sleep(200); port.Write(buffer, 0, buffer.Length); ledPort.Write(false); Thread.Sleep(5000); } } finally { port.Close(); } }
/// <summary> /// Sets up the relay board using the passed in /// pin map. If that is null, it will set up one /// based on pin0 == GPIO_PIN_D2 /// </summary> /// <param name="rawPinMap"></param> public RelayBoard(bool inverse = true, Cpu.Pin[] rawPinMap = null) { Inverse = inverse; if (null == rawPinMap) { rawPinMap = new Cpu.Pin[] { Pins.GPIO_PIN_D2, Pins.GPIO_PIN_D3, Pins.GPIO_PIN_D4, Pins.GPIO_PIN_D5, Pins.GPIO_PIN_D6, Pins.GPIO_PIN_D7, Pins.GPIO_PIN_D8, Pins.GPIO_PIN_D9 }; } MaxPin = rawPinMap.Length; // Build the outputs bool initalState = Inverse ? true : false; PinMap = new OutputPort[MaxPin]; for (int i = 0; i < MaxPin; i++) { PinMap[i] = new OutputPort(rawPinMap[i], initalState); } }
public OLED_sh1106(ref SPI globalSPIDevice, OutputPort dcPin, OutputPort rsPin) { displayStr = ""; spiDevice = globalSPIDevice; dataCommandPin = dcPin; resetOutputPort = rsPin; }
protected H.OutputPort _enablePort = null; // if enabled, then IsNeutral = false public HBridgeMotor(H.Cpu.PWMChannel a1Pin, H.Cpu.PWMChannel a2Pin, H.Cpu.Pin enablePin, float pwmFrequency = 1600) { this._pwmFrequency = pwmFrequency; // create our PWM outputs this._motorLeftPwm = new H.PWM(a1Pin, _pwmFrequency, 0, false); this._motorRighPwm = new H.PWM(a2Pin, _pwmFrequency, 0, false); this._enablePort = new H.OutputPort(enablePin, false); }
/// <summary> /// Turns the debug LED on or off. /// </summary> /// <param name="on">True if the debug LED should be on</param> public override void SetDebugLED(bool on) { if (debugLed == null) { this.debugLed = new OutputPort(Generic.GetPin('A', 14), on); } this.debugLed.Write(on); }
public NativeDigitalOutput(Socket socket, Socket.Pin pin, bool initialState, Module module, Hardware.Cpu.Pin cpuPin) { if (cpuPin == Hardware.Cpu.Pin.GPIO_NONE) { // this is a mainboard error but should not happen since we check for this, but it doesnt hurt to double-check throw Socket.InvalidSocketException.FunctionalityException(socket, "DigitalOutput"); } _port = new Hardware.OutputPort(cpuPin, initialState); }
/// <summary> /// Turns the debug LED on or off. /// </summary> /// <param name="on">True if the debug LED should be on</param> public override void SetDebugLED(bool on) { if (debugLed == null) { // if (DebugLedPin == Cpu.Pin.GPIO_NONE) return; debugLed = new OutputPort(DebugLedPin, false); } debugLed.Write(on); }
public DigitalOutputPin(Cpu.Pin pin, double initialValue = 0) { Input = AddInput("Input", Units.Digital, initialValue); port = new HWOutputPort(pin, initialValue >= HighMinValue); Input.ValueChanged += (s, e) => { port.Write(Input.Value >= HighMinValue); }; }
public static void Main() { // // Controls server // // initialize the serial port for COM1 (using D0 & D1) // initialize the serial port for COM3 (using D7 & D8) var serialPort = new SerialPort(SerialPorts.COM3, 57600, Parity.None, 8, StopBits.One); serialPort.Open(); var server = new ControlServer(serialPort); // // Just some diagnostic stuff // var uptimeVar = server.RegisterVariable("Uptime (s)", 0); var lv = false; var led = new Microsoft.SPOT.Hardware.OutputPort(Pins.ONBOARD_LED, lv); // // Make the robot // var leftMotor = HBridgeMotor.CreateForNetduino(PWMChannels.PWM_PIN_D3, Pins.GPIO_PIN_D1, Pins.GPIO_PIN_D2); var rightMotor = HBridgeMotor.CreateForNetduino(PWMChannels.PWM_PIN_D6, Pins.GPIO_PIN_D4, Pins.GPIO_PIN_D5); var robot = new TwoWheeledRobot(leftMotor, rightMotor); // // Expose some variables to control it // robot.SpeedInput.ConnectTo(server, writeable: true, name: "Speed"); robot.DirectionInput.ConnectTo(server, writeable: true, name: "Turn"); leftMotor.SpeedInput.ConnectTo(server); rightMotor.SpeedInput.ConnectTo(server); // // Show diagnostics // for (var i = 0; true; i++) { uptimeVar.Value = i; led.Write(lv); lv = !lv; Thread.Sleep(1000); } }
public Lcd2004(H.Cpu.Pin RS, H.Cpu.Pin E, H.Cpu.Pin D4, H.Cpu.Pin D5, H.Cpu.Pin D6, H.Cpu.Pin D7) { DisplayConfig = new TextDisplayConfig { Height = 4, Width = 20 }; LCD_E = new H.OutputPort(E, false); LCD_RS = new H.OutputPort(RS, false); LCD_D4 = new H.OutputPort(D4, false); LCD_D5 = new H.OutputPort(D5, false); LCD_D6 = new H.OutputPort(D6, false); LCD_D7 = new H.OutputPort(D7, false); Initialize(); }
public static void Main2() { // configure an output port for us to "write" to the LED var led = new Microsoft.SPOT.Hardware.OutputPort(Pins.ONBOARD_LED, false); int i = 0; while (true) { led.Write(true); // turn on the LED Thread.Sleep(250); // sleep for 250ms led.Write(false); // turn off the LED Thread.Sleep(250); // sleep for 250ms Debug.Print("Looping" + i); i++; } }
public static void Run() { // initialize the serial port for COM1 (using D0 & D1) // initialize the serial port for COM3 (using D7 & D8) var serialPort = new SerialPort(SerialPorts.COM3, 57600, Parity.None, 8, StopBits.One); serialPort.Open(); var server = new ControlServer(serialPort); var led = new Microsoft.SPOT.Hardware.OutputPort(Pins.ONBOARD_LED, false); var lv = false; var a0 = new AnalogInput(AnalogChannels.ANALOG_PIN_A0, -1); var a1 = new AnalogInput(AnalogChannels.ANALOG_PIN_A1, -1); var uptimeVar = server.RegisterVariable("Uptime (s)", 0); server.RegisterVariable("Speed", 0, v => { }); server.RegisterVariable("Turn", 0, v => { }); var a0Var = server.RegisterVariable("Analog 0", 0); var a1Var = server.RegisterVariable("Analog 1", 0); var magicCmd = server.RegisterCommand("Magic", () => { Debug.Print("MAAAGIIICC"); return(42); }); for (var i = 0; true; i++) { uptimeVar.Value = i; a0Var.Value = a0.Read(); a1Var.Value = a1.Read(); led.Write(lv); lv = !lv; Thread.Sleep(1000); } }
public SoftPwm(H.Cpu.Pin outputPin, float dutyCycle = 0.5f, float frequency = 1.0f) { OutputPort = new H.OutputPort(outputPin, false); DutyCycle = dutyCycle; Frequency = frequency; }
/// <summary> /// Creates a new DigitalOutputPort from a pin. /// </summary> /// <param name="pin"></param> /// <param name="initialState"></param> public DigitalOutputPort(H.Cpu.Pin pin, bool initialState = false) : base(initialState) { this._digitalOutPort = new H.OutputPort(pin, initialState); }
public HumiditySensorController(MSH.Cpu.Pin analogPort, MSH.Cpu.Pin digitalPort) { _analogPort = new SLH.AnalogInput(analogPort); _digitalPort = new MSH.OutputPort(digitalPort, false); }
//static bool roverHeadLights = false; //static bool roverTakePicture = false; public static void Main() { #region Newhaven 3.5" Display Graphic Setup /* * var lcdConfig3 = new Configuration.LCD.Configurations(); * * lcdConfig3.Width = 320; * lcdConfig3.Height = 240; * * lcdConfig3.OutputEnableIsFixed = true; * lcdConfig3.OutputEnablePolarity = true; * * lcdConfig3.HorizontalSyncPolarity = false; * lcdConfig3.VerticalSyncPolarity = false; * lcdConfig3.PixelPolarity = true; * * lcdConfig3.HorizontalSyncPulseWidth = 68; * lcdConfig3.HorizontalBackPorch = 2; * lcdConfig3.HorizontalFrontPorch = 18; * lcdConfig3.VerticalSyncPulseWidth = 10; * lcdConfig3.VerticalBackPorch = 3; * lcdConfig3.VerticalFrontPorch = 10; * * lcdConfig3.PixelClockRateKHz = 6400; * * Configuration.LCD.Set(lcdConfig3); * */ //if (Configuration.LCD.Set(lcdConfig3)) PowerState.RebootDevice(false); //Initialiazing and hooking to events var display = new DisplayNhd5(new Microsoft.SPOT.Hardware.I2CDevice(new Microsoft.SPOT.Hardware.I2CDevice.Configuration(0x38, 400))); //display.TouchUp += (sender, e) => Debug.Print("Finger " + e.FingerNumber + " up!"); display.TouchUp += new TouchEventHandler(display_TouchUp); //display.TouchDown += (sender, e) => Debug.Print("Finger " + e.FingerNumber + " down!"); display.TouchDown += new TouchEventHandler(display_TouchDown); display.ZoomIn += (sender, e) => Debug.Print("Zoom in"); display.ZoomOut += (sender, e) => Debug.Print("Zoom out"); /* * //Method one: polling manually. Uncomment the while cycle to use it. * * //while (true) { * // display.ReadAndProcessTouchData(); * // Thread.Sleep(50); * //} */ //Method two: using interrupt (for G120). var touchPin = new Microsoft.SPOT.Hardware.InterruptPort(GHI.Hardware.G120.Pin.P0_25, false, Microsoft.SPOT.Hardware.Port.ResistorMode.PullUp, Microsoft.SPOT.Hardware.Port.InterruptMode.InterruptEdgeLow); var wakePin = new Microsoft.SPOT.Hardware.InputPort(GHI.Hardware.G120.Pin.P0_24, false, Microsoft.SPOT.Hardware.Port.ResistorMode.Disabled); //var touchPin = new Microsoft.SPOT.Hardware.InterruptPort(GHI.Hardware.G120.Pin.P0_23, false, Microsoft.SPOT.Hardware.Port.ResistorMode.PullUp, Microsoft.SPOT.Hardware.Port.InterruptMode.InterruptEdgeLow); //I DID THIS touchPin.OnInterrupt += (data1, data2, time) => display.ReadAndProcessTouchData(); #endregion #region LAIRD XCVR SETUP //lairdWirelss.Configure(9600, GT.Interfaces.Serial.SerialParity.None, GT.Interfaces.Serial.SerialStopBits.One, 7); lairdComPort = new SerialPort("COM2", 115200); //TX2 = P2.0, RX2 = P0.16 //lairdComPort = new SerialPort("COM2", 9600); lairdComPort.Open(); lairdReset = new Microsoft.SPOT.Hardware.OutputPort(lairdResetPin, true); lairdCts = new Microsoft.SPOT.Hardware.OutputPort(lairdCtsPin, false); //lairdRts = new Microsoft.SPOT.Hardware.InputPort(lairdRtsPin, false, Microsoft.SPOT.Hardware.Port.ResistorMode.PullUp); lairdRange = new Microsoft.SPOT.Hardware.InputPort(lairdRangePin, false, Microsoft.SPOT.Hardware.Port.ResistorMode.Disabled); /* * lairdCtsPin = GT.Socket.GetSocket(5, true, null, null).CpuPins[6]; * //lairdRtsPin = GT.Socket.GetSocket(5, true, null, null).CpuPins[7]; * lairdResetPin = GT.Socket.GetSocket(5, true, null, null).CpuPins[3]; * lairdRangePin = GT.Socket.GetSocket(5, true, null, null).CpuPins[8]; */ lairdWirelessBuffer = new SerialBuffer(72); #endregion #region QUAD POWER SETUP quadPowerComPort = new SerialPort("COM3", 9600); quadPowerComPort.Open(); quadPowerBuffer = new SerialBuffer(36); #endregion // Load the window _mainWindow = GlideLoader.LoadWindow(OakhillLandroverController.Resources.GetString(OakhillLandroverController.Resources.StringResources.wndMain)); //pictureWindow = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.Picture_Window)); outputsWindow = new OutputsWindow();//gndEfxWindow = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.GroundEfx_Window)); ecoCamWindow = new EcoCamWindow(); setupWindow = new SetupWindow(); // Activate touch //GlideTouch.Initialize(); // Initialize the windows. initMainWindow(_mainWindow); // Assigning a window to MainWindow flushes it to the screen. // This also starts event handling on the window. Glide.MainWindow = _mainWindow; //bool mybool = SDCard.sdCardDetect; //bool yourBool = batChargeState.Read(); //lcdBacklight.Write(false); //turn lcd screen off //onBoardLed.Write(true); picCounter = -1; //Glide.MessageBoxManager.Show("SD Card not found.", "SD Card"); UpdateMainWindowTimer = new Timer(new TimerCallback(UpdateMainWindowTimer_Tick), null, 0, UpdateMainWindowTimerPeriod); PictureViewerTimer = new Timer(new TimerCallback(PictureViewerTimer_Tick), null, -1, PictureViewerTimerPeriod); RoverJoystickControlTimer = new Timer(new TimerCallback(RoverJoystickControlTimer_Tick), null, 0, RoverJoystickTimerPeriod); //display_T35.SimpleGraphics.DisplayImage(SD_ROOT_DIRECTORY + @"\roverPic17.jpg", Bitmap.BitmapImageType.Jpeg, 0, 0); Thread.Sleep(-1); }
/// <summary> /// Creates a DigitalOutputPort from an existing SPOT.Hardware.OutputPort /// </summary> /// <param name="port"></param> /// <param name="initialState"></param> public DigitalOutputPort(H.OutputPort port, bool initialState = false) : base(initialState) { this._digitalOutPort = port; }