SunFounder RasPad 3
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â ˘
A ´
Zs Silder widget.
110
Chapter 7. RASPAD PROJECTS AND ACTIVITIES
Summary of Contents for RasPad 3
Page 1: ...SunFounder RasPad 3 www sunfounder com May 10 2022 ...
Page 2: ......
Page 6: ...SunFounder RasPad 3 2 Contents ...
Page 8: ...SunFounder RasPad 3 4 Chapter 1 SAFETY NOTICES ...
Page 9: ...5 ...
Page 10: ...SunFounder RasPad 3 Chapter 2 COMPONENTS LIST 6 Chapter 2 COMPONENTS LIST ...
Page 16: ...SunFounder RasPad 3 Connect the USB C cable 12 Chapter 3 ASSEMBLY INSTRUCTIONS ...
Page 23: ...SunFounder RasPad 3 19 ...
Page 24: ...SunFounder RasPad 3 20 Chapter 3 ASSEMBLY INSTRUCTIONS ...
Page 38: ...SunFounder RasPad 3 34 Chapter 4 QUICK USER GUIDE ...
Page 50: ...SunFounder RasPad 3 46 Chapter 6 INTERFACES INTRODCTION ...
Page 51: ...SunFounder RasPad 3 6 3 Connect Headphones or Other Screens 47 ...
Page 52: ...SunFounder RasPad 3 48 Chapter 6 INTERFACES INTRODCTION ...
Page 77: ...SunFounder RasPad 3 Select the device type ESP32 for example 7 4 Home Assistant 73 ...
Page 129: ...SunFounder RasPad 3 7 7 Scratch Projects 125 ...
Page 143: ...SunFounder RasPad 3 Also let it appear at the right time 7 7 Scratch Projects 139 ...
Page 146: ...SunFounder RasPad 3 142 Chapter 7 RASPAD PROJECTS AND ACTIVITIES ...
Page 151: ...SunFounder RasPad 3 Let it change the color and size randomly 7 7 Scratch Projects 147 ...
Page 156: ...SunFounder RasPad 3 152 Chapter 7 RASPAD PROJECTS AND ACTIVITIES ...
Page 157: ...SunFounder RasPad 3 7 7 Scratch Projects 153 ...
Page 162: ...SunFounder RasPad 3 158 Chapter 7 RASPAD PROJECTS AND ACTIVITIES ...
Page 175: ...SunFounder RasPad 3 7 7 Scratch Projects 171 ...
Page 181: ...SunFounder RasPad 3 Copy out the second Trees 7 7 Scratch Projects 177 ...
Page 182: ...SunFounder RasPad 3 178 Chapter 7 RASPAD PROJECTS AND ACTIVITIES ...
Page 188: ...SunFounder RasPad 3 184 Chapter 7 RASPAD PROJECTS AND ACTIVITIES ...
Page 202: ...SunFounder RasPad 3 198 Chapter 7 RASPAD PROJECTS AND ACTIVITIES ...
Page 204: ...SunFounder RasPad 3 200 Chapter 7 RASPAD PROJECTS AND ACTIVITIES ...
Page 222: ...SunFounder RasPad 3 218 Chapter 7 RASPAD PROJECTS AND ACTIVITIES ...