Arduino_Scuola
Published © GPL3+

Use a hard disk like a rotational input device

If you have a broken hard disk you can hack it, turning it into an input device. This hack is very simple and only needs some soldering.

BeginnerFull instructions provided1 hour5,843
Use a hard disk like a rotational input device

Things used in this project

Story

Read more

Code

Code snippet #1

Arduino
/**
HD Encoder 
**/

int actual = -1;
int encActual = -1;



void setup() 
{
  Serial.begin(9600);
}

int readEncoder() {
  int p1 = analogRead(1);
  int p2 = analogRead(2);
  int p3 = analogRead(3);

  if (p1+p2+p3==0)
    return -1;

  int l = p1+p2+p3;    
  int x = (p2-p3)*86;
  int y = p1*100 - (p2+p3)*50;
  int p=-1;
  if (y>0) {
    if (abs(x) < y*57/100) 
      p=0;
    else 
      p=(x<0) ? 5 : 1;
  } 
  else {
    if (abs(x) < -y*57/100) 
      p=3;
    else 
      p=(x<0) ? 4 : 2;
  }
  return p;
}




boolean interpolate() {
  int delta[11] = {
    -1, -2, 0, +2, +1, 0, -1, -2, 0, +2, +1
  };
  int v = readEncoder();
  if (v==-1)
    return false;
  if (actual==-1) {
    actual = 0;
    encActual = v;
    return true;
  }

  int d = delta[v-encActual+5];
  actual += d;
  encActual = v;
  return true;
}

void loop()
{
  if (interpolate())
    Serial.println(actual);
  delay(20);
}

Credits

Arduino_Scuola
32 projects • 155 followers
Contact

Comments

Please log in or sign up to comment.