2021年11月21日 星期日

B4R LCD 量測脈波寬度 (ESP32-WROOM-32)

 B4R LCD 量測脈波寬度



#Region Project Notes
'B4R HowTo Project: Pulse Width Meter (ESP32-WROOM-32)
'
'Connection (looking at the blue sensor from right to left)
 
 ' LCD 4bit mode RS--------------- GPIO13
 ' LCD 4bit mode EN--------------- GPIO12
 ' LCD 4bit mode D4--------------  GPIO14
 ' LCD 4bit mode D5--------------  GPIO27
 ' LCD 4bit mode D6--------------  GPIO26
 ' LCD 4bit mode D7--------------  GPIO25
'  
#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(23, pinButton.MODE_INPUT_PULLUP) 'Using the internal pull up resistor to prevent the pin from floating.
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.Initialize(13, 255, 12, Array As Byte(14, 27, 26, 25))
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("State: ", PulseWidth)
End If
End Sub



沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...