public static void Main()
{
OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
while (true)
{
led.Write(true);
Thread.Sleep(250);
led.Write(false);
Thread.Sleep(250);
}
}
public static void Main()
{
OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
InputPort button = new InputPort(Pins.ONBOARD_BTN, false, Port.ResistorMode.Disabled);
bool buttonState = false;
while (true)
{
buttonState = button.Read();
led.Write(buttonState);
}
}
I am not sure if I understand your problem correctly, but I want to point out:Possibly the most basic question, if I may .............................
I am playing with a sample code that toggles an LED from a web page by typing <ipaddress./ON or <ipaddress>/OFF
The code is
if (request.IndexOf("ON") >= 0)
{
led.Write(true):
}
else if request bla-bla turn it off again
I realise that an 'if' statement has to be followed by an 'else if'.... but what if I want to send more than just on & off. I want to be able to send
light led 1 & light led2 etc.
I know how to set up more output ports ...but what can I replace the 'if' statement with?
I apologize in advance for being very new to this
This explains it perfectly. I would like to make duplicate 'if' statements. I wrongly assumed I had to use 'else' as I keep seeing examples that only have two functions.- if statement can be by itself
- if statement can be followed by else, the if else combo.
.
Thanks for this help.This is how to post code.
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
namespace Blinky
{
public class testSecond {
public static void Main()
{
// write your code here
OutputPort led1 = new OutputPort(Pins.GPIO_PIN_D1, false);
OutputPort led2 = new OutputPort(Pins.GPIO_PIN_D2, false);
int port = 80;
Thread.Sleep(50000);
var interf = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0];
interf.EnableStaticIP("192.168.0.125", "255.255.255.0", "192.168.0.1");
interf.EnableStaticDns(new string[] { "192.168.0.1", "192.168.0.1" });
Socket listenerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint listenerEndPoint = new IPEndPoint(IPAddress.Any, port);
listenerSocket.Bind(listenerEndPoint);
listenerSocket.Listen(1);
while (true)
{
Socket clientSocket = listenerSocket.Accept();
bool dataReady = clientSocket.Poll(5000000, 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("SWAP") >= 0)
{
led1.Write(true);
led2.Write(false);
Thread.Sleep(250);
led1.Write(false);
led2.Write(true);
Thread.Sleep(250);
}
if (request.IndexOf("OFF") >= 0)
{
led1.Write(false);
led2.Write(false);
}
string statusText = "STATE IS " + (led1.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>Setscore</title></head>" +
"<body>" + statusText + "</body></html>";
clientSocket.Send(System.Text.Encoding.UTF8.GetBytes(response));
}
clientSocket.Close();
}
}
}
}
by Aaron Carman
by Aaron Carman
by Aaron Carman