Hi Guys,
I am totally new here. So I hope to find some help with my project.
I have an adafruit 16-channel servo hat for raspberry pi with 2 connected servo's and 2 led's. My 2 servo's are working great. My next step is to make the 2 connected led's blink. Now there 'on' for a few milliseconds and then turned 'off'. Can any body tell me what is the best way (code) to make the led's blink?
My setup:
Raspberry pi 4b+
Adafruit 16-channel servo hat
2x SG90 micro servo's (on channel 0 and 1)
2 led's connected on 1 channel on the adafruit hat (on channel 2).
Thanks in advance!!
How to make blinking Led's on 16-channel servo hat
Moderators: adafruit_support_bill, adafruit
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
- Rich_art
- Posts: 4
- Joined: Mon Apr 11, 2022 1:47 pm
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: How to make blinking Led's on 16-channel servo hat
You can used PWM to control the LEDs. This section of the guide will be quite helpful:
https://learn.adafruit.com/adafruit-16- ... -3013782-7
https://learn.adafruit.com/adafruit-16- ... -3013782-7
Code: Select all
# Increase brightness:
for i in range(0xffff):
led_channel.duty_cycle = i
# Decrease brightness:
for i in range(0xffff, 0, -1):
led_channel.duty_cycle = i
- Rich_art
- Posts: 4
- Joined: Mon Apr 11, 2022 1:47 pm
Re: How to make blinking Led's on 16-channel servo hat
Hi Mike, thanks for your quick reply.
I had read this part of the documentation but I do not understand the numbering between the parentheses.
So 'for i in range(0xfff, 0, -1):'
Where is the (0) and the (-1) for? How do I set the time of 'blinking' of the led's?
Thanks in advance!
Rich
I had read this part of the documentation but I do not understand the numbering between the parentheses.
So 'for i in range(0xfff, 0, -1):'
Where is the (0) and the (-1) for? How do I set the time of 'blinking' of the led's?
Thanks in advance!
Rich
- Rich_art
- Posts: 4
- Joined: Mon Apr 11, 2022 1:47 pm
Re: How to make blinking Led's on 16-channel servo hat
Ah... I did find a workaround. :-)
For now this is it for me:
For now this is it for me:
Code: Select all
led_channel = hat.channel[2]
led_channel.duty_cycle = 0xffff
time.sleep(0.1)
led_channel.duty_cycle = 0
time.sleep(0.1)
led_channel.duty_cycle = 0xffff
time.sleep(0.1)
led_channel.duty_cycle = 0
time.sleep(0.1)
led_channel.duty_cycle = 0xffff
time.sleep(0.1)
led_channel.duty_cycle = 0
time.sleep(0.1)
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: How to make blinking Led's on 16-channel servo hat
The loop code I had linked you to sets the duty_cycle in a range from 0-65535.
The first loop counts up from 0 (0xffff) or 65,535 the next loop goes back down to zero.
Python uses the 0 and -1 as loop controls to specific where to stop and how much to decrement by.
The first loop counts up from 0 (0xffff) or 65,535 the next loop goes back down to zero.
Python uses the 0 and -1 as loop controls to specific where to stop and how much to decrement by.
- Rich_art
- Posts: 4
- Joined: Mon Apr 11, 2022 1:47 pm
Re: How to make blinking Led's on 16-channel servo hat
After puzzling for a while I made it the following:
Here I find some extra info: https://www.w3schools.com/python/python_for_loops.asp
Thanks!!
Code: Select all
for i in range(20):
led_channel = hat.channels[2]
led_channel.duty_cycle = 0xffff #led on
time.sleep(0.1)
led_channel.duty_cycle = 0 #led off
time.sleep(0.1)
Thanks!!
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/