Please advise.
I have a conditional strip of 93 LEDs. There are several "masks" for turning on individual pieces of the strip in different modes. For example: 000000000000000000 - the strip is off.
Masks 1100 and 1010.
001100000000001010 - masks are applied in positions 1 and 2 (without changing other sections of the strip)
001010000000001100 - masks are applied in positions 2 and 1 (without changing other sections of the strip)
A question about examples of such code (i use Adafruit NEOPIXEL). I am not a programmer and do not even know how to correctly formulate a search query ... I looked at the projects of some watches and some matrix, but did not find anything similar. Thank you.
then the library has examples...
What is your question?
It is best if you start with a wiring diagram, all source code in code tags, and any error logs also in codse tags.
Please explain what you mean. Under what conditions is it a strip? What is it under other conditions?
I can't understand this. 4 bits control position 1 and 4 bits control position 2. What do the other 10 bits do? What controls the other 91 LEDs?
Thanks everyone for your answers.
I probably couldn't explain what i want correctly.
Maybe like this: how can i collect a batch of data for all the LEDs and send them to the tape? That is, i form a sequence in the code 10100001100, etc. from pieces, and send it all to the tape.
Or like this: i have 10 variables with codes like 0101. i have collect them in one variable: $varmax="$var1$var2...$var10" and send them all to the tape. And i don't understand how to formulate this into a single thought.
Your example is 5 sections of 18 bits with three extra. Strange number. I would guess that you want the two masks to alternate, without the extra bits:
0011.1010.0011.1010...
You can read about bit masking here...
https://docs.arduino.cc/learn/programming/bit-mask/
Put the data in an array. This example (Adafruit and FastLED are nearly the same) has the static data in an array... but you can change the data and re-write it to the NeoPixels.
you don't... see how the library works:
The strip is represented by an object (instance of Adafruit_NeoPixel)
const byte nbPixels = 93;
const byte controlPin = 2;
Adafruit_NeoPixel strip(nbPixels, controlPin, NEO_GRB + NEO_KHZ800); // 93 pixels, controlled from pin 2
➜ I declared an objet name strip which lets me address each pixel individually.
if you want to set the pixel 27 in the strip to red, and pixel 42 to blue you would do
strip.setPixelColor(27, strip.Color(255, 0, 0)); // pixel #27 tuns to RGB (255, 0, 0) = full red
strip.setPixelColor(42, strip.Color(0, 0, 255)); // pixel #42 tuns to RGB (0, 0, 255) = full blue
and then to send the new colors to the strip you do
pixels.show(); // Send the updated pixel colors to the hardware.
You don't have to mess with string of 0 and 1 or whatever...
Try looking at the sample sketches included with the library, that will show you how it is done.
What kind of data? Is it text? Or binary?
How did you collect it?
Let's say that you have a text of 93 characters, each one being a '0' or a '1'.
You can loop through that text with a for-loop, use an if/else to decide if a LED must be on or off and set the pixel on or off. Once the for-loop is finished, you can send the data to the strip using show.
please describe more context. What system is sending
10100001100 ?
How have you connected your Arduino to it?
Will you always receive a stream of 93 digits consisting 0 and 1?
Which Arduino are you using?
Let me try to explain it this way. Here in the picture there are three states 1 2 and 3. Conventionally, 1 and 0 are simply on and off (color is not important). I could, for example, use a for loop, go through from 13 to 25 and turn on the green one. And there is even such an example in the library and I understand it. However, if I need to turn on 110010110001, then I can’t do it with a simple loop. Or I don’t know how. There is an array with masks, but I don’t understand at all how to use it to turn on the desired section of the tape. All I can do is turn on a specific LED or light them one by one.
I didn't notice the link right away, but it looks like this is what I need.
This is one way... read each bit in the mask then use a condition to turn section on or off...
byte mask[] = {B1100, B1010};
void setup() {
Serial.begin(115200);
for (int j = 0; j < 2; j++) { // two arrays
for (int i = 0; i < 4; i++) { // each array is 4 bits
if (mask[j] & 1 << 3 - i) // read the mask backwards (3, 2, 1, 0) "AND" with "1"
Serial.print(1); // call any function if mask is "1"
else Serial.print(0); // call another function if mask is "0"
}
Serial.println();
}
}
void loop() {
// empty
}
Looking at your drawing, you have 8 squares made up with 12 leds (so 96 leds total) and they are arrange in a strip from what I gather from the small top view and the arrows, so the led numbering goes like this
numbering starts at 0 so this would actually be from 12 to 23
why not ? you are still going through each character and just test if the character is 1 or 0 and set the color to green or black...
until you explain to us where the 0 and 1 come from and what they represent (do you get a full 96 characters of 0 and 1 ?) , this conversation is going nowhere....
"Conditional" is this week's assignment; if '1' then red square else green square... (called "any function" in post 13).
It took 11 posts just to show a visual representation. Probably another 10 to show a wiring diagram (with 90/96 LEDs powered by an Arduino... and 10 posts to clear that up). If OP spent as much time reading, learning and trying as "correcting" assistance attempts, the project would be complete. OP is waiting for a code dump.
Thanks to everyone for the answers and hints. With the help of your links and hints, I found a suitable project (I think it was a watch project). I modified it a little and got this:
#include <ESP8266WiFi.h>
#include <Adafruit_NeoPixel.h>
const char *ssid = "";
const char *password = "";
#define PIN D5
#define PIXEL_COUNT 91
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(PIXEL_COUNT, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 500
uint32_t DIGIT[] = {
0x60f06 /* circle */
};
uint8_t POSITION[] = { 68,47,24,3 };
unsigned int R_MASK[] = {
0x00000001, 0x00000002, 0x00000004, 0x00000008,
0x00000010, 0x00000020, 0x00000040, 0x00000080,
0x00000100, 0x00000200, 0x00000400, 0x00000800,
0x00001000, 0x00002000, 0x00004000, 0x00008000,
0x00010000, 0x00020000, 0x00040000, 0x00080000 };
void PutChar(char c,uint8_t digit,uint32_t color){
uint32_t mask = 0;
uint32_t color1 = pixels.Color(0, 0, 0); //off
switch(c){
case 'o': mask = DIGIT[0]; break;
default : mask = 0;
}
for( int i=0; i<20; i++ )
if( mask & R_MASK[i] ) {
pixels.setPixelColor(POSITION[digit]+i, color);
} else {
pixels.setPixelColor(POSITION[digit]+i, color1);
}
}
void Clear(){
for( int i=0; i<PIXEL_COUNT; i++ )pixels.setPixelColor(i, 0);
}
void setup() {
WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED ) {
delay ( 500 );
Serial.print ( "." );
}
pixels.begin();
Clear();
PutChar('o',0,pixels.Color(2, 0, 0));
PutChar('o',1,pixels.Color(2, 0, 0));
PutChar('o',2,pixels.Color(2, 0, 0));
PutChar('o',3,pixels.Color(2, 0, 0));
pixels.show();
}
void loop() {
}
This is enough for further research. And I finally understood bit masks! Thanks to everyone, the question is closed.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.


