第1步:需要什么
硬件
LattePanda/Arduino UNO
軟件
Viusal Studio
Arduino IDE
步驟2:C#代碼
創(chuàng)建一個新的Windows Form項目。在左側(cè)的工具箱中,從工具箱中拖出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
當(dāng)您單擊“打開”時‘按鈕,LED燈將點亮。
到目前為止還好嗎?
如果您用其他東西代替LED,那么您可以使用鼠標(biāo)來控制一切!這是一個非常有用的功能。
-
GUI
+關(guān)注
關(guān)注
3文章
679瀏覽量
41240 -
Arduino
+關(guān)注
關(guān)注
190文章
6498瀏覽量
192182
發(fā)布評論請先 登錄
GUI Guider全新優(yōu)化方案GUI xTurbo-VeloRender初體驗:基于i.MX RT平臺的LVGL渲染能力突破

【PCA9958HN-ARD】GUI工具的使用
免費分享Arduino入門+進階(全套例程+書籍)

《ESP32S3 Arduino開發(fā)指南》第二章 Arduino基礎(chǔ)知識
樹莓派GUI應(yīng)用開發(fā):從零到炫酷的魔法之旅!

使用GUI GUIDER(1.9.0 或 1.8.1)創(chuàng)建項目時報錯的原因?
DLP4710EVM無法通過GUI控制怎么解決?
京準(zhǔn)電鐘:NTP網(wǎng)絡(luò)時間服務(wù)器如何設(shè)置?教您簡單兩步法

DLPLCR4500GUI-4.4.1的GUI可以在win10使用嗎?
DLPC3479 GUI上面的Edit Firmware制作中有幾個疑問求解
dlp4500無法通過gui控制怎么解決?
HAL庫在Arduino平臺上的使用
開源項目!基于 Arduino 的 MIDI 架子鼓
Scalable PMICs GUI用戶指南

評論