第1步:需要什么
硬件
LattePanda/Arduino UNO
軟件
Viusal Studio
Arduino IDE
步驟2:C#代碼
創(chuàng)建一個(gè)新的Windows Form項(xiàng)目。在左側(cè)的工具箱中,從工具箱中拖出2個(gè)按鈕組件。重命名它們,一個(gè)為“ ON”,一個(gè)為“ 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)您單擊“打開”時(shí)‘按鈕,LED燈將點(diǎn)亮。
到目前為止還好嗎?
如果您用其他東西代替LED,那么您可以使用鼠標(biāo)來控制一切!這是一個(gè)非常有用的功能。
-
GUI
+關(guān)注
關(guān)注
3文章
697瀏覽量
43509 -
Arduino
+關(guān)注
關(guān)注
190文章
6526瀏覽量
197035
發(fā)布評(píng)論請(qǐng)先 登錄
探索用于Arduino的TLE94112ES直流電機(jī)控制盾牌
恩智浦GUI Guider 1.10.0正式上線
使用恩智浦FRDM-MCXN947開發(fā)板GUI控制電機(jī)
如何在 NuMaker-IoT-M467 板上使用 Arduino IDE 控制 Wi-Fi 模塊?
【Milk-V Duo S 開發(fā)板免費(fèi)體驗(yàn)】Milk-V DuoS之使用Arduino開發(fā)小核
GUI Guider全新優(yōu)化方案GUI xTurbo-VeloRender初體驗(yàn):基于i.MX RT平臺(tái)的LVGL渲染能力突破
【PCA9958HN-ARD】GUI工具的使用
Arduino與LabVIEW聯(lián)合編程指南
10分鐘上手睿擎平臺(tái)GUI開發(fā):第一個(gè)LVGL圖形應(yīng)用
免費(fèi)分享Arduino入門+進(jìn)階(全套例程+書籍)
《ESP32S3 Arduino開發(fā)指南》第二章 Arduino基礎(chǔ)知識(shí)
如何制作和控制一只仿生手
樹莓派GUI應(yīng)用開發(fā):從零到炫酷的魔法之旅!
如何制作最簡(jiǎn)單的GUI來控制您的arduino
評(píng)論