Drehgeber - Rotary Encoder ohne Interrupt ?


mahlzeit zusammen  :) ,

was haltet ihr davon, wenn man einen drehgeber auswertet, ohne dabei eine isr zu verwenden?

wie stark leidet die zykluszeit / latenz bei groesseren programmen?

versuch ohne interrupt:
code: [select]

/*
  drehgeber auswertung ohne interrupt
  neutral = clk & dt an
  rechts = (dt dann clk aus) -> (dt dann clk an)
  links  = (clk dann dt aus) -> (clk dann dt an)
*/
const uint8_t clk = 2;
const uint8_t dt = 3;
const uint8_t sw = 4;

void setup()
{
  serial.begin(19200);
  pinmode(clk, input);
  pinmode(dt, input);
  pinmode(sw, input_pullup);
  while(!serial){/*warten*/}
}

void loop()
{
  static bool drehen, block;
  static int32_t zahl;
  bool m_clk = digitalread(clk);
  bool m_dt = digitalread(dt);
  bool m_sw = !digitalread(sw);
 
  if(m_sw && !block) //taster
  {
    block = true;
    zahl = 0;
    serial.print(f("reset "));
    serial.println(zahl);
  }
  else if(!m_sw && block)
  {
    block = false;
  }
 
  if (!m_clk && !drehen) //rechts
  {
    drehen = true;
    zahl -= 1;
    serial.print(f("links "));
    serial.println(zahl);
  }
  else if (!m_dt && !drehen) //links
  {
    drehen = true;
    zahl += 1;
    serial.print(f("rechts "));
    serial.println(zahl);
  }
 
  if (m_clk && m_dt && drehen) //grunstellung
  {
    drehen = false;
  }
}

was für ein drehgeber ist das? tastaturersatz oder drehzahl/positionskontrolle eines motors?


Arduino Forum > International > Deutsch (Moderator: uwefed) > Drehgeber - Rotary Encoder ohne Interrupt ?


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???