2 channel encoder simulator

@dougp thanks for your effort. I will try it out all on Monday properly.

Here's another. (Too cold to go to the beach, so…)

Speed control - the slider goes from fast clockwise to slow to fast anticlockwise.

Fun!

# include <Adafruit_NeoPixel.h>

Adafruit_NeoPixel wheel = Adafruit_NeoPixel(4, A1, NEO_GRB + NEO_KHZ800);

void setup() {

  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);

  pinMode(A0, INPUT);

  Serial.begin(9600);

  wheel.begin();

}

# define MAX  1000
# define MIN  100

void loop()
{
  int8_t direction;
  static unsigned long lastTime = 0;
  static unsigned char phase = 0;

  unsigned long now = millis();

  int period = analogRead(A0);
  if (period < 512) {
    direction = -1;     // backward
    period = map(period, 0, 511, MIN, MAX);
  }
  else {
    direction = 1;     // backward
    period = map(period, 512, 1023, MAX, MIN);
  }

  if (now - lastTime < period) return;
  lastTime = now;

//  Serial.println(analogRead(A0));

  switch (phase & 0x3) {    // just use bottom two bits of the phase counter
  case 0 :
    digitalWrite(3, LOW);   
    digitalWrite(4, LOW);    
    break;

  case 1 :
    digitalWrite(3, LOW);   
    digitalWrite(4, HIGH);    
    break;

  case 2 :
    digitalWrite(3, HIGH);   
    digitalWrite(4, HIGH);    
    break;

  case 3 :
    digitalWrite(3, HIGH);   
    digitalWrite(4, LOW);    
    break;
  }

  for (uint8_t ii = 0; ii < 4; ii++) wheel.setPixelColor(ii, 0);
  
  wheel.setPixelColor(phase & 0x3, 0xff0000);
  wheel.show();

  phase += direction;
}

wokwi.com - so easy. Why wouldn't I?

And as far as this goes

It looks like your link to wokwi.com was already posted in the topic by @alto777 in a reply on Jan 14, '22 – are you sure you want to post it again?

Yes, yes I am sure, but thanks for the heads up, Discord!

a7