EasyManua.ls Logo

SunFounder TS7-Pro - Page 120

Default Icon
235 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
TS7-Pro 7-inch Touch Screen
Code Explanation
RELAY_PIN = 18
Relay connected to GPIO18 of the T-expansion board.
GPIO.setmode(GPIO.BCM)
GPIO.setup(RELAY_PIN, GPIO.OUT)
Set to BCM nomenclature and set RELAY_PIN to output.
def relay_control(value=None):
GPIO.output(RELAY_PIN, value)
return GPIO.input(RELAY_PIN)
This function controls the relay according to the value and returns the current level of the relay.
Note: Since the relay works at high level, the relay closes when the switch state is True and opens when the switch
state is False.
variables = {
'LED On': {
'type': 'bool',
'value': False,
'bind': relay_control
},
}
By setting the value of the 'value' key, we can set the initial value of the Switch widget, then always read
the value of the 'value' key and send the current level of RELAY_PIN (the value returned by the function
relay_control()) to Cloud4RPi.
Smart Light
In this project, we will learn to control the brightness of LED with Cloud4RPi’s Silder widget.
116 Chapter 5. PROJECTS AND ACTIVITIES

Related product manuals