第1步:需要什么
硬件
LattePanda/Arduino UNO
軟件
Viusal Studio
Arduino IDE
步驟2:C#代碼
創(chuàng)建一個新的Windows Form項目。在左側的工具箱中,從工具箱中拖出2個按鈕組件。重命名它們,一個為“ ON”,一個為“ OFF”。
public partial class Form1 : Form
{
SerialPort port;
public Form1()
{
InitializeComponent();
this.FormClosed += new FormClosedEventHandler(Form1_FormClosed);
if (port == null)
{
//Change the portname according to your computer
port = new SerialPort(“COM4”, 9600);
port.Open();
}
}
void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
if (port != null && port.IsOpen)
{
port.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
PortWrite(“1”);
}
private void button2_Click(object sender, EventArgs e)
{
PortWrite(“0”);
}
private void PortWrite(string message)
{
if (port != null && port.IsOpen)
{
port.Write(message);
}
}
}
第3步:Arduino Sketch
打開Arduino IDE,將以下代碼上傳到您的電路板上。
const int LedPin = 3;int ledState = 0;
void setup()
{
pinMode(LedPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
char receiveVal;
if(Serial.available() 》 0)
{
receiveVal = Serial.read();
if(receiveVal == ‘1’)
ledState = 1;
else
ledState = 0;
}
digitalWrite(LedPin, ledState);
delay(50);
}
步驟4:Showtime
當您單擊“打開”時‘按鈕,LED燈將點亮。
到目前為止還好嗎?
如果您用其他東西代替LED,那么您可以使用鼠標來控制一切!這是一個非常有用的功能。
-
GUI
+關注
關注
3文章
665瀏覽量
40050 -
Arduino
+關注
關注
188文章
6478瀏覽量
188396
發(fā)布評論請先 登錄
相關推薦
DLP4710EVM無法通過GUI控制怎么解決?
DLPLCR4500GUI-4.4.1的GUI可以在win10使用嗎?
DLPC3479 GUI上面的Edit Firmware制作中有幾個疑問求解
dlp4500無法通過gui控制怎么解決?
HAL庫在Arduino平臺上的使用
開源項目!基于 Arduino 的 MIDI 架子鼓
七大嵌入式GUI盤點
伺服電機最簡單控制方法是什么
能否通過arduino訪問TLE9879的速度/電流測量值?
STM32CubeMx使用GUI_DrawGradientH GUI_DrawGradientV繪制一直顯示黑色,是哪里出錯?
分享幾個嵌入式中常用的GUI

GUI Guider新版本發(fā)布,嵌入式GUI開發(fā)體驗升級

評論