Skip to main content
Arduino

Return to Question

replaced http://arduino.stackexchange.com/ with https://arduino.stackexchange.com/
Source Link

As the answers to this question this question and this one this one state, setup() and loop() are identical in the way they execute code (apart from the obvious looping function of loop()).

However.

I get different results with following two pieces of code: ###Code run once, in setup()###

/*
 * light_ws2812 library test
 */ 
#include <WS2812.h>
WS2812 LED(1); // 1 LED
 
cRGB value;
void setup() {
 LED.setOutput(13); // Digital Pin 13
 value.b = 0; value.g = 0; value.r = 255; // RGB Value -> Yellow?
 LED.set_crgb_at(0, value); // Set value at LED found at index 0
 LED.sync(); // Sends the value to the LED
}
void loop() {
}

###Code run once, in loop()###

/*
 * light_ws2812 library test
 */ 
#include <WS2812.h>
WS2812 LED(1); // 1 LED
 
cRGB value;
bool hasBeenSet = false;
void setup() {
 LED.setOutput(13); // Digital Pin 13
}
void loop() {
 if (hasBeenSet == false){
 value.b = 0; value.g = 0; value.r = 255; // RGB Value -> Red
 LED.set_crgb_at(0, value); // Set value at LED found at index 0
 LED.sync(); // Sends the value to the LED
 hasBeenSet = true;
 }
}

###The difference:###

The code run in setup() makes the LED flash once with the desired color.
The code run in loop() makes the LED stay lit with the desired color.

With the data being transmitted on pin 13, I can tell (because of the LED on there) in both cases data is being sent only once. With the loop() version I can even disconnect the data line after the color has been set, and it will stay lit.

I can only conclude the same code is executed differently in both cases.

Is there some sort of (soft) power reset after setup()? That could be a potential cause, as the color is stored in volatile memory on the WS2812B (if I'm not mistaken).


Link to the library used: [http://github.com/cpldcpu/light_ws2812][3]

As the answers to this question and this one state, setup() and loop() are identical in the way they execute code (apart from the obvious looping function of loop()).

However.

I get different results with following two pieces of code: ###Code run once, in setup()###

/*
 * light_ws2812 library test
 */ 
#include <WS2812.h>
WS2812 LED(1); // 1 LED
 
cRGB value;
void setup() {
 LED.setOutput(13); // Digital Pin 13
 value.b = 0; value.g = 0; value.r = 255; // RGB Value -> Yellow?
 LED.set_crgb_at(0, value); // Set value at LED found at index 0
 LED.sync(); // Sends the value to the LED
}
void loop() {
}

###Code run once, in loop()###

/*
 * light_ws2812 library test
 */ 
#include <WS2812.h>
WS2812 LED(1); // 1 LED
 
cRGB value;
bool hasBeenSet = false;
void setup() {
 LED.setOutput(13); // Digital Pin 13
}
void loop() {
 if (hasBeenSet == false){
 value.b = 0; value.g = 0; value.r = 255; // RGB Value -> Red
 LED.set_crgb_at(0, value); // Set value at LED found at index 0
 LED.sync(); // Sends the value to the LED
 hasBeenSet = true;
 }
}

###The difference:###

The code run in setup() makes the LED flash once with the desired color.
The code run in loop() makes the LED stay lit with the desired color.

With the data being transmitted on pin 13, I can tell (because of the LED on there) in both cases data is being sent only once. With the loop() version I can even disconnect the data line after the color has been set, and it will stay lit.

I can only conclude the same code is executed differently in both cases.

Is there some sort of (soft) power reset after setup()? That could be a potential cause, as the color is stored in volatile memory on the WS2812B (if I'm not mistaken).


Link to the library used: [http://github.com/cpldcpu/light_ws2812][3]

As the answers to this question and this one state, setup() and loop() are identical in the way they execute code (apart from the obvious looping function of loop()).

However.

I get different results with following two pieces of code: ###Code run once, in setup()###

/*
 * light_ws2812 library test
 */ 
#include <WS2812.h>
WS2812 LED(1); // 1 LED
 
cRGB value;
void setup() {
 LED.setOutput(13); // Digital Pin 13
 value.b = 0; value.g = 0; value.r = 255; // RGB Value -> Yellow?
 LED.set_crgb_at(0, value); // Set value at LED found at index 0
 LED.sync(); // Sends the value to the LED
}
void loop() {
}

###Code run once, in loop()###

/*
 * light_ws2812 library test
 */ 
#include <WS2812.h>
WS2812 LED(1); // 1 LED
 
cRGB value;
bool hasBeenSet = false;
void setup() {
 LED.setOutput(13); // Digital Pin 13
}
void loop() {
 if (hasBeenSet == false){
 value.b = 0; value.g = 0; value.r = 255; // RGB Value -> Red
 LED.set_crgb_at(0, value); // Set value at LED found at index 0
 LED.sync(); // Sends the value to the LED
 hasBeenSet = true;
 }
}

###The difference:###

The code run in setup() makes the LED flash once with the desired color.
The code run in loop() makes the LED stay lit with the desired color.

With the data being transmitted on pin 13, I can tell (because of the LED on there) in both cases data is being sent only once. With the loop() version I can even disconnect the data line after the color has been set, and it will stay lit.

I can only conclude the same code is executed differently in both cases.

Is there some sort of (soft) power reset after setup()? That could be a potential cause, as the color is stored in volatile memory on the WS2812B (if I'm not mistaken).


Link to the library used: [http://github.com/cpldcpu/light_ws2812][3]
There were different colors in the code samples, fixed that. Boy, I should pay more attention..
Source Link
KJdev
  • 175
  • 1
  • 1
  • 5

As the answers to this question and this one state, setup() and loop() are identical in the way they execute code (apart from the obvious looping function of loop()).

However.

I get different results with following two pieces of code: ###Code run once, in setup()###

/*
 * light_ws2812 library test
 */ 
#include <WS2812.h>
WS2812 LED(1); // 1 LED
 
cRGB value;
void setup() {
 LED.setOutput(13); // Digital Pin 13
 value.b = 0; value.g = 255;0; value.r = 255; // RGB Value -> Yellow?
 LED.set_crgb_at(0, value); // Set value at LED found at index 0
 LED.sync(); // Sends the value to the LED
}
void loop() {
}

###Code run once, in loop()###

/*
 * light_ws2812 library test
 */ 
#include <WS2812.h>
WS2812 LED(1); // 1 LED
 
cRGB value;
bool hasBeenSet = false;
void setup() {
 LED.setOutput(13); // Digital Pin 13
}
void loop() {
 if (hasBeenSet == false){
 value.b = 0; value.g = 0; value.r = 255; // RGB Value -> Red
 LED.set_crgb_at(0, value); // Set value at LED found at index 0
 LED.sync(); // Sends the value to the LED
 hasBeenSet = true;
 }
}

###The difference:###

The code run in setup() makes the LED flash once with the desired color.
The code run in loop() makes the LED stay lit with the desired color.

With the data being transmitted on pin 13, I can tell (because of the LED on there) in both cases data is being sent only once. With the loop() version I can even disconnect the data line after the color has been set, and it will stay lit.

I can only conclude the same code is executed differently in both cases.

Is there some sort of (soft) power reset after setup()? That could be a potential cause, as the color is stored in volatile memory on the WS2812B (if I'm not mistaken).


Link to the library used: [http://github.com/cpldcpu/light_ws2812][3]

As the answers to this question and this one state, setup() and loop() are identical in the way they execute code (apart from the obvious looping function of loop()).

However.

I get different results with following two pieces of code: ###Code run once, in setup()###

/*
 * light_ws2812 library test
 */ 
#include <WS2812.h>
WS2812 LED(1); // 1 LED
 
cRGB value;
void setup() {
 LED.setOutput(13); // Digital Pin 13
 value.b = 0; value.g = 255; value.r = 255; // RGB Value -> Yellow?
 LED.set_crgb_at(0, value); // Set value at LED found at index 0
 LED.sync(); // Sends the value to the LED
}
void loop() {
}

###Code run once, in loop()###

/*
 * light_ws2812 library test
 */ 
#include <WS2812.h>
WS2812 LED(1); // 1 LED
 
cRGB value;
bool hasBeenSet = false;
void setup() {
 LED.setOutput(13); // Digital Pin 13
}
void loop() {
 if (hasBeenSet == false){
 value.b = 0; value.g = 0; value.r = 255; // RGB Value -> Red
 LED.set_crgb_at(0, value); // Set value at LED found at index 0
 LED.sync(); // Sends the value to the LED
 hasBeenSet = true;
 }
}

###The difference:###

The code run in setup() makes the LED flash once with the desired color.
The code run in loop() makes the LED stay lit with the desired color.

With the data being transmitted on pin 13, I can tell (because of the LED on there) in both cases data is being sent only once. With the loop() version I can even disconnect the data line after the color has been set, and it will stay lit.

I can only conclude the same code is executed differently in both cases.

Is there some sort of (soft) power reset after setup()? That could be a potential cause, as the color is stored in volatile memory on the WS2812B (if I'm not mistaken).


Link to the library used: [http://github.com/cpldcpu/light_ws2812][3]

As the answers to this question and this one state, setup() and loop() are identical in the way they execute code (apart from the obvious looping function of loop()).

However.

I get different results with following two pieces of code: ###Code run once, in setup()###

/*
 * light_ws2812 library test
 */ 
#include <WS2812.h>
WS2812 LED(1); // 1 LED
 
cRGB value;
void setup() {
 LED.setOutput(13); // Digital Pin 13
 value.b = 0; value.g = 0; value.r = 255; // RGB Value -> Yellow?
 LED.set_crgb_at(0, value); // Set value at LED found at index 0
 LED.sync(); // Sends the value to the LED
}
void loop() {
}

###Code run once, in loop()###

/*
 * light_ws2812 library test
 */ 
#include <WS2812.h>
WS2812 LED(1); // 1 LED
 
cRGB value;
bool hasBeenSet = false;
void setup() {
 LED.setOutput(13); // Digital Pin 13
}
void loop() {
 if (hasBeenSet == false){
 value.b = 0; value.g = 0; value.r = 255; // RGB Value -> Red
 LED.set_crgb_at(0, value); // Set value at LED found at index 0
 LED.sync(); // Sends the value to the LED
 hasBeenSet = true;
 }
}

###The difference:###

The code run in setup() makes the LED flash once with the desired color.
The code run in loop() makes the LED stay lit with the desired color.

With the data being transmitted on pin 13, I can tell (because of the LED on there) in both cases data is being sent only once. With the loop() version I can even disconnect the data line after the color has been set, and it will stay lit.

I can only conclude the same code is executed differently in both cases.

Is there some sort of (soft) power reset after setup()? That could be a potential cause, as the color is stored in volatile memory on the WS2812B (if I'm not mistaken).


Link to the library used: [http://github.com/cpldcpu/light_ws2812][3]
Error in copy-pasting code
Source Link
KJdev
  • 175
  • 1
  • 1
  • 5

As the answers to this question and this one state, setup() and loop() are identical in the way they execute code (apart from the obvious looping function of loop()).

However.

I get different results with following two pieces of code: ###Code run once, in setup()###

/*
 * light_ws2812 library test
 */ 
#include <WS2812.h>
WS2812 LED(1); // 1 LED
 
cRGB value;
void setup() {
 LED.setOutput(13); // Digital Pin 13
 value.b = 0; value.g = 255; value.r = 255; // RGB Value -> Yellow?
 LED.set_crgb_at(0, value); // Set value at LED found at index 0
 LED.sync(); // Sends the value to the LED
}
void loop() {
}

###Code run once, in loop()###

/*
 * light_ws2812 library test
 */ 
#include <WS2812.h>
WS2812 LED(1); // 1 LED
 
cRGB value;
bool hasBeenSet = true;false;
void setup() {
 LED.setOutput(13); // Digital Pin 13
}
void loop() {
 if (hasBeenSet == false){
 value.b = 0; value.g = 0; value.r = 255; // RGB Value -> Red
 LED.set_crgb_at(0, value); // Set value at LED found at index 0
 LED.sync(); // Sends the value to the LED
 hasBeenSet = true;
 }
}

###The difference:###

The code run in setup() makes the LED flash once with the desired color.
The code run in loop() makes the LED stay lit with the desired color.

With the data being transmitted on pin 13, I can tell (because of the LED on there) in both cases data is being sent only once. With the loop() version I can even disconnect the data line after the color has been set, and it will stay lit.

I can only conclude the same code is executed differently in both cases.

Is there some sort of (soft) power reset after setup()? That could be a potential cause, as the color is stored in volatile memory on the WS2812B (if I'm not mistaken).


Link to the library used: [http://github.com/cpldcpu/light_ws2812][3]

As the answers to this question and this one state, setup() and loop() are identical in the way they execute code (apart from the obvious looping function of loop()).

However.

I get different results with following two pieces of code: ###Code run once, in setup()###

/*
 * light_ws2812 library test
 */ 
#include <WS2812.h>
WS2812 LED(1); // 1 LED
 
cRGB value;
void setup() {
 LED.setOutput(13); // Digital Pin 13
 value.b = 0; value.g = 255; value.r = 255; // RGB Value -> Yellow?
 LED.set_crgb_at(0, value); // Set value at LED found at index 0
 LED.sync(); // Sends the value to the LED
}
void loop() {
}

###Code run once, in loop()###

/*
 * light_ws2812 library test
 */ 
#include <WS2812.h>
WS2812 LED(1); // 1 LED
 
cRGB value;
bool hasBeenSet = true;
void setup() {
 LED.setOutput(13); // Digital Pin 13
}
void loop() {
 if (hasBeenSet == false){
 value.b = 0; value.g = 0; value.r = 255; // RGB Value -> Red
 LED.set_crgb_at(0, value); // Set value at LED found at index 0
 LED.sync(); // Sends the value to the LED
 hasBeenSet = true;
 }
}

###The difference:###

The code run in setup() makes the LED flash once with the desired color.
The code run in loop() makes the LED stay lit with the desired color.

With the data being transmitted on pin 13, I can tell (because of the LED on there) in both cases data is being sent only once. With the loop() version I can even disconnect the data line after the color has been set, and it will stay lit.

I can only conclude the same code is executed differently in both cases.

Is there some sort of (soft) power reset after setup()? That could be a potential cause, as the color is stored in volatile memory on the WS2812B (if I'm not mistaken).


Link to the library used: [http://github.com/cpldcpu/light_ws2812][3]

As the answers to this question and this one state, setup() and loop() are identical in the way they execute code (apart from the obvious looping function of loop()).

However.

I get different results with following two pieces of code: ###Code run once, in setup()###

/*
 * light_ws2812 library test
 */ 
#include <WS2812.h>
WS2812 LED(1); // 1 LED
 
cRGB value;
void setup() {
 LED.setOutput(13); // Digital Pin 13
 value.b = 0; value.g = 255; value.r = 255; // RGB Value -> Yellow?
 LED.set_crgb_at(0, value); // Set value at LED found at index 0
 LED.sync(); // Sends the value to the LED
}
void loop() {
}

###Code run once, in loop()###

/*
 * light_ws2812 library test
 */ 
#include <WS2812.h>
WS2812 LED(1); // 1 LED
 
cRGB value;
bool hasBeenSet = false;
void setup() {
 LED.setOutput(13); // Digital Pin 13
}
void loop() {
 if (hasBeenSet == false){
 value.b = 0; value.g = 0; value.r = 255; // RGB Value -> Red
 LED.set_crgb_at(0, value); // Set value at LED found at index 0
 LED.sync(); // Sends the value to the LED
 hasBeenSet = true;
 }
}

###The difference:###

The code run in setup() makes the LED flash once with the desired color.
The code run in loop() makes the LED stay lit with the desired color.

With the data being transmitted on pin 13, I can tell (because of the LED on there) in both cases data is being sent only once. With the loop() version I can even disconnect the data line after the color has been set, and it will stay lit.

I can only conclude the same code is executed differently in both cases.

Is there some sort of (soft) power reset after setup()? That could be a potential cause, as the color is stored in volatile memory on the WS2812B (if I'm not mistaken).


Link to the library used: [http://github.com/cpldcpu/light_ws2812][3]
Fixed a discrepancy between comment and code
Source Link
KJdev
  • 175
  • 1
  • 1
  • 5
Loading
Source Link
KJdev
  • 175
  • 1
  • 1
  • 5
Loading

AltStyle によって変換されたページ (->オリジナル) /