I'm sorry, but I have NO idea how to code.
I'm looking to turn 9 LEDs on sequentially, then run 3 neopixels with random colour outputs.
Ive got two working codes, but I can not combine them.
Either the NEOPixels blink, or the 9 white LEDS turn on sequentually.
Any coders here able to help a total noob please?
#include <Adafruit_NeoPixel.h>
#define PIN 11 // input pin Neopixel is attached to
#define NUMPIXELS 3 // number of neopixels in strip
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 10; // timing delay in milliseconds
int redColor = 0;
int greenColor = 0;
int blueColor = 0;
void setup1() { // Initialize the NeoPixel library.
pixels.begin();
}
void loop1() {
setColor();
for (int i=0; i < NUMPIXELS; i++) {
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(redColor, greenColor, blueColor));
// This sends the updated pixel color to the hardware.
pixels.show();
// Delay for a period of time (in milliseconds).
delay(delayval);
}
}
// setColor()
// picks random values to set for RGB
void setColor(){
redColor = random(0, 0);
greenColor = random(100,255);
blueColor = random(200, 255);
}
void setup() {
// put your setup code here, to run once:
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
}
void loop() {
// analogWrite(3, brightness);
ledStart();
delay(1000);
engineStartSection1(11);
delay(500);
engineStartSection2(11);
delay(500);
engineStartSection4(11);
delay(2000);
digitalWrite(10,HIGH);
delay(1000);
// engine4();
}
void engineStartSection1(int led){
for(int i = 0; i < 100; i++){
analogWrite(led, i);
delay(40);
}
delay(50);
for(int i = 100; i > 11; i--){
analogWrite(led, i);
delay(40);
}
}
void engineStartSection2(int led){
for(int i = 11; i < 250; i++){
analogWrite(led, i);
delay(5);
}
delay(100);
for(int i = 250; i > 10; i--){
analogWrite(led, i);
delay(30);
}
}
void engineStartSection4(int led){
for(int i = 50; i < 200; i++){
analogWrite(led, i);
delay(10);
}
delay(100);
for(int i = 250; i > 200; i--){
analogWrite(led, i);
delay(10);
}
}
void engine4(){
while(true){
int randomNumber = random(150,230);
analogWrite(11, randomNumber);
delay(100);
}
}
void ledStart(){
for(int i = 2; i < 10; i++){
digitalWrite(i,HIGH);
delay(1000);
}
}`Preformatted text`
Which Arduino board do you use ?
Are 3 NeoPixel leds connected to pin 11 ?
Are the pins 2 up to 10 used for 9 white leds ?
Is nothing else connected to the Arduino board ?
When writing a sequence in code with delay(), then it is not possible to do something else at the same time. That is no problem if you first turn on the 9 white leds sequentially and after that put a random color on the NeoPixel leds.
Which Arduino board do you use ?
Uno R3, but hoping to rum them on a Nano for a model.
Are 3 NeoPixel leds connected to pin 11 ?
Yes
Are the pins 2 up to 10 used for 9 white leds ?
Yes
Is nothing else connected to the Arduino board ?
Nothing else is connected.
I tried the NEOPixel code after the 9 LEDs, but the code just wouldnt work. Sorry I didnt post that one here as I scrapped it and just posted the individual sections. I had the 9 light up in sequence, then called up a rewritten Engine4 loop that reported no errors, but didn't light up the NEO's.
Your sketch raises some questions and I didn't know what to do with it.
Is it okay if I give something that works, then you can continue with my sketch.
// 9 March 2022
// For: https://forum.arduino.cc/t/multiple-led-neopixel/967303
#include <Adafruit_NeoPixel.h>
const int ledPins[9] = { 2, 3, 4, 5, 6, 7, 8, 9, 10};
#define PIN 11 // input pin Neopixel is attached to
#define NUMPIXELS 3 // number of neopixels in strip
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 100; // timing delay in milliseconds
void setup()
{
// ---------------------------------
// Nine white leds
// ---------------------------------
for( int i=0; i<9; i++)
{
pinMode( ledPins[i], OUTPUT);
}
// ---------------------------------
// Three Neopixel leds
// ---------------------------------
pixels.begin();
}
void loop()
{
// ---------------------------------
// Nine white leds
// ---------------------------------
for( int i=0; i<9; i++)
{
digitalWrite( ledPins[i], HIGH); // turn led on
delay( 150);
}
// ---------------------------------
// Three Neopixel leds
// ---------------------------------
for( int j=0; j<20; j++) // a number of times a random color
{
for (int i=0; i < NUMPIXELS; i++)
{
int redColor = random( 0, 256);
int greenColor = random( 0, 256);
int blueColor = random( 0, 256);
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(redColor, greenColor, blueColor));
// This sends the updated pixel color to the hardware.
pixels.show();
// Delay for a period of time (in milliseconds).
delay(delayval);
}
}
// ---------------------------------
// Nine white leds
// ---------------------------------
for( int i=8; i>=0; i--)
{
digitalWrite( ledPins[i], LOW); // turn led off
delay( 150);
}
delay( 500);
}
Ask what you don't understand.
I put that sketch in Wokwi simulation:
To continue with my Wokwi project, log in at Wokwi and save it to your own projects with "Save a copy". Then you (or someone else) can continue with it and give a link to the new Wokwi project, and someone else can continue with that.
Maybe you hoped that setup() and setup1() and then loop() and loop1() would be running at the same time, in parallel? Unfortunately not. setup() and loop() will be executed, but setup1() and loop1() are never called and will never execute.