public static void Main() { OutputPort o = new OutputPort(Pins.ONBOARD_LED, true); while (true) { Thread.Sleep(1000); o.Write(true); Thread.Sleep(1000); o.Write(false); } // write your code here // I2CDevice i2c = new I2CDevice(new I2CDevice.Configuration(0x38,100)); // Microsoft.SPOT.Hardware.I2CDevice.I2CTransaction[] actions; // var buffer = new byte[1]; // actions = new I2CDevice.I2CTransaction[] // { // I2CDevice.CreateWriteTransaction(buffer) // }; // while (true) // { // buffer[0] = 255; // i2c.Execute(actions, 1000); // Thread.Sleep(1000); // buffer[0] = 0; // i2c.Execute(actions, 1000); // Thread.Sleep(1000); // } }
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(); } }
public static void Main() { // Specify the GPIO pin we want to use as an interrupt // source, specify the edges the interrupt should trigger on //InterruptPort button = new InterruptPort(Pins.V2_GPIO2, false, // Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth); // Hook up an event handler (delegate) to the OnInterrupt event //button.OnInterrupt += new NativeEventHandler(button_OnInterrupt); Debug.Print("Started"); //Thread.Sleep(-1); //Debug.Print("Interruption"); OutputPort bar = new OutputPort(Pins.V2_GPIO17, false); bar.Write(false); bool foo = false; OutputPort o = new OutputPort(Pins.V2_GPIO11, false); bar.Write(true); for (int i = 0; i < 10000; i++) { //Console.WriteLine(i); foo = !foo; o.Write(foo); } bar.Write(false); Debug.Print("END"); }
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); } }
static void Main() { // ... check if SD is inserted // SD Card is inserted // Create a new storage device PersistentStorage sdPS = new PersistentStorage("SD"); // Mount the file system sdPS.MountFileSystem(); // Assume one storage device is available, // access it through NETMF string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory; FileStream FileHandle = new FileStream(rootDirectory + @"\hello1.txt", FileMode.Create); byte[] data = Encoding.UTF8.GetBytes("This string will go in the file!"); // Toggle LED on SD Write OutputPort LED; LED = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, true); LED.Write(true); // write the data and close the file FileHandle.Write(data, 0, data.Length); FileHandle.Close(); // Turn off led LED.Write(false); // if we need to unmount sdPS.UnmountFileSystem(); // ... Thread.Sleep(100); }
public static void Main() { // write your code here //PWM led1 = new PWM(PWMChannels.PWM_PIN_D3, 500, .5, false); //led1.Start(); //led1.DutyCycle = .05; OutputPort led = new OutputPort(Pins.GPIO_PIN_D13, false); //A while-loop will make our code loop indefinitely while (true) { led.Write(false); Thread.Sleep(1000); led.Write(true); Thread.Sleep(1000); } /* OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); 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 } */ }
public static void Main() { // create an analog input for our photo resistor // we will use analog pin 0 on our Netduino // note: place a 10k ohm resistor between the photo resistor and ground. AnalogInput photo = new AnalogInput(SecretLabs.NETMF.Hardware.Netduino.AnalogChannels.ANALOG_PIN_A0); // create a new outpot port for our LED and write to digital port 13 OutputPort led = new OutputPort(Pins.GPIO_PIN_D13, false); while (true) { // create a new var for our photo resistor data // multiply * 100 for a value that's easier to work with double photoSense = photo.Read() * 100; // if our values are over 1, then it's dark and we... if (photoSense > 0.5) { // turn on the LED led.Write(true); } else { // otherwise, turn off the LED led.Write(false); } // sleep every 10 ms for faster light response Thread.Sleep(10); } }
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); } }
//click, led will flash twice. click to enter a number n, wait and led will flash n times public static void Main() { OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); InputPort btn = new InputPort(Pins.ONBOARD_BTN, false, Port.ResistorMode.Disabled); bool currentState = false; bool lastState = false; int flashes = 0; bool ledOn = false; int clicks = -1; Stopwatch timer = Stopwatch.StartNew(); ; while (true) { timer.Stop(); //if user has already introduced number if(timer.ElapsedMilliseconds > 3000) { timer.Reset(); while(clicks > 0) { clicks--; led.Write(true); Thread.Sleep(500); led.Write(false); Thread.Sleep(500); } } timer.Start(); currentState = btn.Read(); //if button is pressed if (currentState && !lastState) { clicks++; //flash led twice to start while(flashes < 4) { led.Write(!ledOn); Thread.Sleep(500); ledOn = !ledOn; flashes++; } if(clicks > 0) { timer.Stop(); timer.Reset(); timer.Start(); } } lastState = currentState; } }
public static void Test() { // Create new Thread that runs the ExampleThreadFunction Thread ExampleThread = new Thread(new ThreadStart(ExampleThreadFunction)); // SD stuff is in PersistentStorage sdPS = new PersistentStorage("SD"); // Led stuff is in OutputPort LED; LED = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, true); // Button stuff in InputPort Button; Button = new InputPort((Cpu.Pin)FEZ_Pin.Digital.LDR, false, Port.ResistorMode.PullUp); while (true) { //Led status at the beginning is off LED.Write(false); if (Button.Read()) { while (Button.Read()) ; // wait while busy //Led is on LED.Write(true); // Mount sdPS.MountFileSystem(); // Start our new Thread ExampleThread.Start(); while (Button.Read()) ; // wait while busy //Led is off LED.Write(true); // Abort our new Thread ExampleThread.Abort(); // Unmount sdPS.UnmountFileSystem(); } } }
float ReadRaw() { int humidityRaw = 0; _digitalPort.Write(true); Thread.Sleep(5); humidityRaw = _analogPort.Read(); _digitalPort.Write(false); return(humidityRaw); }
public static void Main() { // write your code here var led = new OutputPort(Pins.ONBOARD_LED, false); while (true) { led.Write(true); // turn on the led Thread.Sleep(250); // sleep for 250 ms led.Write(false); // turn off the led Thread.Sleep(250); // sleep for 250 ms } }
public static void Main() { // write your code here OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); while (true) { led.Write(true); Thread.Sleep(259); led.Write(false); Thread.Sleep(259); } }
public float Read() { int sample; float humidity; _digitalPort.Write(true); Thread.Sleep(5); sample = _analogPort.Read(); _digitalPort.Write(false); humidity = 100 - Map(sample, 250, 1023, 0, 100); return(humidity); }
public static void Main() { var ledPort = new OutputPort(Pins.ONBOARD_LED, false); while (true) { ledPort.Write(true); Thread.Sleep(500); ledPort.Write(false); Thread.Sleep(500); } }
static void Main() { var ledPort = new OutputPort(Parameters.LedPin, false); while (true) { ledPort.Write(true); // turn on LED Thread.Sleep(500); // wait 500 ms ledPort.Write(false); // turn off LED Thread.Sleep(500); // wait 500 ms } }
private static void StartUp() { var led = new OutputPort(Pins.ONBOARD_LED, false); var led1 = new OutputPort(Pins.GPIO_PIN_D0, false); var led2 = new OutputPort(Pins.GPIO_PIN_D1, false); using (System.Net.Sockets.Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { socket.Bind(new IPEndPoint(IPAddress.Any, 8080)); socket.Listen(1); while (true) { using (Socket newSocket = socket.Accept()) { if (newSocket.Poll(-1, SelectMode.SelectRead)) { byte[] bytes = new byte[newSocket.Available]; int count = newSocket.Receive(bytes); char[] chars = Encoding.UTF8.GetChars(bytes); string str = new string(chars, 0, count); if (str == "test1") { led1.Write(true); Thread.Sleep(250); led1.Write(false); } else if (str == "test2") { led2.Write(true); Thread.Sleep(250); led2.Write(false); } else { led1.Write(true); led2.Write(true); Thread.Sleep(250); led1.Write(false); led2.Write(false); } Debug.Print(str); } } } } }
public static void Main() { OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); OutputPort red = new OutputPort(Pins.GPIO_PIN_D11, false); while (true) { led.Write(true); // turn on the LED red.Write(true); Thread.Sleep(250); // sleep for 250ms led.Write(false); // turn off the LED red.Write(false); Thread.Sleep(250); // sleep for 250ms } }
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 static void Main() { OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); OutputPort shieldLed = new OutputPort(Pins.GPIO_PIN_D13, true); while (false) { led.Write(true); shieldLed.Write(false); Thread.Sleep(250); led.Write(false); shieldLed.Write(true); Thread.Sleep(250); } }
public static void Main() { // write your code here OutputPort led01 = new OutputPort(Pins.GPIO_PIN_D0, false); while (true) { Thread.Sleep(250); led01.Write(true); Thread.Sleep(250); led01.Write(false); } }
public static void Main() { OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); SetUpTrigger(); SetUpServo(); while (true) { led.Write(true); Thread.Sleep(250); led.Write(false); Thread.Sleep(250); } }
public Humidity Read() { int sample; float humidity; _digitalPort.Write(true); Thread.Sleep(20); sample = _analogPort.Read(); _digitalPort.Write(false); humidity = 100 - Map(sample, 250, 1023, 0, 100); return(new Humidity { raw = sample, mapped = humidity }); }
public static void Main() { // We use the LED to understand if the shield is properly connected to Netduino and valid average samples are counted OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); // This is the main WeatherShield object WeatherShield1 wShield1 = new WeatherShield1(Pins.GPIO_PIN_D7, Pins.GPIO_PIN_D2, WeatherShield1.DEFAULTADDRESS); // Wait until valid samples are ready on the shield while (!wShield1.averageValuesReady()) { led.Write(true); Thread.Sleep(1000); led.Write(false); Thread.Sleep(1000); } // Then start sending data to Console while (true) { // Read values from the shield float temperature = wShield1.readAveragedValue(WeatherShield1.units.TEMPERATURE); float pressure = wShield1.readAveragedValue(WeatherShield1.units.PRESSURE); float humidity = wShield1.readAveragedValue(WeatherShield1.units.HUMIDITY); if ((temperature != float.MinValue) && (pressure != float.MinValue) && (humidity != float.MinValue)) { // Connection performed OK. led.Write(true); Debug.Print("Temperature: " + temperature.ToString() + "\n"); Debug.Print("Pressure: " + pressure.ToString() + "\n"); Debug.Print("Humidity: " + humidity.ToString() + "\n"); } else { // Something went wrong led.Write(false); // Try to resync the WeatherShield connection wShield1.resetConnection(); } // Wait for 30 seconds Thread.Sleep(30000); } }
public static void Main() { // write your code here OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); int port = 80; // Wait 5 seconds for DHCP to assign an address Thread.Sleep(5000); Microsoft.SPOT.Net.NetworkInformation.NetworkInterface networkInterface = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0]; Debug.Print("My IP Address is: " + networkInterface.IPAddress.ToString()); Socket listenerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, port); listenerSocket.Bind(endpoint); listenerSocket.Listen(1); while (true) { Socket clientSocket = listenerSocket.Accept(); bool dataReady = clientSocket.Poll(5000, SelectMode.SelectRead); if (dataReady && clientSocket.Available > 0) { byte[] buffer = new byte[clientSocket.Available]; int bytesRead = clientSocket.Receive(buffer); string request = new string(System.Text.Encoding.UTF8.GetChars(buffer)); if (request.IndexOf("ON") >= 0) led.Write(true); else led.Write(false); string statusText = "LED is " + (led.Read() ? "ON" : "OFF") + "."; string response = "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html; charset=utf-8\r\n\r\n" + "<html><head><title>Netduino Networking Example</title></head>" + "<body>" + statusText + "</body></html>"; clientSocket.Send(System.Text.Encoding.UTF8.GetBytes(response)); clientSocket.Close(); } } }
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() { // create a new outpot port and write to the onboard LED // we must define a port ID, and it's initial state (false == off); OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); // create a loop for the program to run in... while (true) { // blink every 1 second led.Write(true); // turns the LED on Thread.Sleep(1000); // waits 1 second led.Write(false); // turns the LED off Thread.Sleep(1000); // waits 1 second } }
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"); } } }
public static void Main() { // write your code here OutputPort led = new OutputPort(Pins.GPIO_PIN_D0, false); InputPort button = new InputPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.PullUp); OutputPort ledLight = new OutputPort(Pins.GPIO_PIN_D2, false); InputPort buttonLight = new InputPort(Pins.GPIO_PIN_D3, false, Port.ResistorMode.PullUp); AnalogInput pot = new AnalogInput(Pins.GPIO_PIN_A0); bool buttonState = false; bool isDark = false; int potValue = 0; while (true) { buttonState = !button.Read(); isDark = buttonLight.Read() || buttonState; ledLight.Write(isDark); led.Write(buttonState); if (buttonState) { //while (buttonState) //{ // potValue = pot.Read(); // led.Write(true); // Thread.Sleep(potValue*10); // led.Write(false); // Thread.Sleep(potValue*10); // buttonState = !button.Read(); //} } } }
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() { // Initialize Outputs OutputPort ledBuiltIn = new OutputPort(Pins.ONBOARD_LED, false); OutputPort ledGreen = new OutputPort(Pins.GPIO_PIN_D11, true); // Initialize Inputs InputPort button = new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled); // Declare variables bool buttonState = false; int buttonPress = 0; // Loop until button has been pressed 5 times while (buttonPress < 6) { // Read the button bool // TRUE when open, FALSE when closed buttonState = button.Read(); // Turn on blue light when button open ledBuiltIn.Write(buttonState); // Turn green light on when button closed ledGreen.Write(!buttonState); } }
public static void Main() { mainThread = Thread.CurrentThread; activityLED = new OutputPort(Pins.ONBOARD_LED, false); if (enableLogging) { int i = 0; while (File.Exists(csvPath + i + ".csv")) i++; csvPath += i + ".csv"; writer = new FileStream(csvPath, FileMode.Append); buffer = Encoding.UTF8.GetBytes("A X,A Y,A Z,M X,M Y,M Z,G X,G Y,G Z,,Yaw,Pitch,Roll \n"); writer.Write(buffer, 0, buffer.Length); } //ComplexNumTests(); //VectorTests(); //MatrixTests(); InitializeACDC(); mainThread.Priority = ThreadPriority.BelowNormal; // Loop forever to keep the code running // flashing the on board led to let us know code hasn't crashed while (true) { activityLED.Write(!activityLED.Read() && enableLogging); Thread.Sleep(10); } }
static void button_OnInterrupt(uint port, uint state, DateTime time) { // This method is called whenever an interrupt OutputPort bar = new OutputPort(Pins.V2_GPIO17, false); bar.Write(false); bool foo = false; OutputPort o = new OutputPort(Pins.V2_GPIO11, false); bar.Write(true); for (int i = 0; i < 200; i++) { foo = !foo; o.Write(foo); } bar.Write(false); }
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 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++; } }
/// <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); }
private void SendByte(byte value, bool mode) { LCD_RS.Write(mode); // high bits LCD_D4.Write((value & 0x10) == 0x10); LCD_D5.Write((value & 0x20) == 0x20); LCD_D6.Write((value & 0x40) == 0x40); LCD_D7.Write((value & 0x80) == 0x80); ToggleEnable(); // low bits LCD_D4.Write((value & 0x01) == 0x01); LCD_D5.Write((value & 0x02) == 0x02); LCD_D6.Write((value & 0x04) == 0x04); LCD_D7.Write((value & 0x08) == 0x08); ToggleEnable(); }
/// <summary> /// Drive rover. /// </summary> static void RoverJoystickControlTimer_Tick(object temp) { switch (DRIVE_MODE_ROVER) { case DRIVE_MODE.MANUAL: //get check box accessories //Array.Copy(byteToHex(getChkBoxAccessories()), 0, ps2Data, 4, 2); Array.Copy(byteToHex((byte)(convertLinearScale(steeringWheelAnalog.ReadRaw(), steeringWheelMin, steeringWheelMax, 0, 255))), 0, manualCmdOutput, 5, 2); Array.Copy(byteToHex(triggerSpeedCmd()), 0, manualCmdOutput, 8, 2); //get checksum Array.Copy(byteToHex(getChecksum(Encoding.UTF8.GetBytes(new string(manualCmdOutput)))), 0, manualCmdOutput, 14, 2); lairdComPort.Write(Encoding.UTF8.GetBytes(new string(manualCmdOutput)), 0, manualCmdOutput.Length); //Debug.Print(new string(manualCmdOutput)); break; case DRIVE_MODE.AUTO: //Array.Copy(byteToHex((byte)DRIVE_MODE_ROVER), 0, autoCmdOutput, 5, 2); //get checksum Array.Copy(byteToHex(getChecksum(Encoding.UTF8.GetBytes(new string(autoCmdOutput)))), 0, autoCmdOutput, 8, 2); lairdComPort.Write(Encoding.UTF8.GetBytes(new string(autoCmdOutput)), 0, autoCmdOutput.Length); //Debug.Print(new string(autoCmdOutput)); break; case DRIVE_MODE.COMPASS: //get checksum Array.Copy(byteToHex(getChecksum(Encoding.UTF8.GetBytes(new string(compassCmdOutput)))), 0, compassCmdOutput, 8, 2); lairdComPort.Write(Encoding.UTF8.GetBytes(new string(compassCmdOutput)), 0, compassCmdOutput.Length); //'$','O','C','C',',' // ,'0','0', //bytes 5,6 get byte 1 // ,'*' // ,'0','0' // ,0x0D,0x0A}; break; } SYSTEM_LED = !SYSTEM_LED; onBoardLed.Write(SYSTEM_LED); }
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 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 override void Write(bool state) { _port.Write(state); }
/// <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) { debugled.Write(on); }
private void ToggleEnable() { LCD_E.Write(true); LCD_E.Write(false); }