2021年11月21日 星期日

B4R LCD 量測脈波寬度 (Arduino UNO)

  B4R LCD 量測脈波寬度 (Arduino UNO)




#Region Project Notes
' pinButton -------------------A5 
'initialize the display(RS As Byte, RW As Byte, Enable As Byte
'RS pin > Arduino digital pin 12
'RW pin > 255 means mot used 
'Enable pin > Arduino digital pin 11 
'DataPins: Arduino digital pins 5, 4, 3, 2 
'DB7-----------------2
'DB6-----------------3
'DB5-----------------4
'DB4-----------------5
'-----------------------------------------
#End Region
#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 600
#End Region
Sub Process_Globals
Public Serial1 As Serial
Public pinButton As Pin 'pin for the button
Public lcdDisplay As LiquidCrystal
Public TimeBegin, PulseWidth As ULong 'used to measure the time
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("APP Starting......")
'Using the internal pull up resistor to prevent the pin from floating.
pinButton.Initialize(pinButton.A5, pinButton.MODE_INPUT_PULLUP) 
pinButton.AddListener("pinButton_StateChanged")
'initialize the display(RS As Byte, RW As Byte, Enable As Byte
'RS pin > Arduino digital pin 12
'RW pin > 255 means mot used 
'Enable pin > Arduino digital pin 11 
'DataPins: Arduino digital pins 5, 4, 3, 2 
lcdDisplay.Initialize(12, 255, 11, Array As Byte(5, 4, 3, 2))
lcdDisplay.Begin(16, 2) 'set the display type 2 * 16 characters
lcdDisplay.Write("Pulse width [ms]") 'write "Pulse width" in the first line 
End Sub
Private Sub pinButton_StateChanged (State As Boolean)
Log("State: ", State) 'Log the State value
If State = False Then 'if State = False, button down
TimeBegin = Millis 'set TimeBegin, Millis = number of milliseconds since the last restart
Else
PulseWidth = Millis - TimeBegin 'calculate the numer of milliseconds since button down
lcdDisplay.SetCursor(0, 1) 'set the cursor at the begin of the second line 
lcdDisplay.Write("          ") 'clear the text
lcdDisplay.SetCursor(0, 1) 'set the cursor at the begin of the second line 
lcdDisplay.Write(PulseWidth) 'write the nubmer of milli seconds
Log("PulseWidth: ", PulseWidth)
End If
End Sub


沒有留言:

張貼留言

113 學年度第 1 學期 RFID應用課程 Arduino程式

113 學年度第 1 學期 RFID應用課程 Arduino程式 https://www.mediafire.com/file/zr0h0p3iosq12jw/MFRC522+(2).7z/file 內含修改過後的 MFRC522 程式庫 (原程式有錯誤) //定義MFRC522...