Go Down

Topic: Name for this type of button instance (Read 925 times) previous topic - next topic

liudr

So I'm updating my phi_buttons class to include the following elements:

1) rotary encoder up and down. I added a software button type. The button status is entirely supplied by calling a function attached to the button with attach_alt_sense(). I think "software button" sounds right. The entire logic (up-pressed-down-released) is generated by software based on either software algorithm or interpreting hardware different from tactile switches. What do you think of this name?

2) analog buttons on a series of resistors (YEAH!) and other buttons such as pressure sensor or thermistor, both resistive, or in general, a range of analog values that corresponds to a button. They create a true status and false status and may need debounce. If I have a function that just reads and converts these buttons into true/false and feed these to my phi_buttons class with the debounce, I don't have to re-write debounce for them any more. But what to call this type of buttons to be most descriptive? para_buttons? non_digital? digitized? analog buttons sound to narrow but I will use it if there is no better name there.

Need some help here. Thanks.

robtillaart


So these buttons hide "hardware" behaviour like bouncing thresholds etc. sounds good. names that came into my mind ...
- button     (keep it simple...)
- swbutton (
- ibutton    (i from ideal
- pbutton   (p from perfect
- _button    (nah)

just button still feels the best for me.

Can you post some code of how you implemented the rotary -> button?




Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

liudr



So these buttons hide "hardware" behaviour like bouncing thresholds etc. sounds good. names that came into my mind ...
- button     (keep it simple...)
- swbutton (
- ibutton    (i from ideal
- pbutton   (p from perfect
- _button    (nah)

just button still feels the best for me.

Can you post some code of how you implemented the rotary -> button?



Thanks Rob. I will post my codes once I turn on my main computer.

liudr

So here is the code I worked out to turn rotary encoder up and down motions into two effective buttons for phi_buttons class or anything else if you care to adapt a few lines:

Code: [Select]
void initPins()
{
  pinMode(EncoderChnA, INPUT);
  digitalWrite(EncoderChnA, HIGH);
  pinMode(EncoderChnB, INPUT);
  digitalWrite(EncoderChnB, HIGH);
  pinMode(EncoderPress, INPUT);
  digitalWrite(EncoderPress, HIGH);
}

byte read_encoder(byte direction) // 1 for asking CW counts, -1 for asking CCW counts. 0 for asking click counts. 127 asking for absolute orientation. Returns counts and decrements the counts till 0.
{
  static byte stat_seq[]={3,2,0,1,3,2,0,1,3}; // For always on switches use {0,1,3,2,0,1,3,2,0};
  static byte stat_seq_ptr=4;
  static byte cw_counter=0;
  static byte ccw_counter=0;
  static byte click_counter=0;

  byte stat_int=(digitalRead(EncoderChnB)<<1) | digitalRead(EncoderChnA);
  byte press = digitalRead(EncoderPress);
//  if (stat_int!=3) Serial.println(stat_int,DEC);
  if (stat_int==stat_seq[stat_seq_ptr+1])
  {
    stat_seq_ptr++;
    if (stat_seq_ptr==8)
    {
      stat_seq_ptr=4;
      cw_counter++;
    }
  }
  else if (stat_int==stat_seq[stat_seq_ptr-1])
  {
    stat_seq_ptr--;
    if (stat_seq_ptr==0)
    {
      stat_seq_ptr=4;
      ccw_counter++;
    }
  }
  if (direction==1)
  {
    if (cw_counter>0)
    {
      cw_counter--;
      return cw_counter+1;
    }
    else return 0;
  }

  else if (direction==255)
  {
    if (ccw_counter>0)
    {
      ccw_counter--;
      return ccw_counter+1;
    }
    else return 0;
  }
 
  else if (direction==127) return cw_counter-ccw_counter;
 
  else if (direction==0)
  {
    if (click_counter>0)
    {
      click_counter--;
      return click_counter+1;
    }
    else return 0;
  }
  else return 0;
}

byte up_sense() // This function replaces the original mechanism in phi_buttons to sense a tactile button to sense a rotary encoder rotating CW
{
  byte ct;
  ct=read_encoder(1);
  if (ct>0) return buttons_released;
  else return buttons_up;
}

byte down_sense() // This function replaces the original mechanism in phi_buttons to sense a tactile button to sense a rotary encoder rotating CCW
{
  byte ct;
  ct=read_encoder(-1);
  if (ct>0) return buttons_released;
  else return buttons_up;
}


There are 4 functions.
The initPins sets all relevant pins to inputs and enables internal pull-ups.
The byte read_encoder(byte) simply reads and keeps record of the status of the rotary encoder and reports back a number depending on the input parameter. It could be used by the other two functions to create clicks or report orientation of the encoder shaft. I need to polish that part but up down are perfect.
The up_sense() and down_sense() generates appropriate "button" status depending on the read_encoder return.

Tested on a 12 detent encoder with no problem. I also modified my button library to take alternative sense function so I just create 2 software buttons and supply up_sense and down_sense to these buttons and I can scroll up and down a menu created in phi_prompt with the encoder.

Go Up