Go Down

Topic: error: ‘class QuadEncoder’ has no member named ‘hb’ (Read 3937 times) previous topic - next topic

puchisco

Hello from Argentina (and sorry for my english)!

I'm trying to use the QuadEncoder library (https://github.com/medecau/QuadEncoder) but when i try to compile have this message:

[font=Verdana]error: 'class QuadEncoder' has no member named 'hb' [/font]

The code is very simple:

Code: [Select]

#include <QuadEncoder.h>

int qe1Move=0;

QuadEncoder qe(2,4);
void setup() {
    Serial.begin(9600);
}

void loop() {
  qe1Move=qe.hb();
  if (qe1Move=='>')
    Serial.print(char(qe1Move));
  else if (qe1Move=='<')
    Serial.print(char(qe1Move));
}


QuadEncoder.cpp
Code: [Select]
/**
* QuadEncoder.cpp - Library for reading moves from a quadrature rotary encoder
* Created by Pedro Rodrigues (medecau@gmail.com) 9, January of 2010
* Modified by Andreas Lekas (spadusa@gmail.com) 31, January, 2010
* Released into the public domain.
* Updated by Scottapotamas scott@26oclock.com for arduino 1.0 ice
*/

#include "Arduino.h"
#include "QuadEncoder.h"

QuadEncoder::QuadEncoder(int pin1, int pin2)
{
  pinMode(pin1, INPUT);
  pinMode(pin2, INPUT);
  digitalWrite(pin1, HIGH);
  digitalWrite(pin2, HIGH);
  _inputPin1=pin1;
  _inputPin2=pin2;
  _val1=1;
  _val2=1;
  _oldVal1=1;
  _oldVal2=1;
  _pos=0;
  _oldPos=0;
  _turn=0;
  _turnCount=0;
}

char QuadEncoder::tick()

  _moved = false;
  _val1 = digitalRead(_inputPin1);
  _val2 = digitalRead(_inputPin2);
    // Detect changes
  if ( _val1 != _oldVal1 || _val2 != _oldVal2) {
    _oldVal1=_val1;
    _oldVal2=_val2;
   
      //for each pair there's a position out of four
    if ( _val1 == 1 ) {// stationary position
      if (_val2 == 1)
        _pos = 0;
      else if (_val2 == 0)
        _pos = 3;
    } else if (_val1 == 0){
      if (_val2 == 1)
        _pos = 1;
      else if (_val2 == 0)
        _pos = 2;
    }
   
    _turn = _pos-_oldPos;
    _oldPos = _pos;
    if (abs(_turn) != 2) {
      if (_turn == 1 || _turn == -3)
        _turnCount++;
      else if (_turn == -1 || _turn == 3)
        _turnCount--;
    }
   
    if (_pos==0){
      if (_turnCount>0){
        _turnCount=0;
_moved = true;
        return '>';
      } else if (_turnCount<0){
_moved = true;
        _turnCount=0;
        return '<';
      } else {
_moved = false;
        _turnCount=0;
        return '-';
      }
    }
  }
}


QuadEncoder.h
Code: [Select]

/**
* QuadEncoder.h - Library for reading moves from a quadrature rotary encoder
* Created by Pedro Rodrigues (medecau@gmail.com) 9, January of 2010
* Released into the public domain.
* Updated by Scottapotamas scott@26oclock.com for arduino 1.0 ice
*/

#ifndef QuadEncoder_h
#define QuadEncoder_h

#include "Arduino.h"


class QuadEncoder
{
  public:
    QuadEncoder(int pin1, int pin2);
    char tick();
  private:
bool _moved;
    int _inputPin1;
    int _inputPin2;
    int _val1;
    int _val2;
    int _oldVal1;
    int _oldVal2;
    int _pos;
    int _oldPos;
    int _turn;
    int _turnCount; 
  };

#endif


I'm using Arduino IDE (on Ubuntu) and Arduino UNO.

AWOL

Quote
'class QuadEncoder' has no member named 'hb'

After a very quick inspection, I can't disagree.
Where do you think "hb" is declared?

puchisco

I've found the error. The example code i used from de Readme is old. On the new version of QuadEncoder,
Code: [Select]
char QuadEncoder::hb()

was reemplaced by

Code: [Select]
char QuadEncoder::tick()

I simply change 'hb' for 'tick' and now compile OK.
Thanks therefore.

Go Up