On the same Arduino 2 programs for two different pins

Hello,

My name is Michael, I'm working on a project for my Cosplay association. I have the codes but I'm struggling a bit.

I managed to put the first code that runs on pin 6 and 7 but I would like (on the same arduino), that a different code runs on pin 8.

Here is the 1st code

#include <bitswap.h>
#include <chipsets.h>
#include <color.h>
#include <colorpalettes.h>
#include <colorutils.h>
#include <controller.h>
#include <cpp_compat.h>
#include <dmx.h>
#include <FastLED.h>
#include <fastled_config.h>
#include <fastled_delay.h>
#include <fastled_progmem.h>
#include <fastpin.h>
#include <fastspi.h>
#include <fastspi_bitbang.h>
#include <fastspi_dma.h>
#include <fastspi_nop.h>
#include <fastspi_ref.h>
#include <fastspi_types.h>
#include <hsv2rgb.h>
#include <led_sysdefs.h>
#include <lib8tion.h>
#include <noise.h>
#include <pixelset.h>
#include <pixeltypes.h>
#include <platforms.h>
#include <power_mgt.h>

// For led chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806, define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 6
#define DATA_PIN1 7

// How many leds in your strip?
#define NUM_LEDS 17
// Define the array of leds
CRGB leds[NUM_LEDS];

//Deuxiem

void setup() {
// put your setup code here, to run once:

FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.addLeds<WS2812B, DATA_PIN1, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}

void loop() {

// Demarrage
for (int i = 0; i < 2; i++) {
// First slide the led in one direction
for (int i = 0; i < NUM_LEDS; i++) {
// Set the i'th led to
leds[i] = CRGB::Blue;
// Show the leds
FastLED.show();
// now that we've shown the leds, reset the i'th led to black
leds[i] = CRGB::Blue;
// Wait a little bit before we loop around and do it again
delay(80);
}

// Now go in the other direction.
for (int i = NUM_LEDS - 1; i >= 0; i--) {
  // Set the i'th led to red
  leds[i] = CRGB::Blue;
  // Show the leds
  FastLED.show();
  // now that we've shown the leds, reset the i'th led to black
  leds[i] = CRGB::Blue;
  // Wait a little bit before we loop around and do it again
 delay(15);
}

}

//Battements de coeur
for (int j = 0; j < 3; j++ ) {
// Fade IN
for (int k = 0; k < 256; k++) {
setAll(0, 0, k);
FastLED.show();
delay(3);
}
// Fade OUT
for (int k = 255; k >= 0; k--) {
setAll(0, 0, k);
FastLED.show();
delay(3);
}

}
}

/**
Default functions
*/
void setAll(byte red, byte green, byte blue) {
for (int i = 0; i < NUM_LEDS; i++ ) {
leds[i] = CRGB(red, green, blue);
}
FastLED.show();
}

Here is the 2nd code

#include <bitswap.h>
#include <chipsets.h>
#include <color.h>
#include <colorpalettes.h>
#include <colorutils.h>
#include <controller.h>
#include <cpp_compat.h>
#include <dmx.h>
#include <FastLED.h>
#include <fastled_config.h>
#include <fastled_delay.h>
#include <fastled_progmem.h>
#include <fastpin.h>
#include <fastspi.h>
#include <fastspi_bitbang.h>
#include <fastspi_dma.h>
#include <fastspi_nop.h>
#include <fastspi_ref.h>
#include <fastspi_types.h>
#include <hsv2rgb.h>
#include <led_sysdefs.h>
#include <lib8tion.h>
#include <noise.h>
#include <pixelset.h>
#include <pixeltypes.h>
#include <platforms.h>
#include <power_mgt.h>

// For led chips like Neopixels, which have a data line, ground, and power, you just

#define DATA_PIN2 8

// How many leds in your strip?
#define NUM_LEDS 77
// Define the array of leds
CRGB leds[NUM_LEDS];

//Deuxiem

void setup() {
// put your setup code here, to run once:

FastLED.addLeds<WS2812B, DATA_PIN2, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );

}

void loop() {

// Demarrage
for (int i = 0; i < 2; i++) {
// First slide the led in one direction
for (int i = 0; i < NUM_LEDS; i++) {
// Set the i'th led to
leds[i] = CRGB::Green;
// Show the leds
FastLED.show();
// now that we've shown the leds, reset the i'th led to black
leds[i] = CRGB::Black;
// Wait a little bit before we loop around and do it again
delay(30);
}

// Now go in the other direction.
for (int i = NUM_LEDS - 1; i >= 0; i--) {
  // Set the i'th led to red
  leds[i] = CRGB::Green;
  // Show the leds
  FastLED.show();
  // now that we've shown the leds, reset the i'th led to black
  leds[i] = CRGB::Green;
  // Wait a little bit before we loop around and do it again
  //delay(30);
}

}

//Battements de coeur
for (int j = 0; j < 3; j++ ) {
// Fade IN
for (int k = 0; k < 256; k++) {
setAll(0, k, 0);
FastLED.show();
delay(1);
}
// Fade OUT
for (int k = 255; k >= 0; k--) {
setAll(0, k, 0);
FastLED.show();
delay(1);
}

}
}

/**
Default functions
*/
void setAll(byte red, byte green, byte blue) {
for (int i = 0; i < NUM_LEDS; i++ ) {
leds[i] = CRGB(red, green, blue);
}
FastLED.show();
}

If you have an idea I'm interested!

Thanks in advance for reading my post :3

Relar

To make an Arduino do multiple things at once, use millis() for timing:
Using millis() for timing | Multi-tasking the Arduino - Part 1 | Adafruit Learning System
There are multiple pages but I think two will give you enough info to fix your project.

Please read the sticky notes at the top of the forum and post both programs again in code tags so they are readable and can be copied.

Basically

Use the IDE auto format tool, then use “copy for forum” before lasting here.

Now… do you have each program working separately?

And you want them both to run at once, so the Arduino is making one effect on some LEDs and a different effect on some others?

Post a link to where these programs came from originally. You have a crap-ton of include *.h files which looks very odd… usually one only needs fastled.h and mebbe one or two other common headers.

Perhaps the easiest and fastest route to success, and the one requiring the least learning, is to simply put two Arduinos into service, one for each set of LEDs.

Getting two naively written LED effect programs running at the same time on one processor can be an effort varying from dead simple to, well, not so simple at all if you are new to programming.

Which is why we’d like to be able to see and play with the two programs.

Not impossible, just might take a change in perspective to a method of programming @er_name_not_found has already pointed you towards.

HTH

a7

The code is including every header file in the FastLED library src directory, only fastled.h is needed, the others will be included by the library itself.

Using millis timing with multiple strips of leds is going to be somewhat inaccurate, because the millis timer cannot run while sending data to the led strips. FastLED attempts to adjust for the lost time, but something short like 3 milliseconds is going to be difficult because updating a strip of 77 LEDS takes 2.31mS.

Thank you so much I will look into it!

@david_2018 Using millis timing with multiple strips of leds is going to be somewhat inaccurate


Word. I wrote a workaround for that, see this thread for ideas:

I have used this and variations on it as necessary on other microprocessors, basically find a peripheral timer counter to spare and set it up as a free running counter and consult that for assessment of the passage of real time.

a7

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.