Hello, I am new to Arduino, I have read several tutorials and documentation about all of this but I am not really understanding it all. I have an issue where my servos work great so long as I am not using the LEDs (Which are controlled by Neopixel). As soon as I introduce the LED code it causes the LEDs to jitter uncontrollably.
Here is the code I am currently using. I read an article that suggested that these 2 libraries are not compatible but it was over my head from a coding standpoint as I am trying to learn. Also, it was from 2014 so I was hopeful that this was fixed since then or there was a better way to handle it.
//========================================
// ---------------LIBRARIES---------------
//========================================
#include <Servo.h> // Get Servo library
#include <Adafruit_NeoPixel.h> // Get NeoPixel library for WS2812B LEDs
//========================================
// ---------------CONSTANTS---------------
//========================================
// Assign arduino pins for Servos
const int servoPin_Neck = 5; // Lowest Neck Segment pan servo is on this pin (FS5103R Continuous Rotation Servo)
const int servoPin_DrivePlate = 6; // Drive Plate (Eye Segment) pan servo is on this pin (FS5103R Continuous Rotation Servo)
const int servoPin_EyeTilt = 7; // Eye Tilt pan servo is on this pin (9 gram SG90 180 Deg rotation Servo)
const int servoPin_SensorSegment = 8; // Sensor Segment pan servo is on this pin (FS5103R Continuous Rotation Servo)
// Assign arduino pins for LEDs
#define LED_Pin 4 // Pixels are on this pin
#define LED_Num 11 // Number of LEDs
//======================================
unsigned long currentMicros = 0; // Current Time
// Create Objects to attach servos and LEDs to.
Servo servo_Neck;
Servo servo_DrivePlate;
Servo servo_EyeTilt;
Servo servo_SensorSegment;
Adafruit_NeoPixel LEDs(LED_Num, LED_Pin, NEO_GRB + NEO_KHZ800);
//======================================
//======================================
void setup() {
servo_Neck.write(85); //85 or 86
servo_Neck.attach(servoPin_Neck); // Attach the servo to the pin
servo_DrivePlate.write(85); //85
servo_DrivePlate.attach(servoPin_DrivePlate); // Attach the servo to the pin
servo_EyeTilt.write(90);
servo_EyeTilt.attach(servoPin_EyeTilt); // Attach the servo to the pin
servo_SensorSegment.write(85); //84 or 85
servo_SensorSegment.attach(servoPin_SensorSegment); // Attach the servo to the pin
// LED setup
LEDs.begin(); // INITIALIZE NeoPixel pixels object
LEDs.show(); // Turn OFF all pixels
}
//======================================
//======================================
void loop() {
// IdleState_LEDs();
IdleState_Neck();
IdleState_DrivePlate();
IdleState_SensorSegment();
}
//======================================
//==================================================================================================================
//------- IDLE STATE FUNCTIONS ---------
//==================================================================================================================
void IdleState_LEDs() {
uint32_t reddim = LEDs.Color(255, 0, 0); // create color "reddim"
LEDs.fill(reddim, 0, LED_Num); // Change all LED values to reddim
LEDs.setBrightness(5);
LEDs.show(); // Change LEDs
}
//=====================
void IdleState_Neck() {
servo_Neck.write(85); //
}
//=====================
void IdleState_DrivePlate() {
servo_DrivePlate.write(85); //
}
//=====================
void IdleState_SensorSegment() {
servo_SensorSegment.write(85); //
}