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 #114 background imageLoading...
Page #114 background image
Chapter 8 Potentiometer & LED
114
www.freenove.com
support@freenove.com
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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:
value = analogRead(0) #read A0 pin
p. ChangeDutyCycle(value*100/255) #Convert ADC value to duty cycle of PWM
voltage = value / 255.0 * 3.3 #calculate voltage
print ('ADC Value : %d, Voltage : %.2f'%(value,voltage))
time.sleep(0.01)
def destroy():
bus. close()
GPIO. cleanup()
if __name__ == '__main__':
p rint ('Program is starting ... ')
setup()
try:
loop()
e xcept KeyboardInterrupt:
destroy()
In the code, read ADC value of potentiometers and map it to duty cycle of PWM to control LED brightness.

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