SunFounder RasPad 3
Code Explanation
led_val = GPIO.PWM(LED_PIN, 2000)
led_val.start(0)
Call the
GPIO.PWM()
function to define
LED_PIN
as PWM pin and set the frequency of PWM pin to 2000Hz, then
use the
start()
function to set the initial duty cycle to 0.
led_val.ChangeDutyCycle(value)
The value sent by Slider widget to Raspberry Pi is used as PWM duty cycle to change the brightness of the LED.
variables = {
'CPU Temp': {
'type': 'numeric',
'value': 0,
'bind': led_control
},
}
By setting the value of the
'value'
key, we can set the initial value of the Slider widget, then always read the value
of the
'value'
key and send the current level of
LED_PIN
(the value returned by the function
led_control
) to
Cloud4RPi.
Smart Curtain
In this project, we will simulate a scenario where the curtains are automatically opened or closed according to the
brightness of the room. When the photoresistor detects that the room brightness is too bright, Raspberry Pi will drive
the motor to close the curtain; when the room brightness is too dark, the curtain will be opened.
Also you can view the indoor brightness change through text widget on Cloud4RPi, or control the lamp with Switch
widget (for electricity safety, this experiment uses LED instead).
7.5. Cloud4RPi
113
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 ...