Hi Community. I am new to Seeeduino XIAO and just received my first three units. I ordered them, because I needed a smaller alternative to a Wemos D1 mini to control several LEDs in an RC model.
I am trying to fade in and out eight LEDs independant of each other. I do the fading by setting the desired duration of the fade process, and then using millis() and setting the LED brightness according to the time elapsed.
The brightness is set by analogWrite(Pin, Brightness_between_0_and_255).
The code worked perfect on the Wemos D1 Mini.
What I discovered on the XIOA however is, that A5 and A8 seem to influence each other. No matter what brightness I write to A5, it will change the brighness of both A5 and A8 and vice versa.
I verified this by writing a sketch that sets all LEDs on the analog Pins 1,2,3,4,5,6,7, and 8 to full brightness (255) and then just repeatedly fading out and in the LED on PIN 5. However, the result ist both LEDs on Pin 5 and Pin 8 fading synchronously.
Is this supposed to be normal? All three units do the same .
Here is a video of what happens. The only LED that is controlled by my code is the one on A5.
Here is my code:
// macros for LED state
#define ON true
#define OFF false
// define LED PIN
const byte LED_PIN = A5;
bool ledState = OFF;
unsigned long fadeStartTime;
// parameters to control the effect
unsigned long FADE_IN_PERIOD = 1000; // fade in time
unsigned long ON_DURATION = 500; // time before we move to next LED
unsigned long FADE_OUT_PERIOD = 3000; // fade out time
int brightness;
void setup() {
// set A1through A8 as OUTPUT and to 255 brightness:
pinMode(A1, OUTPUT);
analogWrite(A1, 255);
pinMode(A2, OUTPUT);
analogWrite(A2, 255);
pinMode(A3, OUTPUT);
analogWrite(A3, 255);
pinMode(A4, OUTPUT);
analogWrite(A4, 255);
pinMode(A5, OUTPUT);
analogWrite(A5, 255);
pinMode(A6, OUTPUT);
analogWrite(A6, 255);
pinMode(A7, OUTPUT);
analogWrite(A7, 255);
pinMode(A8, OUTPUT);
analogWrite(A8, 255);
// initialize fading
fadeStartTime = millis();
}
void loop() {
// only the LED on LED_PIN (=A5) is faded in and out by this code:
unsigned long progress = millis() - fadeStartTime;
if (ledState == OFF)
{
// LED is off, we're fading out
if (progress <= FADE_OUT_PERIOD) {
brightness = 255 - (map(progress, 1, FADE_OUT_PERIOD, 0, 255));
}
else
{
ledState = ON;
fadeStartTime = millis();
}
}
else {
// LED is on, we're fading in
if (progress <= FADE_IN_PERIOD) {
brightness = map(progress, 0, FADE_IN_PERIOD, 0, 255);
}
else{
if (progress <= (FADE_IN_PERIOD + ON_DURATION)) {
//do nothing LEDwill remain on
}
else
{
// start fade out
ledState = OFF;
fadeStartTime = millis();
}
}
}
analogWrite(LED_PIN, brightness);
}