For a while I work with neopixel ws2812 LEDs and works fine. Only I always use example skins because self programming is quite difficult. Now I have found a program that helps me to find colors for these LEDs but I want to add something.
Below you will find a sketch what this program generates, in it the colors red white blue and now I want to let it run at a certain speed, for example every second changed to red becomes white, white becomes blue and blue becomes red. Can someone change what I have to do for this. How do I tell arduino that he has to walk and the speed of that. If I know that, then I'll get out of it.
Thank you, it works so well indeed. Can I be so brazen to ask a question?
I have a print with 6 x ws2812 digital LEDs, but I do not have 1 print but 20 prints in total, so 120 x ws2812 leds. all prints are connected with one controller / arduino but I want all prints to do the same. so led1 and led7 led13 led19 do the same as led2, led8, led14 ect. I will add a picture, this is the photo of 1 print with 6 ws2812 LEDs so there are 20 prints of how to make the schedule so that they all do the same.
Loop over all the 120 LEDs, and (assuming the index in the for loop is 'i') take i%6 - that will give you a number from 0~5 corresponding to the position of that led on the board, which you can use to look up what color to make it.
I do not understand it at all but mostly I load file sketch and then change a few things, I often learn well from this, I also understand that when I see it happening. little by little I understand.
When I read this code, I think it says when the first LED starts and how many LEDs are present. is that right? Y++ counts up. I often try it in a schematic and by trying and changing, I quickly find out what it does exactly.
It is quite difficult to create your own LED scheme, for example 2 white 2 red and 2 blue running and if he has done 4 times everything in orange changed as an example. Therefore, working with 00ff00 code seems easier than this but it is good to learn how things can be done differently.
What Larry was asking about was this Modular arithmetic - Wikipedia
It is a way of turning numbers that go on getting bigger into a sequence of numbers from zero to some value that keep cycling. It is a very useful concept if you want to write the sort of code you are trying to write.
//WalkingMarkeeVer2
#include <Adafruit_NeoPixel.h>
#define wait 1000 //viewing time
bool allowWalking = true; //true >>>---> allows the colors to walk
// false >>>---> stationary
#define ledCount 12 //total number of LEDs <----<<< change to 120, when all LEDs are attached
#define PIN 6 //output pin to the LED strip
#define LEDsPerBoard 6 //number of LEDs on a PCB
int offset = 0; //offset or index into colourArray[]
unsigned long colourArray[] = //colour code sequence
{
//example 1:
//red green blue pink yellow white cyan orange black
//0xFF0000, 0x00FF00, 0x0000FF, 0xFF00FF, 0xFF7F00, 0xFFFFFF, 0x00FFFF, 0xFF3000, 0x000000
//example 2:
//red green blue white
//0xFF0000, 0x00FF00, 0x0000FF, 0xFFFFFF
//example 3:
//red red green green blue blue pink pink white white
//0xFF0000, 0xFF0000, 0x00FF00, 0x00FF00, 0x0000FF, 0x0000FF, 0xFF00FF, 0xFF00FF, 0xFFFFFF, 0xFFFFFF
//example 4:
//red green blue pink yellow white
0x3F0000, 0x003F00, 0x00003F, 0x3F003F, 0x3F3F00, 0x3F3F3F //dimmer
//example 5:
//red green blue pink yellow white
//0xFF0000, 0x00FF00, 0x0000FF, 0xFF00FF, 0xFF7F00, 0xFFFFFF //bright
};
//how many colours do we have
const byte availableColors = sizeof(colourArray) / sizeof(unsigned long);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(ledCount, PIN, NEO_GRB + NEO_KHZ800);
//***********************************************************************************
void setup()
{
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}// END of setup()
//***********************************************************************************
void loop()
{
//cycle through all the colours
for (byte colourSelect = 0; colourSelect < availableColors; colourSelect++)
{
//fill the pixel array memory
for (byte ledNumber = 0; ledNumber < ledCount; ledNumber++)
{
strip.setPixelColor(ledNumber, colourArray[offset]);
//the next index/offset into colourArray[]
offset++;
offset = offset % availableColors;
}// END of for()
//send the pixel array memory to the LEDs
strip.show();
//give some time to view the strip
delay(wait);
//*********************
//move to the next item in colourArray[]
if (allowWalking == true)
{
offset = colourSelect;
}
//*********************
}// END of for()
}// END of loop()
//***********************************************************************************