
1:VB控制元件程式設計—后臺程式設計
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.PortName = "COM7"
SerialPort1.Open()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim RXD = SerialPort1.ReadExisting()
If RXD <> "" Then
If Mid(RXD, 1, 1) = "T" Then
Lab_t.Text = Mid(RXD, 2, 5)
Dim temp = Val(Mid(Lab_t.Text, 1, 1)) * 1000 + Val(Mid(Lab_t.Text, 2, 1)) * 100 + Val(Mid(Lab_t.Text, 4, 1)) * 10 + Val(Mid(Lab_t.Text, 5, 1))
If temp < 2750 Then
PictureBox2.Image = My.Resources.風扇停
Else
PictureBox2.Image = My.Resources.風扇轉
End If
End If
End If
End Sub
End Class

2:Arduino端程式
#include <DallasTemperature.h>
#include <OneWire.h>
// 定義DS18B20資料口連接arduino的10號IO上
#define ONE_WIRE_BUS 10
// 初始連接在單總線上的單總線設備
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup(void)
{
// 設定串口通信波特率
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// 初始庫
sensors.begin();
}
void loop(void)
{
sensors.requestTemperatures();
Serial.print("T");
Serial.println(sensors.getTempCByIndex(0));
delay (100);
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/280279.html
標籤:其他
下一篇:Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2)ABCDEFGH題解
