millus before delay

I cant get this program to work using millus timing and delay timing for fading and flashing neopixel and leds any help would be appreciated.

the void loop looks like this

void loop(){
time = millis();
value = 128+127cos(2PI/periodetime);
value2 = 128+127
cos(2PI/periode(displace-time));
analogWrite(ledpin, value); // sets the value (range from 0 to 255)
analogWrite(ledpin2, value2); } // sets the value (range from 0 to 255)

{
rgbFadeInAndOut(0, 0, 255, ledFadeTime); // Blue
}

void rgbFadeInAndOut(uint8_t red, uint8_t green, uint8_t blue, uint8_t wait) {
for(uint8_t b = 0; b <255; b++) {
for(uint8_t i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, red * b/255, green * b/255, blue * b/255);
}

strip.show();
delay(10);
};

for(uint8_t b=255; b > 0; b–) {
for(uint8_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, red * b/255, green * b/255, blue * b/255);
}
strip.show();
delay(10);
{
// Turn the LED on, then pause

{
if (millis() - waitTime > lastTime) // time for a new flash
{
// adjust timing params
lastTime += waitTime;
waitTime = random(BETWEEN);

for (int i=0; i< random(TIMES); i++)
{
Serial.println(millis());

leds[0] = CRGB::White;
FastLED.show();
delay(20 + random(DURATION));
leds[0] = CRGB::Black;
FastLED.show();
delay(10);
}
}
}
}
{

};
}

You've got bigger problems than that. Why don't you hit a couple of tutorials and find out what all those braces { and } are all about. You seem to be dropping them in there sort of at random. They have a particular purpose and once you figure that out maybe you can write some code that we can work with.

To assist in Delta_G’s suggestion I recommend that you do a Tools > Auto Format on your sketch. The automatic indentation will help you to see what is happening with your braces as well as making it easier for others to read your code.

Also, please use code tags(</> button) when posting code or warnings/error messages. Post your entire sketch rather than just one part of it.

Hi,

Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html
then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks… Tom… :slight_smile:

Is this what you want?

void loop()
{ 
	time = millis();
	value = 128+127*cos(2*PI/periode*time);
	value2 = 128+127*cos(2*PI/periode*(displace-time));
	analogWrite(ledpin, value);           // sets the value (range from 0 to 255) 
	analogWrite(ledpin2, value2);          // sets the value (range from 0 to 255) 

	rgbFadeInAndOut(0, 0, 255, ledFadeTime); // Blue
}

void rgbFadeInAndOut(uint8_t red, uint8_t green, uint8_t blue, uint8_t wait) 
{
	for(uint8_t b = 0; b <255; b++) {
		for(uint8_t i=0; i < strip.numPixels(); i++) {
			strip.setPixelColor(i, red * b/255, green * b/255, blue * b/255);
		}

		strip.show();
		delay(10);
	}

	for(uint8_t b=255; b > 0; b--) {
		for(uint8_t i = 0; i < strip.numPixels(); i++) {
			strip.setPixelColor(i, red * b/255, green * b/255, blue * b/255);
		}
		strip.show();
		delay(10);
		
		// Turn the LED on, then pause

		
		if (millis() - waitTime > lastTime)  // time for a new flash
		{
			// adjust timing params
			lastTime += waitTime;
			waitTime = random(BETWEEN);

			for (int i=0; i< random(TIMES); i++)
			{
				Serial.println(millis());
				
				leds[0] = CRGB::White;
				FastLED.show();
				delay(20 + random(DURATION));
				leds[0] = CRGB::Black;
				FastLED.show();
				delay(10);
			}
		}
	}

}

Are you using floats? They're slow, like 100x slower than 32-bit integers.

strip.setPixelColor(i, red * b/255, green * b/255, blue * b/255);

Divide those by 256, not 255.

unsigned int x = 4321;

x = x >> 8; // divides x by 256 very fast

thank you for your help and sorry for my bad posting.

the full code is this

#include <Adafruit_NeoPixel.h>
#include "FastLED.h"
int PIN = 3;
int totalLEDs = 11;
int ledFadeTime = 5;
int value, value2 ;
int ledpin = 10;                           // light connected to digital pin 10
int ledpin2 = 11;                           // light connected to digital pin 11
long time = 0;

int periode = 2000;
int displace = 500;


// How many leds in your strip?
#define NUM_LEDS 1

// 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 3
#define CLOCK_PIN 13
#define BETWEEN 2579
#define DURATION 43
#define TIMES 7
// Define the array of leds
CRGB leds[NUM_LEDS];
unsigned long lastTime = 0;
int waitTime = 0;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(totalLEDs, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop()


void loop()
{
  time = millis();
  value = 128 + 127 * cos(2 * PI / periode * time);
  value2 = 128 + 127 * cos(2 * PI / periode * (displace - time));
  analogWrite(ledpin, value);           // sets the value (range from 0 to 255)
  analogWrite(ledpin2, value2);          // sets the value (range from 0 to 255)
}
rgbFadeInAndOut(0, 0, 255, ledFadeTime); // Blue


void rgbFadeInAndOut(uint8_t red, uint8_t green, uint8_t blue, uint8_t wait)
{
  for (uint8_t b = 0; b < 255; b++) {
    for (uint8_t i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, red * b / 255, green * b / 255, blue * b / 255);
    }

    strip.show();
    delay(10);
  }

  for (uint8_t b = 255; b > 0; b--) {
    for (uint8_t i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, red * b / 255, green * b / 255, blue * b / 255);
    }
    strip.show();
    delay(10);

    // Turn the LED on, then pause


    if (millis() - waitTime > lastTime)  // time for a new flash
    {
      // adjust timing params
      lastTime += waitTime;
      waitTime = random(BETWEEN);

      for (int i = 0; i < random(TIMES); i++)
      {
        Serial.println(millis());

        leds[0] = CRGB::White;
        FastLED.show();
        delay(20 + random(DURATION));
        leds[0] = CRGB::Black;
        FastLED.show();
        delay(10);
      }
    }
  }

}

and the current errors are

ino:42:1: error: expected initializer before 'void'
ino:50:16: error: expected constructor, destructor, or type conversation before '(' token

the first section is to fade a normal led with out interfering or interrupting the neopixel code of vice a versa.
the second and third section is to have neopixels fade bule the same as the normal led but with random flashes of white to simulate a lightning effect.

many thanks in advance for any help.

void loop()


void loop()
{

So good, they named it twice?

Justicar_leStat: ...

the full code is this

...
void loop()

void loop() {  time = millis();  value = 128 + 127 * cos(2 * PI / periode * time);  value2 = 128 + 127 * cos(2 * PI / periode * (displace - time));  analogWrite(ledpin, value);           // sets the value (range from 0 to 255)  analogWrite(ledpin2, value2);          // sets the value (range from 0 to 255) } rgbFadeInAndOut(0, 0, 255, ledFadeTime); // Blue ...




and the current errors are



ino:42:1: error: expected initializer before 'void' ino:50:16: error: expected constructor, destructor, or type conversation before '(' token ```

the first section is to fade a normal led with out interfering or interrupting the neopixel code of vice a versa. the second and third section is to have neopixels fade bule the same as the normal led but with random flashes of white to simulate a lightning effect.

many thanks in advance for any help.

I can see two errors in the part of your code I quoted. There are two declarations of the function loop(), and there is a line of code that is outside of the (second) loop function, that you might have intended to be in the function.

Fix those, then attempt recompilation.

some has been fixed now but there is a new error

void loop()
{
  time = millis();
  value = 128 + 127 * cos(2 * PI / periode * time);
  value2 = 128 + 127 * cos(2 * PI / periode * (displace - time));
  analogWrite(ledpin, value);           // sets the value (range from 0 to 255)
  analogWrite(ledpin2, value2);          // sets the value (range from 0 to 255)
}
{
rgbFadeInAndOut(0, 0, 255, ledFadeTime); // Blue
void rgbFadeInAndOut(uint8_t red, uint8_t green, uint8_t blue, uint8_t wait)

  for (uint8_t b = 0; b < 255; b++) {
    for (uint8_t i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, red * b / 255, green * b / 255, blue * b / 255);
    }

    strip.show();
    delay(10);
  }
}

the new error is

  analogWrite(ledpin2, value2);          // sets the value (range from 0 to 255)
}
{
rgbFadeInAndOut(0, 0, 255, ledFadeTime); // Blue

Why are the braces there?

Try this

#include <Adafruit_NeoPixel.h>
#include "FastLED.h"
int PIN = 3;
int totalLEDs = 11;
int ledFadeTime = 5;
int value, value2 ;
int ledpin = 10;                           // light connected to digital pin 10
int ledpin2 = 11;                           // light connected to digital pin 11
long time = 0;

int periode = 2000;
int displace = 500;


// How many leds in your strip?
#define NUM_LEDS 1

// 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 3
#define CLOCK_PIN 13
#define BETWEEN 2579
#define DURATION 43
#define TIMES 7
// Define the array of leds
CRGB leds[NUM_LEDS];
unsigned long lastTime = 0;
int waitTime = 0;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(totalLEDs, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
	FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
	strip.begin();
	strip.show(); // Initialize all pixels to 'off'
}

void loop()
{
	time = millis();
	value = 128 + 127 * cos(2 * PI / periode * time);
	value2 = 128 + 127 * cos(2 * PI / periode * (displace - time));
	analogWrite(ledpin, value);           // sets the value (range from 0 to 255)
	analogWrite(ledpin2, value2);          // sets the value (range from 0 to 255)

	rgbFadeInAndOut(0, 0, 255, ledFadeTime); // Blue
}

void rgbFadeInAndOut(uint8_t red, uint8_t green, uint8_t blue, uint8_t wait)
{
	for (uint8_t b = 0; b < 255; b++) {
		for (uint8_t i = 0; i < strip.numPixels(); i++) {
			strip.setPixelColor(i, red * b / 255, green * b / 255, blue * b / 255);
		}

		strip.show();
		delay(10);
	}

	for (uint8_t b = 255; b > 0; b--) {
		for (uint8_t i = 0; i < strip.numPixels(); i++) {
			strip.setPixelColor(i, red * b / 255, green * b / 255, blue * b / 255);
		}
		strip.show();
		delay(10);

		// Turn the LED on, then pause


		if (millis() - waitTime > lastTime)  // time for a new flash
		{
			// adjust timing params
			lastTime += waitTime;
			waitTime = random(BETWEEN);

			for (int i = 0; i < random(TIMES); i++)
			{
				Serial.println(millis());

				leds[0] = CRGB::White;
				FastLED.show();
				delay(20 + random(DURATION));
				leds[0] = CRGB::Black;
				FastLED.show();
				delay(10);
			}
		}
	}

}

sorry, the new error is expected unqualified-id before '{' token

it is referring to the { at the beginning of the neopixel fade code

it compiles but with a test led and neopeixel the led is still being effected by the loop of the neopixel fade.