Adafruit_NeoPixel | Arduino library
kandi X-RAY | Adafruit_NeoPixel Summary
kandi X-RAY | Adafruit_NeoPixel Summary
Arduino library for controlling single-wire-based LED pixels and strip such as the Adafruit 60 LED/meter Digital LED strip, the Adafruit FLORA RGB Smart Pixel, the Adafruit Breadboard-friendly RGB Smart Pixel, the Adafruit NeoPixel Stick, and the Adafruit NeoPixel Shield. After downloading, rename folder to 'Adafruit_NeoPixel' and install in Arduino Libraries folder. Restart Arduino IDE, then open File->Sketchbook->Library->Adafruit_NeoPixel->strandtest sketch. Compatibility notes: Port A is not supported on any AVR processors at this time.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Adafruit_NeoPixel
Adafruit_NeoPixel Key Features
Adafruit_NeoPixel Examples and Code Snippets
Community Discussions
Trending Discussions on Adafruit_NeoPixel
QUESTION
I have made a class to represent my led strip, and I would like to switch off the strip when I stop it (aka when the program stops and the object is destroyed). Hence, as I would do in C++, I created a destructor to do that. But it looks like Python call it after it destroyed the object. Then I got a segmentation fault error.
Here is my class, the destructor just have to call the function to set the colour of each LED to 0.
ANSWER
Answered 2021-May-27 at 04:46Let's put it this way. Firstly, "...as I would do in C++" approach is not appropriate, as I'm sure you know yourself. It goes without saying that Python is totally different language. But in this particular case it should be stressed, since Python's memory management is quite different from C++. Python uses reference counting, when objects reference count goes to zero, its memory will be released (i.e. when an object is garbage collected) and so on.
Python user-defined objects sometimes do need to define __del__()
method. But it is not a destructor in any sense (not in C++ sense for sure), it's finalizer. Moreover, it is not guaranteed that __del__()
methods are called for objects that still exist when the interpreter exits. Yet we can invoke __del__()
explicitly, it should not be for your case, as for this I would advise to make LED switch off as an explicit method, not relying on Python's internals. Just like it goes in Zen of Python (import this
command).
Explicit is better than implicit.
For more information on __del__()
, check this good answer. For more on reference counting check this article.
QUESTION
I'm new in programming, and tried to programm a clock with a RGB-LED-Ring, but i had Errors and just didn't understand them. At first i tried it with extra Methods but i didn't really understand how they work so i just wrote the code in the loop. Would be nice if somebody can help and write beginner friendly.
...ANSWER
Answered 2021-May-04 at 10:57I won't go into too much details here. Please do a beginners tutorial on C++ befor you continue. You don't need to go into advanced topics like templates or polymorphims yet but at least you should know the basic syntax.
Your code does not make any sense.
What is #define MULTISEK
supposed to do?
Especially followed by static int MULTISEK = 0;
Why do you use preprocessor directives if you don't know what they do?
QUESTION
I've been having problems trying to work out how to loop through an array of Adafruit_NeoPixel objects. But I cant for the life of me get my head aroud what is going wrong. Ive looked up this issue on google and trough both Ardrino and stack over flow ive tryed adapting the code to what ive seen other people have done (for example instead of listing the adafruit_neopixles objects in the array,create the neopixles inside the array) to get it to work and still I have no luck.
so heres an simple example: this script should make the first 6 Leds light up in green blue
...ANSWER
Answered 2020-Nov-29 at 23:20So I've fixed this issue by swapping out the adafruit liabery with fastled no more crashing or abnormal behaviour.
QUESTION
I am trying to manage some LED strips with my mobile device using bluetooth + Adafruit NeoPixel. I almost had the sketch finished but I have found the numbers for RGB are not appearing as I expected and I cannot find what I am doing wrong.
Imagine that from my mobile I have sent the following RGB code "0,19,255", when I check the console I see the following result:
As you can see the first two lines are ok, but the third one we can see 2550. The 0 should no be there and I cannot figure it out the problem.
So I decided isolate the code and try to keep the minimum to identify the root cause and this is the code:
...ANSWER
Answered 2020-Nov-07 at 10:36You describe that for the shown output you sent via mobile "0,19,255".
Yet in the shown output that obviously is only the second part of a longer sequence of numbers sent, which starts with "0,21".
Assuming that what you send is always of the format you have described, i.e. three numbers, separated by two ",", the shown output is most likely the result of you sending first "0,21,255" and then another triplet "0,19,255".
These two messages together would end up in an input buffer "0,21,2550,19,255".
Now I have to do some speculation. Most parsers, when told to look for numbers within the buffer, will look for digits followed by non-digits. They would end up yielding "0,21,2550".
Without knowing details of the parsers working it is hard to say how to fix your problem.
I would however definitly experiment with sending triplets which end in a non-digit.
For example:
"0,21,255,"
or
"0,21,255 "
or
"0,21,255;"
If none of them work you might need to explicitly expect the non-digit, i.e. between triplets of numbers read a character and either ignore it or compare it to " ,", " " or ";" for additional self-checking features.
(Writing this I rely on user zdf not intending to make an answer, because while I did spot the "2550" as "255""0", zdf spotted the only two "," inside the question body in sample input, which I missed. I will of course adapt my answer to one created by zdf, to not use their contribution without their consent.)
QUESTION
I'm having some difficulties understanding how to convert my "regular" code into "Object oriented" code.
My code is for Arduino, but the question is generic enough, so no Arduino specific details are relevant to the question.
In my "regular" code I just import a library, call a constructor with some parameters to create the object, and then call the method begin
...ANSWER
Answered 2020-Oct-05 at 14:42To call a constructor from an other constructor use the syntax:
QUESTION
i was able to make the following code after about a week of desk head banging, it works, kind of. the problem is that it's not that responsive, most of the times i have to spam the buttons on my phone to send the same command over and over again until it catches up.
Can you help me clean the code a bit?
As you will see, at times it seems i over complicated things but that is only cause i found it works better this way then what it seems to be a more "logical" simpler version. i will lay the code and then i will explain and ask my questions.
...ANSWER
Answered 2020-Jul-21 at 01:43I'm bored and feeling generous so here you go. See if you can follow this. It's uncompiled and untested so I can't guarantee it does exactly what you want, but see if you can understand what I'm trying to do here. Nothing ever stops and waits for anything to happen. There are no delay calls. There is no waiting. Just cycling through and see if it is time to do something.
One change I made that doesn't affect this, just makes typing easier was to take all your goLED variables and make an array out of them. Anytime you catch yourself putting numbers on variable names, use an array instead so the compiler has access to those numbers and you don't have to repeat yourself. See how much simpler the checkLedData function got.
Then I made the colorWipe functions so that they will return a boolean, true if they've completed and false if they haven't. Then the runLED function can just check that to see if it is time to move on to the next step. For the first case it is easy, just set the goLED variable to whatever the colorWipe returns. As long as it is still working it returns true and goLED[1] stays true and you keep calling the same colorWipe function. For the others we have to make them state machines, so I added a state variable. When any of them get finished they set their goLED variable back to false. When all of those are false, meaning there's no effect currently running, then runLED will fall all the way through to the last else statement and go to see if there is another command.
Like I said, there may be a mistake or two in there. But see if you can understand how I am writing a checklist to see what needs to happen instead of a story to tell one thing right after another.
QUESTION
i'm using Arduino IDE 1.8.12, it's setup to use digispark libs (i think), don't remember exactly what i did, watched a video online some many moths ago.
i have an issue with my sketch, when i try to compile it it gives me this error:
...ANSWER
Answered 2020-Jul-18 at 01:05Simply implement the same functionality in your sketch using read().
readString blocks for a set amount of time. It freezes your sketch waiting on the transmission to complete for 1 second. This isn't great for most sketches. Most of the time it would be better to implement a non-blocking read. There are also big issues with using the String class on smaller microcontrollers like the UNO and especially the tiny85 in the digiSpark. It would be best on that platform to stick to c-style strings. But here's how to mimic readString if that's really what you want to do.
QUESTION
I am new to C++ I come from a C# background. I am creating an Arduino project using c++ using vs code thanks to https://docs.platformio.org/ .
The following code works and turns on my led strip:
main.cpp
...ANSWER
Answered 2020-Jul-03 at 21:57The writers of that class made a grade-school C++ mistake and didn't correctly observe the Rule of Three. This means an Adafruit_NeoPixel
object can be copied when it is not safe to do so.
QUESTION
I am writing an app in python that controls some LEDs based on GPIO state. On the hardware, I listen for the GPIOs to change state and publish to an MQTT server running on a raspberry pi to control the LEDs. One of the GPIOs should cause an LED to blink indefinitely until state changes again to turn it off, exactly how a car turn signal works.
So when the GPIO goes high I publish to a topic with the payload 'on'. I then set a global variable
blinker_status = True
and then basically say (pseudo code)
while (blinker_status) { blink }
When I publish to that same topic with the payload 'off', I set the value of the global variable
blinker_status = False
I'm expecting the LED to stop blinking, but it doesn't. I'm not sure if the issue is that MQTT is blocking?
Once I start the LED blinking, perhaps it's blocking the on_message()
call back and it cannot process additional messages? Should I isolate all of my subscriber clients into their own threads so that publishing to each topic is handled by its own on_message()
call back?
I have code I can provide if necessary but at this point I'm stuck on trying to understand why my logic is flawed.
Below is my code
...ANSWER
Answered 2020-Jun-09 at 18:36The on_message
callback is run on the MQTT client's network thread, if you block that thread you will not be able to send or receive any more messages.
You should NOT be doing any blocking or long running actions in this (or any of the client callbacks), you should be setting flags in a state machine and using those changes to control other threads.
QUESTION
I'm restarting a personal project that involved an ESP8266 and WS2812Bs (Neopixels).
It is worth noting that I do not have any Neopixels hooked up at the moment; I'm simply trying to get a feel for how fast I can update the pixels.
I'm running a very simple piece of example code taken from Adafruit's Neopixel GitHub repo. I've modified it slightly to make it more accurate to my use case and to remove comments (for the sake of posting here).
DetailsThe sample code:
...ANSWER
Answered 2020-Apr-17 at 08:51This is a wild guess, but these strips work in a serial way: the first LED is taking the first 24bits, ditch them and pass the remaining to the following LED and so on. That does mean the message you are sending is increasing with the number of the LEDs you are currently addressing.
These LEDs IC also need some time to reset before the next message is received, it is possible that there is a data conflict as the strip cannot catch up with an increasing signal length at full speed of you ESP.
Your second example contains some tests, which might slow down the transfer enough to avoid the conflict.
So, you might just need to add a small delay in your first example, from the documentation something as small as 50 microsecs might be enough. You can use delayMicrosecond()
for that.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Adafruit_NeoPixel
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page