Programm Structur IR, Servo -> Neopixel Problem (strange servo twitch)

Hallo Forum,

i have started a Projekt with an Arduino UNO / Nano to control a Servo and 2 Neopixel Rings (24) with Remote Control.

I am new in Arduino Programming and need some help with a usefull and working programm structur.
Here are my code:

#include <IRremote.h>      
#include <Servo.h>

#define plus 16748655                           //IR Code für Taste
#define minus 16754775                          //IR Code für Taste
#define stops 16736925                          //IR Code für Taste

#define tata 16728765

int RECV_PIN = 2;                               //IR receiver pin
Servo servo;
int val = 90;                                   // bei 360 Grad Servo Stop Position
int button1_PIN = 4;                            // pin für Button1
int button2_PIN = 7;                            // pin für Button2
int button1_STATE = 0;                          // Button1 gedrückt Status
int button2_STATE = 0;                          // Button2 gedrückt Status
int button_PRESSED = 0;                         // Status Button 1=oben, 2=unten, 0=neutral

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();                          // Start the receiver
  servo.attach(9);                              // pin für Servo
  pinMode(button1_PIN, INPUT_PULLUP);
  pinMode(button2_PIN, INPUT_PULLUP);
}

void loop() 
{
  button1_STATE = digitalRead(button1_PIN);
  button2_STATE = digitalRead(button2_PIN);
  Serial.println(button1_STATE);
  Serial.println(button2_STATE);
  Serial.println(button_PRESSED);
  Serial.println(val);

  if (button1_STATE == HIGH && button2_STATE == HIGH && button_PRESSED != 0)    // kein Button gedrückt von Status 1 oder 2
    { 
      button_PRESSED = 0;                               // Button Status auf neutral 0
      irrecv.resume();                                  // Receive the next value
    }
  if (button1_STATE == LOW && button_PRESSED == 0)      // Button oben gedrückt von Status neutral
    { 
      irrecv.resume();   
      button_PRESSED = 1;             // Button Status auf 1
          val = 90; 
          
                                            // Servo aus
                                     // Receive the next value
    }
  if (button2_STATE == LOW && button_PRESSED == 0)      // Button unten gedrückt von Status neutral
    { 
      button_PRESSED = 2;                               // Button Status auf 2
      val = 90;                                         // Servo aus
      irrecv.resume();                                  // Receive the next value
    }

    
  if (irrecv.decode(&results) && button_PRESSED == 1 )  // Wenn RC und Button oben gedrückt -> nur Richtung runter
    {
    Serial.println(results.value, DEC);
    irrecv.resume();                                    // Receive the next value
      if (results.value == minus)                       // IR Taste minus
        { val = 20; }                                  // gedrückt -> Servo lauf runter
      else
        { val = 90; }                                   // gehalten -> Servo 1 Step runter
    }
  if (irrecv.decode(&results) && button_PRESSED == 2 )  // Wenn RC und Button unten gedrückt -> nur Richtung rauf
    {
    Serial.println(results.value, DEC);
    irrecv.resume();                                    // Receive the next value
      if (results.value == plus)                        // IR Taste plus
        { val = 160;}                                    // gedrückt -> Servo lauf rauf
      else
        { val = 90; }                                   // gehalten -> Servo 1 Step rauf
    }
  if (irrecv.decode(&results) && button_PRESSED == 0 )  // Wenn RC und Status neutral -> alle Richtungen
    {
    Serial.println(results.value, DEC);
    irrecv.resume();                                    // Receive the next value
     if (results.value == plus)                        // IR Taste plus
        { val = 160;}                                    // gedrückt -> Servo lauf rauf
      else if (results.value == minus)                  // IR Taste minus
        { val = 20;}  
        
     else if (results.value == tata) 
        {
        val = 90;
        }
    }

  servo.write(val);
  delay(200);                                           // General speed
}

Part 1
Every is working so far.

when i press + on the remote the servo go in direction up till button_1 is low then the servo stop an it also is only possible to press -

when i pres - on the remote the servo go in direction down till button_2 is low thej the servo stop and it is only possible to press +

at the moment everything is in the loop function

Part 2
I want to include 2 NEOPIXEL RINGS RGBW 24 and there should be no problem getting the information form the remote (irrecv.resume():wink:
Also i should be possible to start different themes of the NEOPIXEL RINGS.

My Question:
What is the best structur for the programm?
Should i make several Functions and call them in the loop and how could i have a perfect timing
between remote, servosteps and NEOPIXEL performance.

THX

Can you explain the purpose/intent of the 2 physical buttons versus the remote control?

If the 2 physical buttons are meant to stop an ongoing action, then an idea would be to wire the 2 buttons to the 2 interrupts 0 and 1 and drive the main loop just listening for events from the remote control.

When you press a button, the main loop will be stopped and your interrupt function would be executed which could set some global volatile Boolean values to some value that you check in the main run loop.

Does this make sense?

Here and there is If you want to know more about interrupts

Hi J-M-L

thank you for your reply.

I attached a photo for better understanding about the two buttons.

On the picture you see the current construction.

A carriage moves by a servo (90) from the bottom to the top and back down.
The meaning of the buttons is to make the servo stop at the right time and give a information to the arduino that it is only possible for the servo to go in the other direction.

I think i could use interrupts, i would need a cycle who. looks if Button_1 or Button_2 are LOW and then set the possibilities for the Remote and the servo (90)

Do you have some idees for this function?

A few more questions to understand the exact intent and operational process to offer some ideas:

so if I understand well, the carriage can only go in one direction at any given point in time, right?

Say it starts at bottom position, you press + on the IR remote control and it goes up until you press one hardware button. At that point the carriage needs to stop and is only allowed to go back down, regardless of the fact that it might not have reached the top when you pressed the button?

Then you press the - button on the IR remote, the carriage goes down until you press the second hardware button to stop the carriage. And then the carriage is no longer allowed to go down in can only go up again.

Do I get this right?

If so - why do you need two hardware buttons or two IR remote control buttons? Seems to me that you need one remote control that says "move" (as the direction is imposed anyway) and only one hardware button that says "stop"?

Also out of curiosity why are you using the IR remote if the user has to be close to the unit to press the physical stop button anyway?

Ok here are some Explanations.

  1. the User only use the IR remote control, he can go up, down and stop.

  2. the two buttens are pressed by the carriage, one (bottom is pressed when the carriage hit it, second is pressed (via pull of a string) when the carriage is on top.

  3. the User can change the direction of the carriage while it is in motion, so wenn no button is pressed.

I attached a new picture, so you can see the construction so far.

Here are a possible process:

A: Start the arduino
B: the system looks if a End-switch is pressed
“yes” → it is only allowed to go in the right direction
“no” → any direction is allowed
C: IR Button is pressed
the servo pulls or let go of a string the carriage moves till it hits an End-switch and the servo stops
B: = “yes” → allowed direction
C:

Hope now everything is clear.

c.jpg

d.jpg

Have a look at Planning and Implementing a Program

...R

Hi Robin

thank you for your post.
I have updated my code and the next step is to include the Neopixel Feature.

setNeopixelOn();
setNeopixelOff();
setNeopixelTheme();
setNeopixelBrightness();

#include <IRremote.h>     
#include <Servo.h>

//=== RemoteControl ===
int recvPin = 2;                         	//IR receiver pin
IRrecv irrecv(recvPin);
decode_results results;
#define POWER 0x10EFD827 
#define A 0x10EFF807                      // RCMode = 1
#define B 0x10EF7887                      // RCMode = 2
#define C 0x10EF58A7                      // RCMode = 3
#define UP 0x10EFA05F
#define DOWN 0x10EF00FF
#define LEFT 0x10EF10EF
#define RIGHT 0x10EF807F
#define SELECT 0x10EF20DF
int RCMode = 0;

//=== Servo ===
Servo fullturnServo;                        // 360 C servo turn always
const byte servoPin = 9;                    // servo pin
const byte servoStop = 90;                  // servo stop at 90
const byte servoDown = 60;
const byte servoUp = 120;
byte servoPosition = servoStop;

//=== Switch Buttons ===
const byte TopSwitchPin = 4;
const byte BottomSwitchPin = 7;
byte TopSwitchState;
byte BottomSwitchState;



void setup() {

	Serial.begin(9600);
  irrecv.enableIRIn();                     // receiver start
  
	fullturnServo.attach(servoPin);
	fullturnServo.write(servoPosition);

  pinMode(TopSwitchPin, INPUT_PULLUP);
  pinMode(BottomSwitchPin, INPUT_PULLUP);

	delay(5000);
}


void loop() {
	checkSwitches();
	getIRInput();

	setServoMove();
	setNeopixel();
}


void checkSwitches() {
  	TopSwitchState = digitalRead(TopSwitchPin);
  	BottomSwitchState = digitalRead(BottomSwitchPin);
}


void getIRInput() {

  if (irrecv.decode(&results)) 
  {
    if (results.value == POWER) 
    {
      Serial.println("POWER");    
    }
    
    if (results.value == A) 
    {
      RCMode = 1;
      Serial.println("A");    
    }
    
     if (results.value == B) 
    {
      RCMode = 2;
      Serial.println("B");  
    }
    
     if (results.value == C) 
    {
      RCMode = 3;
      Serial.println("C");
    }
    
     if (results.value == UP) 
     {
        if (RCMode == 1) {
          servoPosition = servoUp;
        }
      Serial.println("UP");
     }
     
     if (results.value == DOWN) 
    {
        if (RCMode == 1) {
          servoPosition = servoDown;
        }
      Serial.println("DOWN");
    }
     if (results.value == LEFT) 
    {
      Serial.println("LEFT");
    }
     if (results.value == RIGHT) 
    {
      Serial.println("RIGHT");
    }
     if (results.value == SELECT) 
    {
      Serial.println("SELECT"); 
      if (RCMode == 1) {
        servoPosition = servoStop;
      }
    }
    irrecv.resume();
  }
}


void setServoMove() {
  if (RCMode == 1) {
   
	  if (TopSwitchState == HIGH && BottomSwitchState == HIGH) {
  		 // servo can go up and down
	  }

	  if (TopSwitchState == LOW) {
		  // servo can only go down
		  servoPosition = servoStop;
      Serial.println("STOP SERVO");
	  }
   
    if (TopSwitchState == LOW && results.value == UP) {
      // servo can only go down
      servoPosition = servoStop;
      Serial.println("STOP SERVO");
    }

    if (TopSwitchState == LOW && results.value == DOWN) {
      // servo can only go down
      servoPosition = servoDown;
      Serial.println("SERVO GO DOWN");
    }
  
    if (BottomSwitchState == LOW) {
      // servo can only go up
      servoPosition = servoStop;
      Serial.println("STOP SERVO");
    }

    if (BottomSwitchState == LOW && results.value == DOWN) {
      // servo can only go up
      servoPosition = servoStop;
      Serial.println("STOP SERVO");
    }
  
    if (BottomSwitchState == LOW && results.value == UP) {
      // servo can only go up
      servoPosition = servoUp;
      Serial.println("SERVO GO UP");
    }
    
    Serial.println(servoPosition);
	  fullturnServo.write(servoPosition);
  }
}


void setNeopixel() {
	setNeopixelOn();
	setNeopixelOff();
	setNeopixelTheme();
	setNeopixelBrightness();
}

void setNeopixelOn(){}
void setNeopixelOff(){}
void setNeopixelTheme(){}
void setNeopixelBrightness(){}

Sly311271:
I have updated my code and the next step is to include the Neopixel Feature.

I assume you have no questions at the moment.

In any case I have no knowledge of neo-pixel things.

It can be very useful while developing a program to include empty functions or very basic functions that just return a fixed value if needed to make other parts of the code work.

...R

HI Robin,

i have now include Neopixel and now the program makes crazy things.

#include <IRremote.h>     
#include <Servo.h>
#include <Adafruit_NeoPixel.h>

//=== RemoteControl ===
int recvPin = 2;                         	//IR receiver pin
IRrecv irrecv(recvPin);
decode_results results;
#define POWER 0x10EFD827 
#define A 0x10EFF807                      // RCMode = 1
#define B 0x10EF7887                      // RCMode = 2
#define C 0x10EF58A7                      // RCMode = 3
#define UP 0x10EFA05F
#define DOWN 0x10EF00FF
#define LEFT 0x10EF10EF
#define RIGHT 0x10EF807F
#define SELECT 0x10EF20DF
int RCMode = 0;

//=== Servo ===
Servo fullturnServo;                        // 360 C servo turn always
const byte servoPin = 9;                    // servo pin
const byte servoStop = 90;                  // servo stop at 90
const byte servoDown = 60;
const byte servoUp = 120;
byte servoPosition = servoStop;

//=== Switch Buttons ===
const byte TopSwitchPin = 4;
const byte BottomSwitchPin = 7;
byte TopSwitchState;
byte BottomSwitchState;

//=== Adafruit NeoPixel Ring - 24 x 5050 RGBW 2x24=48 ===

#define PIN 6
#define NUM_LEDS 8
#define BRIGHTNESS 55
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRBW + NEO_KHZ800);
int gamma[] = {
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,
    1,  1,  1,  1,  1,  1,  1,  1,  1,  2,  2,  2,  2,  2,  2,  2,
    2,  3,  3,  3,  3,  3,  3,  3,  4,  4,  4,  4,  4,  5,  5,  5,
    5,  6,  6,  6,  6,  7,  7,  7,  7,  8,  8,  8,  9,  9,  9, 10,
   10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
   17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
   25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
   37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
   51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
   69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
   90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,
  115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,
  144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
  177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
  215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };


//=== SETUP ===
void setup() {

	Serial.begin(9600);
  irrecv.enableIRIn();                     // receiver start
  
	fullturnServo.attach(servoPin);
	fullturnServo.write(servoPosition);

  pinMode(TopSwitchPin, INPUT_PULLUP);
  pinMode(BottomSwitchPin, INPUT_PULLUP);

  strip.setBrightness(BRIGHTNESS);
  strip.begin();

	delay(5000);
}


void loop() {
	checkSwitches();
	getIRInput();

	setServoMove();
	setNeopixel();
}


void checkSwitches() {
  	TopSwitchState = digitalRead(TopSwitchPin);
  	BottomSwitchState = digitalRead(BottomSwitchPin);
}


void getIRInput() {

  if (irrecv.decode(&results)) 
  {
    if (results.value == POWER) 
    {
      Serial.println("POWER");    
    }
    
    if (results.value == A) 
    {
      RCMode = 1;
      Serial.println("A");    
    }
    
     if (results.value == B) 
    {
      RCMode = 2;
      Serial.println("B");  
    }
    
     if (results.value == C) 
    {
      RCMode = 3;
      Serial.println("C");
    }
    
     if (results.value == UP) 
     {
        if (RCMode == 1) {
          servoPosition = servoUp;
        }
      Serial.println("UP");
     }
     
     if (results.value == DOWN) 
    {
        if (RCMode == 1) {
          servoPosition = servoDown;
        }
      Serial.println("DOWN");
    }
     if (results.value == LEFT) 
    {
      Serial.println("LEFT");
    }
     if (results.value == RIGHT) 
    {
      Serial.println("RIGHT");
    }
     if (results.value == SELECT) 
    {
      Serial.println("SELECT"); 
      if (RCMode == 1) {
        servoPosition = servoStop;
      }
    }
    irrecv.resume();
  }
}


void setServoMove() {
  if (RCMode == 1) {
   
	  if (TopSwitchState == HIGH && BottomSwitchState == HIGH) {
  		 // servo can go up and down
	  }

	  if (TopSwitchState == LOW) {
		  // servo can only go down
		  servoPosition = servoStop;
      Serial.println("STOP SERVO");
	  }
   
    if (TopSwitchState == LOW && results.value == UP) {
      // servo can only go down
      servoPosition = servoStop;
      Serial.println("STOP SERVO");
    }

    if (TopSwitchState == LOW && results.value == DOWN) {
      // servo can only go down
      servoPosition = servoDown;
      Serial.println("SERVO GO DOWN");
    }
  
    if (BottomSwitchState == LOW) {
      // servo can only go up
      servoPosition = servoStop;
      Serial.println("STOP SERVO");
    }

    if (BottomSwitchState == LOW && results.value == DOWN) {
      // servo can only go up
      servoPosition = servoStop;
      Serial.println("STOP SERVO");
    }
  
    if (BottomSwitchState == LOW && results.value == UP) {
      // servo can only go up
      servoPosition = servoUp;
      Serial.println("SERVO GO UP");
    }
    
    Serial.println(servoPosition);
	  fullturnServo.write(servoPosition);
  }
}

void setNeopixel() {
  
    pulseWhite(10); 
}

void pulseWhite(uint8_t wait) {
  for(int j = 0; j < 256 ; j++){
      for(uint16_t i=0; i<24; i++) {
          strip.setPixelColor(i, strip.Color(0,0,0, gamma[j] ) );
          strip.setPixelColor(47-i, strip.Color(0,0,0, gamma[j] ) );
        }
        delay(wait);
        strip.show();
      }

  for(int j = 255; j >= 0 ; j--){
      for(uint16_t i=0; i<strip.numPixels(); i++) {
          strip.setPixelColor(i, strip.Color(0,0,0, gamma[j] ) );
        }
        delay(wait);
        strip.show();
      }
}

The Neopixel do what they should, but i have also

  1. a small twitch and move of the servo
  2. no response from the Remote
    (i thing the neopixel makes the arduino to slow, there is also no info in the Seriell monitor)

Someone has a solution ?

Don't use the delay() function as it blocks everything else. Use millis() to manage timing as illustrated in Several Things at a Time

Don't use FOR loops in the pulseWhite() function - they also block stuff. Let the loop() function take care of the repetition and just use variables to keep count of the iterations.

...R

HI Robin,

i have now updated my sketch

#include <IRremote.h>     
#include <Servo.h>
#include <Adafruit_NeoPixel.h>

// ---------- REMOTE CONTROL CONSTANTS AND VARIABLES START ---------------

#define POWER 0x10EFD827 
#define A 0x10EFF807                        // RCMode = 1
#define B 0x10EF7887                        // RCMode = 2
#define C 0x10EF58A7                        // RCMode = 3
#define UP 0x10EFA05F
#define DOWN 0x10EF00FF
#define LEFT 0x10EF10EF
#define RIGHT 0x10EF807F
#define SELECT 0x10EF20DF
const byte recvPin = 2;                     // IR-receiver pin
byte RCMode = 0;                            // used to record if remote is in state A, B ,C
IRrecv irrecv(recvPin);
decode_results results;

// ---------- REMOTE CONTROL CONSTANTS AND VARIABLES START ---------------


// ---------- 360C SERVO CONSTANTS AND VARIABLES START ---------------

const byte servoPin = 9;                    // servo pin
const byte servoStop = 90;                  // servo stop at 90
const byte servoDown = 60;                  // move left
const byte servoUp = 120;                   // move right

byte servoPosition = servoStop;             // set servo to stop
Servo fullturnServo;                        // create servo object

// ---------- 360C SERVO CONSTANTS AND VARIABLES END ---------------


// ---------- SWITCH BUTTONS CONSTANTS AND VARIABLES START ---------------

const byte TopSwitchPin = 4;                // Button1 on Top pin
const byte BottomSwitchPin = 7;             // Button2 on Bottom pin

byte TopSwitchState;
byte BottomSwitchState;

// ---------- SWITCH BUTTONS CONSTANTS AND VARIABLES END ---------------


// ---------- NEOPIXEL CONSTANTS AND VARIABLES START ---------------
// ---------- Adafruit NeoPixel Ring - 24 x 5050 RGBW 2x24=48 ---------------

const byte neopixelRingPin = 6;
const byte numLEDs = 8;
int brightnessLEDs = 55;

int gamma[] = {
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,
    1,  1,  1,  1,  1,  1,  1,  1,  1,  2,  2,  2,  2,  2,  2,  2,
    2,  3,  3,  3,  3,  3,  3,  3,  4,  4,  4,  4,  4,  5,  5,  5,
    5,  6,  6,  6,  6,  7,  7,  7,  7,  8,  8,  8,  9,  9,  9, 10,
   10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
   17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
   25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
   37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
   51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
   69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
   90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,
  115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,
  144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
  177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
  215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };

Adafruit_NeoPixel rings = Adafruit_NeoPixel(numLEDs, neopixelRingPin, NEO_GRBW + NEO_KHZ800);

// ---------- NEOPIXEL CONSTANTS AND VARIABLES END ---------------


// ---------- FOR MILLIS CONF START ---------------

unsigned long currentMillis = 0;                     //  stores the value of millis() in each iteration of loop()

const int checkSwitches_Interval = 200;              //  if (currentMillis - previous_checkSwitches_Millis >= checkSwitches_Interval) {
unsigned long previous_checkSwitches_Millis = 0;     //  store last timeupdate of checkSwitches

const int neopixel_Interval = 1000;                   //  if (currentMillis - previous_LEDs_Millis >= neopixel_Interval) {
unsigned long previous_LEDs_Millis = 0;              //  store last timeupdate of LED

// ----------FOR MILLIS CONF END ---------------


// ===================== PROGRAM START SETUP ============================
void setup() {

 Serial.begin(9600);
  irrecv.enableIRIn();                            // receiver start
  
 fullturnServo.attach(servoPin);
 fullturnServo.write(servoPosition);

  pinMode(TopSwitchPin, INPUT_PULLUP);
  pinMode(BottomSwitchPin, INPUT_PULLUP);

  rings.setBrightness(brightnessLEDs);
  rings.begin();

 delay(2000);
}


void loop() {

  currentMillis = millis(); 

  
 checkSwitches();
 getIRInput();
 setServoMove();
 setNeopixel();
}


void checkSwitches() {

    if (currentMillis - previous_checkSwitches_Millis >= checkSwitches_Interval) {
    TopSwitchState = digitalRead(TopSwitchPin);
    BottomSwitchState = digitalRead(BottomSwitchPin);

      previous_checkSwitches_Millis += checkSwitches_Interval;
    }
    
}


void getIRInput() {

  if (irrecv.decode(&results)) 
  {
    if (results.value == POWER) 
    {
      Serial.println("POWER");    
    }
    
    if (results.value == A) 
    {
      RCMode = 1;
      Serial.println("A");    
    }
    
     if (results.value == B) 
    {
      RCMode = 2;
      Serial.println("B");  
    }
    
     if (results.value == C) 
    {
      RCMode = 3;
      Serial.println("C");
    }
    
     if (results.value == UP) 
     {
        if (RCMode == 1) {
          servoPosition = servoUp;
        }
      Serial.println("UP");
     }
     
     if (results.value == DOWN) 
    {
        if (RCMode == 1) {
          servoPosition = servoDown;
        }
      Serial.println("DOWN");
    }
     if (results.value == LEFT) 
    {
      Serial.println("LEFT");
    }
     if (results.value == RIGHT) 
    {
      Serial.println("RIGHT");
    }
     if (results.value == SELECT) 
    {
      Serial.println("SELECT"); 
      if (RCMode == 1) {
        servoPosition = servoStop;
      }
    }
    irrecv.resume();
  }
}


void setServoMove() {
  if (RCMode == 1) {
   
  if (TopSwitchState == HIGH && BottomSwitchState == HIGH) {
   // servo can go up and down
  }

  if (TopSwitchState == LOW) {
  // servo can only go down
  servoPosition = servoStop;
      Serial.println("STOP SERVO");
  }
   
    if (TopSwitchState == LOW && results.value == UP) {
      // servo can only go down
      servoPosition = servoStop;
      Serial.println("STOP SERVO");
    }

    if (TopSwitchState == LOW && results.value == DOWN) {
      // servo can only go down
      servoPosition = servoDown;
      Serial.println("SERVO GO DOWN");
    }
  
    if (BottomSwitchState == LOW) {
      // servo can only go up
      servoPosition = servoStop;
      Serial.println("STOP SERVO");
    }

    if (BottomSwitchState == LOW && results.value == DOWN) {
      // servo can only go up
      servoPosition = servoStop;
      Serial.println("STOP SERVO");
    }
  
    if (BottomSwitchState == LOW && results.value == UP) {
      // servo can only go up
      servoPosition = servoUp;
      Serial.println("SERVO GO UP");
    }
    
    Serial.println(servoPosition);
  fullturnServo.write(servoPosition);
  }
}

void setNeopixel() {
  
  if (RCMode == 2) {
    pulseWhite(); 
  }
}


void pulseWhite() {

  if (currentMillis - previous_LEDs_Millis >= neopixel_Interval) {

      Serial.println(previous_LEDs_Millis);
      Serial.println(currentMillis);
      Serial.println(neopixel_Interval);
      previous_LEDs_Millis = currentMillis;
    
      for(int j = 0; j < 256 ; j++){
        for(uint16_t i=0; i<8; i++) {
          rings.setPixelColor(i, rings.Color(0,0,0, gamma[j] ) );
          rings.setPixelColor(47-i, rings.Color(0,0,0, gamma[j] ) );
        }
        rings.show();
      }

    for(int j = 255; j >= 0 ; j--){
      for(uint16_t i=0; i<8; i++) {
          rings.setPixelColor(i, rings.Color(0,0,0, gamma[j] ) );
        }
        rings.show();
     }
  }
}

The use of millis is a great feature but i sill have the problem with servo twitches.

I still have the for loops because i have no idee how to manage that with millis???

I can not imagine why this have an impact on the servo?

I have a already tried to power the Neopixel with an extra power power supply,

and to power the Servo with an extra power power supply.

I allways get twitches in the servo, any idea what caused that?

regards
J

Here are a Video what the arduino do:

Arduino Servo Problem