第1步:需要什么
硬件
LattePanda/Arduino UNO
軟件
Viusal Studio
Arduino IDE
步驟2:C#代碼
創建一個新的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文章
663瀏覽量
39931 -
Arduino
+關注
關注
188文章
6477瀏覽量
188052
發布評論請先 登錄
相關推薦
如何使用Arduino實現CAN總線通信呢
HAL庫在Arduino平臺上的使用
開源項目!基于 Arduino 的 MIDI 架子鼓
stm32與Arduino的比較
七大嵌入式GUI盤點
開源項目!基于 Arduino DIY 漂亮的宏機械鍵盤
伺服電機最簡單控制方法是什么
能否通過arduino訪問TLE9879的速度/電流測量值?
STM32CubeMx使用GUI_DrawGradientH GUI_DrawGradientV繪制一直顯示黑色,是哪里出錯?
分享幾個嵌入式中常用的GUI
![分享幾個嵌入式中常用的<b class='flag-5'>GUI</b>](https://file.elecfans.com/web2/M00/20/B3/pYYBAGGfNNmAK-PZAAJsGM5Cgk0227.jpg)
GUI Guider新版本發布,嵌入式GUI開發體驗升級
![<b class='flag-5'>GUI</b> Guider新版本發布,嵌入式<b class='flag-5'>GUI</b>開發體驗升級](https://file1.elecfans.com/web2/M00/C6/2B/wKgZomYGHkiAERxAAAA3D_d3PLo909.png)
如何用Arduino制作一個簡易自動喂魚器
如何制作自己的Arduino電容計
![如何<b class='flag-5'>制作</b>自己的<b class='flag-5'>Arduino</b>電容計](https://file1.elecfans.com/web2/M00/C1/D8/wKgaomXa53-AADvOAAAB6DIT4HM693.jpg)
評論