I have the problem, that I want a non blocking Servo-movement. I want other code to be processed while the servos are moving. I found out, that FastLED.show() causes the servos to jump and jitter all the time. For example, this code runs perfectly well:
But if I comment in the last line (FastLED.show()) the entire Servo movement goes completely nuts. Even the servo2 (connected to another pin and only attached never moved) starts to jump forth and back as soon as FastLED.show() is commented in. Do you have any idea how that can be solved? Or: Can someone at least tell me the cause of this?
Code:
#include <Servo.h>
#include <FastLED.h>
#define SERVO1_PIN 5
#define SERVO2_PIN 4
#define NUM_LEDS 10
#define LEDS_PIN 8
Servo servo1;
Servo servo2;
int pos=0;
int directionOfServo=1;
uint8_t clr=0;
int counter=0;
CRGB leds[NUM_LEDS];
void setup() {
servo1.attach(SERVO1_PIN);
servo2.attach(SERVO2_PIN);
FastLED.addLeds<WS2812, LEDS_PIN, RGB>(leds, NUM_LEDS);
Serial.begin(9600);
}
void loop()
{
counter++;
if(counter>=10000) {
Serial.print("Counter:");Serial.println(counter);
counter=0;
pos=pos+(directionOfServo*10);
if(pos==180 || pos==0) {
directionOfServo=directionOfServo*-1;
}
servo1.write(pos);
}
clr++;
for(int i=0;i<NUM_LEDS;i++) {
leds[i]=CHSV(clr,244,255);
}
//FastLED.show();
}