0

New to this
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: New to this

by giga on Fri Apr 13, 2018 4:11 pm

Here's what I have with me really fumbling around - I now have white with some blue but can't get it to blink and can't even get fade at all


Code: Select all | TOGGLE FULL SIZE
from digitalio import DigitalInOut, Direction
import board
import neopixel
import time
 
pixpin = board.D1
numpix = 10
 
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT
 
strip = neopixel.NeoPixel(pixpin, numpix, bpp=4, brightness=.5, auto_write=True)
 
color1 = (0, 0, 0, 255) 
color2 = (0, 0, 255, 255)

while True:
 
   strip[1] = color1
   strip[2] = color1
   strip[3] = color1
   strip[4] = color1
   strip[5] = color1
   strip[6] = color1
   strip[7] = color1
    time.sleep(.1)
 
   strip[1] = color2
   strip[2] = color2
   strip[3] = color2
   strip[4] = color2
   strip[5] = color2
   strip[6] = color2
   strip[7] = color2
    time.sleep(.1)
   
giga
 
Posts: 17
Joined: Fri Nov 09, 2012 11:17 am

Re: New to this

by adafruit_support_carter on Fri Apr 13, 2018 4:55 pm

Here's another useful link. This guide just went up a little while ago:
https://learn.adafruit.com/circuitpytho ... n-neopixel

There is a fill function you can use if you just want to set all pixels to the same color. Also, to clear or turn off the pixels, just set the color to black, or all zeros. So you can do something like this:
Code: Select all | TOGGLE FULL SIZE
   strip[1] = color1
   strip[2] = color1
   strip[3] = color1
   strip[4] = color1
   strip[5] = color1
   strip[6] = color1
   strip[7] = color1

with this:
Code: Select all | TOGGLE FULL SIZE
   strip.fill(color1)

Blink would be something like:
Code: Select all | TOGGLE FULL SIZE
while True:
    strip.fill(color1)
    time.sleep(0.1)
    strip.fill((0,0,0,0))
    time.sleep(0.1)

adafruit_support_carter
 
Posts: 7530
Joined: Tue Nov 29, 2016 2:45 pm

Re: New to this

by giga on Fri Apr 13, 2018 11:25 pm

When I do this I'm getting a syntax error on the first time.sleep(0.1), says python can't understand?
Blink would be something like:
Code: Select all | TOGGLE FULL SIZE
while True:
    strip.fill(color1)
    time.sleep(0.1)
    strip.fill((0,0,0,0))
    time.sleep(0.1)
giga
 
Posts: 17
Joined: Fri Nov 09, 2012 11:17 am

Re: New to this

by giga on Fri Apr 13, 2018 11:53 pm

giga wrote:When I do this I'm getting a syntax error on the first time.sleep(0.1), says python can't understand?
Blink would be something like:
Code: Select all | TOGGLE FULL SIZE
while True:
    strip.fill(color1)
    time.sleep(0.1)
    strip.fill((0,0,0,0))
    time.sleep(0.1)


Ok 4 whatever reason I rewrote it and it worked. Not just the fade to on part. Yikes! Lol
giga
 
Posts: 17
Joined: Fri Nov 09, 2012 11:17 am

Re: New to this

by giga on Sat Apr 14, 2018 12:22 am

so I'm finally happy with the first part of this - I may tinker a bit more with the timing and colors but I need to figure out the fade from 0 to on and stay on thing now. Basically it's simulating a machine coming awake kind of thing.

No idea if there's a cleaner way of doing this but it works lol

Code: Select all | TOGGLE FULL SIZE
 
from digitalio import DigitalInOut, Direction
import board
import neopixel
import time
 
pixpin = board.D1
numpix = 10
 
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT
 
strip = neopixel.NeoPixel(pixpin, numpix, bpp=4, brightness=.4, auto_write=True)
 
color1 = (100, 0, 0, 50) 
color2 = (180, 0, 0, 20)
color3 = (255, 0, 0, 0)

while True:
 
    strip.fill(color1)
    time.sleep(.002)
    strip.fill((0, 0, 0, 0))
    time.sleep(.03)
    strip.fill(color2)
    time.sleep(.07)
    strip.fill((0, 0, 0, 0))
    time.sleep(.1)
    strip.fill(color3)
    time.sleep(.3)
    strip.fill((0, 0, 0, 0))
    time.sleep(.5)
giga
 
Posts: 17
Joined: Fri Nov 09, 2012 11:17 am

Re: New to this

by adafruit_support_carter on Mon Apr 16, 2018 10:52 am

Looks like you're figuring it out. Try something, if you get some error message, try and work through that. Change a few more things, keep slowly changing the code to get where you want. Learn stuff along the way. So just keep playing with the code and look at other example for ideas, etc.

adafruit_support_carter
 
Posts: 7530
Joined: Tue Nov 29, 2016 2:45 pm

Re: New to this

by giga on Mon Apr 16, 2018 8:04 pm

I was messing with this for a few hours till I just gave up :(

Code: Select all | TOGGLE FULL SIZE
from digitalio import DigitalInOut, Direction
import board
import neopixel
import time
#import pulseio
 
pixpin = board.D0
numpix = 32
 
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT

#Brightness = 0
#fade_amount = 1285
#counter = 0
 
strip = neopixel.NeoPixel(pixpin, numpix, bpp=4, brightness=.03, auto_write=True,)

color1 = (100, 0, 0, 90) 
color2 = (200, 0, 0, 30)
color3 = (255, 0, 0, 0)
color4 = (0, 0, 255, 0)

while True:
 
    strip.fill(color1)
    time.sleep(0)
    strip.fill((0, 0, 0, 0))
    time.sleep(.04)
    strip.fill(color2)
    time.sleep(.08)
    strip.fill((0, 0, 0, 0))
    time.sleep(.2)
    strip.fill(color3)
    time.sleep(.2)
    strip.fill((0, 0, 0, 0))
    time.sleep(.02)
   
#    if (brightness <= 0):
#        fade_amount = -fade_amount
#        counter += 1
#    elif (brightness >= 65635):
#        fade_amount = -fade_amount
#        counter += 1
giga
 
Posts: 17
Joined: Fri Nov 09, 2012 11:17 am

Re: New to this

by adafruit_support_carter on Mon Apr 16, 2018 11:17 pm

time.sleep() is in units of seconds. The values you are using are pretty small. color3 stays on the longest at 0.2 seconds, but even that is pretty quick.

adafruit_support_carter
 
Posts: 7530
Joined: Tue Nov 29, 2016 2:45 pm

Re: New to this

by giga on Tue Apr 17, 2018 8:05 am

Yeah I'm ok with that and I know it's in milliseconds, I want it to blink very fast as it boots up, then fade to on and stay on.
giga
 
Posts: 17
Joined: Fri Nov 09, 2012 11:17 am

Re: New to this

by giga on Tue Apr 17, 2018 1:14 pm

latest messing around to no avail

Code: Select all | TOGGLE FULL SIZE
from digitalio import DigitalInOut, Direction
import board
import neopixel
import time
import pulseio
 
pixpin = board.D0
numpix = 32
 
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT
# strip = pulseio.PWMOut(board.D0)
# FADE_SLEEP = 10

# def duty_cycle(percent):
#    return int(percent / 100.0 * 65535.0)

strip = neopixel.NeoPixel(pixpin, numpix, bpp=4, brightness=.02, auto_write=False,)

color1 = (100, 0, 0, 90) 
color2 = (200, 0, 0, 30)
color3 = (255, 0, 0, 0)
color4 = (0, 0, 255, 0)

while True:
 
    strip.fill(color1)
    strip.show()
    time.sleep(.001)
    strip.fill((0, 0, 0, 0))
    strip.show()
    time.sleep(.01)
    strip.fill(color2)
    strip.show()
    time.sleep(.1)
    strip.fill((0, 0, 0, 0))
    strip.show()
    time.sleep(.1)
    strip.fill(color3)
    strip.show()
    time.sleep(.1)
    strip.fill((0, 0, 0, 0))
    strip.show()
    time.sleep(.2)
   
#    for i in range(100):
#        strip.duty_cycle = duty_cycle(i)
#        time.sleep(FADE_SLEEP)
giga
 
Posts: 17
Joined: Fri Nov 09, 2012 11:17 am

Please be positive and constructive with your questions and comments.


cron