2021年11月18日 星期四

B4R Light Dimmer For ESP32-WROOM-32

 B4R Light Dimmer For ESP32-WROOM-32  

源自於 https://www.b4x.com/guides/B4RExampleProjects/?page=38


#Region Project Notes
'B4R HowTo Project: Light Dimmer (ESP32-WROOM-32)
'
'Connection (looking at the blue sensor from right to left)
' pushbutton switch --------------GPIO23
' blue LED 220 Ω resistor---------GPIO16
' potentiometer-------------------GPIO13 
'  
#End Region
#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 600
#End Region

Sub Process_Globals
Public Serial1 As Serial
Private pinButton, pinPot, pinLedBlue As Pin
Private Reading = False As Boolean
Private Timer1 As Timer
Private BounceTime As ULong
Private BounceDelay = 10 As ULong
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")

'Using the internal pull up resistor to prevent the pin from floating.
pinButton.Initialize(23, pinButton.MODE_INPUT_PULLUP) 
pinButton.AddListener("pinButton_StateChanged")
pinLedBlue.Initialize(16, pinLedBlue.MODE_OUTPUT)

Timer1.Initialize("Timer1_Tick", 200)
pinPot.Initialize(13, pinPot.MODE_INPUT)
End Sub
Sub pinButton_StateChanged (State As Boolean)
Log("State: ", State)
'state will be False when the button is clicked because of the PULLUP mode.
If State = False Then
If Millis - BounceTime < BounceDelay Then
Return
Else
Reading = Not(Reading)
BounceTime = Millis
Timer1.Enabled = Reading
Log("Reading: ", Reading)
If Reading = False Then
pinLedBlue.AnalogWrite(0)
End If
End If
End If
End Sub
Private Sub Timer1_Tick
Private Value As UInt
Value = pinPot.AnalogRead
Log("Value = ", Value)
pinLedBlue.AnalogWrite(Value / 4)
'ESP32沒有analogWrite的功能
End Sub

'ESP32沒有analogWrite的功能需使用PWM方式

沒有留言:

張貼留言

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

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