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


沒有留言:

張貼留言

Messaging API作為替代方案

  LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...