本文整理汇总了C#中Microsoft.SPOT.Hardware.OutputPort.Write方法的典型用法代码示例。如果您正苦于以下问题:C# OutputPort.Write方法的具体用法?C# OutputPort.Write怎么用?C# OutputPort.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.SPOT.Hardware.OutputPort
的用法示例。
在下文中一共展示了OutputPort.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
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);
}
示例2: Main
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);
}
}
示例3: Main
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);
// }
}
示例4: Main
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);
}
}
示例5: Main
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");
}
示例6: Main
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();
}
}
示例7: Main
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);
}
}
示例8: Main
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
}
*/
}
示例9: Main
//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;
}
}
示例10: Test
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();
}
}
}
示例11: Main
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
}
}
示例12: Main
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);
}
}
示例13: Main
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);
}
}
示例14: Main
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
}
}
示例15: StartUp
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);
}
}
}
}
}