EasyManuals Logo

Freenove Ultimate Starter Kit User Manual

Freenove Ultimate Starter Kit
286 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #126 background imageLoading...
Page #126 background image
Chapter 10 Photoresistor & LED
126
www.freenove.com
support@freenove.com
29
30
31
32
delay(100);
}
return 0;
}
Python Code 10.1.1 Nightlamp
First observe the project result, and then analyze the code.
1. Use cd command to enter 09.1.1_Nightlamp directory of Python code.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/Python_Code/10.1.1_Nightlamp
2. Use the python command to execute the Python code Nightlamp.py.
python Nightlamp.py
After the program is executed, when you cover the photosensitive resistance or make a flashlight toward the
photoresistor, the brightness of LED will be enhanced or weakened. And the terminal window will print out
the current input voltage value of PCF8591 AIN0 pin and the converted digital quantity.
The following is the program code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
im port RPi. GPIO as GPIO
im port smbus
im port time
address = 0x48
bus=smbus.SMBus(1)
cmd=0x40
ledPin = 11
def analogRead(chn):
value = bus.read_byte_data(address,cmd+chn)
r eturn value
def analogWrite(value):
bus. write_byte_data(address,cmd,value)
def setup():
g lobal p
GPIO. setmode(GPIO.BOARD)
GPIO. setup(ledPin,GPIO.OUT)
GPIO. output(ledPin,GPIO.LOW)
p = GPIO. PWM(ledPin,1000)
p. start(0)
def loop():
w hile Tr ue:

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Freenove Ultimate Starter Kit and is the answer not in the manual?

Freenove Ultimate Starter Kit Specifications

General IconGeneral
BrandFreenove
ModelUltimate Starter Kit
CategorySingle board computers
LanguageEnglish