Scroll wheel for menu navigation

Hi,

i have a stalk radio control unit and i'm trying to use it with my arduino for other aplications.

so this is the schematic of the stalk controls

so i for now i got all the push buttons connected and working with my UNO and the next phase of the project is to get this to work but i have no idea where to start with the wheel.

i already saw some code for encoders but i'm having trouble understanding how to code for my scroll wheel.

so any help you can give like showing me any good tutorials or articles on this it would be great,

thanks in advance,
pnorv

Is the black broken circle the scroll wheel?

I can't figure from the diagram how it is supposed to work. Do you have a link to the datasheet for the device?

...R

yes the black circle is the scroll this is the only information i could find about it.

got it from here http://goo.gl/naVtru

in the mean time i got some code working it fails when i use it faster any advice?

if(digitalRead(green)){ rotstate="green"; }else{
if(digitalRead(yellow)){ rotstate="yellow"; }else{
if(digitalRead(blue)){ rotstate="blue"; }
}
}
if(lastrotstate!=rotstate){
if(lastrotstate== "green" && rotstate== "yellow" || lastrotstate== "blue" && rotstate== "green" || lastrotstate== "blue" && rotstate== "green"){
Serial.println("scroll down");
}
}else{
if(lastrotstate== "yellow" && rotstate== "green" || lastrotstate== "blue" && rotstate== "yellow" || lastrotstate== "green" && rotstate== "blue"){
Serial.println("scroll up");
}

}
}
lastrotstate=rotstate;

this is inside the loop function

i know the code is weak but i'm still learning

ok
Firstly you seem to have a typo in this line

  if(lastrotstate== "green" && rotstate== "yellow" || lastrotstate== "blue" && rotstate== "green" || lastrotstate== "blue" && rotstate== "green"){

I think you meant

if(lastrotstate== "green" && rotstate== "yellow" || lastrotstate== "yellow" && rotstate== "blue" || lastrotstate== "blue" && rotstate== "green")

Anyhow. Approaching this problem from another angle I'd suggest allocating each of those lines to a single bit. I presume there are a set of 3 microswitches that are getting triggered by the control but there's no way of knowing if they're configured in a "break before make" setup or "make before break"

Nevertheless, I've had a bash at knocking something up but, without any means of replicating your gizmo, it's just a wild stab in the dark. Give it a try and see what comes out.
(just delete your loop function and copy and paste the code below)

int green=10;
int yellow=11;
int blue=12;

void setup()
{
}


//downWire is the one to expect if scroller moves down
//upWire is what we expect if scroller moves up

byte downWire=0;
byte upWire=0;
byte lastR=0;

void loop()
{
byte nextDown[7]={0,2,4,2,1,1,4};
byte nextUp[7]  ={0,4,1,1,2,4,2};
byte direction=0;//direction will be 1 for down 2 for up, 3 ?
byte Rstate;


Rstate=digitalRead(green)+2*digitalRead(yellow)+4*digitalRead(blue);

//ignore cases where all or no wires are currently active
if((Rstate!=0)&&(Rstate<7))
  {if((lastR!=0)&&(lastR!=Rstate)) 
     {direction=(downWire & Rstate)+2*(upWire & Rstate);
     switch(direction)
       {case 0:
             Serial.println("Logic has failed us!");break;
        case 1:
             Serial.println("Scroll down");break;
        case 2:
             Serial.println("Scroll up");break;

        case 3:
             Serial.println("must have missed a pulse");break;

       }

     }


  //Now setup vars for next time
  downWire=nextDown[Rstate];
  upWire=nextUp[Rstate]; 
  }

}

digitalRead() is rather slow so if you need to read faster you will have to use direct port manipulation which will allow you to read all three pins (assuming they are connected appropriately) in a single PINx instruction.

If that doesn't improve the speed sufficiently you will need to learn how to use interrupts.

...R