Results 1 to 10 of 10
  1. #1
    75+ Posting Member
    Join Date
    Feb 2010
    Location
    London
    Posts
    87
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    How to vonnct many rotay encoders

    I started to build radio panel and MCP based on Arduino mega and Jim Link2FS,I am modifying fim code for multi ratio bit by bit.
    So I got my LCD set up,I got switches end I started with the encoders,

    The first one was easy,made small modification to Jim code and it worked,but the second one wont send the data it should

    So we got:

    #include "Quadrature.h"
    Quadrature quad1(8, 9); //first encoder one that works
    Quadrature quad11(22, 22); //second encoder one that does not work


    int X;// a rotary variable com1 1st encoder
    int Xold;// the old reading com1 1st encoder
    int Xdif;// the difference since last loop com1 1st encoder
    int X1;// a rotary variable nav1 2nd encoder
    int Xold1;// the old reading nav1 2nd encoder
    int Xdif1;// the difference since last loop na 2nd encoder


    void loop() {

    {INPUTPINS();} //Check the "button pressed" section
    }
    void ROTARYS() {//now the bit for the rotary encoder input
    X = (quad1.position()/2);
    if (X != Xold) { // checks to see if it different
    (Xdif = (X-Xold));// finds out the difference

    // Com1 rotary encoder output
    if (Xdif == 1) {
    if (digitalRead(10)==0 ) {
    Serial.println("A02");
    }
    else Serial.println("A04");
    }
    if (Xdif == -1) {
    if (digitalRead(10)==0 ) {
    Serial.println("A01");
    }
    else Serial.println("A03");
    }

    X1 = (quad11.position()/2);
    if (X1 != Xold1) { // checks to see if it different
    (Xdif1 = (X1-Xold1));// finds out the difference

    // Com1 rotary encoder output
    if (Xdif1 == 1) {
    if (digitalRead(25)==0 ) {
    Serial.println("A13");
    }
    else Serial.println("A15");
    }
    if (Xdif1 == -1) {
    if (digitalRead(25)==0 ) {
    Serial.println("A14");
    }
    else Serial.println("A16");
    }
    }

    Now the 2nd encoder is connected to pin 22,23 and switch to 35
    it send data like D220,D230 and so on,but it will not sen the command A14,A13 and so on.
    I am guessing that it's something with the line

    X1 = (quad11.position()/2);

    I look all over the internet and I ca not find what does position() do in relation to encoders.

    Please help any idea?

  2. #2
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    275
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: How to vonnct many rotay encoders

    You have not posted the entire code, so I'm guessing.
    But as it sends data like D220,D230, I would think that the encoder is connected to pins that are defined as KEYS, and and is therefore seen as a switch.
    Have a look in the setup at the:
    Code:
      Kstringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";  
      for (int KoutPin = 8; KoutPin < 70; KoutPin++)// Get all the pins ready for "Keys"
    And change to whatever fits your setup.
    Also change in the "void KEYS" section.
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  3. #3
    75+ Posting Member
    Join Date
    Feb 2010
    Location
    London
    Posts
    87
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: How to vonnct many rotay encoders

    I don't think it's that
    In my code the pins from 8 o 54 ar set as outputs,and encode is a set of 2 switches anyway.
    It is etected it is orking but for some season it does not want to send the comands A
    here is the whole code that i got so far



    /*

    ======================================================

    This sketch prints the airspeed, altitude,
    com1. frequency and com1. standby frequency to the LCD.

    It is set up to use with the Uno card but it will also run as-is on the Mega using
    the pins up to No. 19.
    If you have a Mega card and want all the pins, then
    there are only 3 things to change,,,
    where it says <= 19 change that to read <= 69 (on 2 lines)
    also,,
    stringoldstate = "1111111111111111 etc" you need to have the appropriate one active.

    =======================================================

    This example code is in the public domain.

    */

    // include the library code:


    #include
    #include "math.h"
    #include "Quadrature.h"
    #include
    Quadrature quad1(8, 9);
    Quadrature quad11(22, 23);

    // initialize the library with the numbers of the interface pins
    LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

    int mark; // shows where the cursor is in the likes of ADF etc
    int active; // the mode thats active
    int X;// a rotary variable com1
    int Xold;// the old reading com1
    int Xdif;// the difference since last loop com1
    int X1;// a rotary variable nav1
    int Xold1;// the old reading nav1
    int Xdif1;// the difference since last loop nav1



    int j1;
    int j2;
    int pinState;
    int pinNo;
    int doutpin;
    String oldpinStateSTR, pinStateSTR, stringnewstate,stringoldstate, com1, com1old, com1sb, com1sbold, APairsp, APairspold,
    APaltit, APaltitold,APhdg, APhdgold, VS, VSold, nav, navold, navsb,navsbold,trans, transold,mach, machold,
    baro, baroold;

    void setup()
    {
    // set up the LCD's number of columns and rows:
    lcd.begin(20, 4);
    // Print a message to the LCD.
    delay (11);
    lcd.print("Witaj Bartku");
    delay (11);
    lcd.setCursor(0, 1);
    delay (11);
    lcd.print("Czekam na dane z FSX");
    delay (11);
    // the line below is for the Uno card

    //the line below is for the mega card
    stringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";

    Serial.begin(115200);
    for (int doutPin = 8; doutPin <= 33; doutPin++)
    {
    pinMode(doutPin, INPUT);
    digitalWrite(doutPin, HIGH);
    }
    Serial.flush();
    delay(5000);
    lcd.clear();

    lcd.setCursor(6,1);
    lcd.print("QNH");
    }

    void loop() {

    {INPUTPINS();} //Check the "button pressed" section
    {ROTARYS();} // go and check the rotary encoder


    // read the oldest byte in the serial buffer:
    if (Serial.available() > 0) {
    j1 = Serial.read();


    if (j1 == 'k'){ // Found the reading "mach"
    delay (0);
    baro = "";
    baro += char(Serial.read());
    baro += char(Serial.read());
    baro += char(Serial.read());
    baro += char(Serial.read());
    baro += char(Serial.read());
    //pads it up to 5 caracters
    if (baro != baroold){

    lcd.setCursor(0, 1);
    delay (0);
    lcd.print(baro);
    baroold = baro;
    }
    }

    if (j1 == 'g'){ // Found the reading "mach"
    delay (0);
    mach = "";
    mach += char(Serial.read());
    mach += char(Serial.read());
    mach += char(Serial.read());
    mach += char(Serial.read());
    //pads it up to 3 caracters
    if (mach != machold){

    lcd.setCursor(0, 0);
    delay (0);
    lcd.print(mach);
    machold = mach;
    }
    }

    if (j1 == 'f' ){ // Found the reading "airspeed indicated"
    delay (0); // It seems to need a delay here
    APairsp = "";
    APairsp += char(Serial.read());
    APairsp += char(Serial.read());
    APairsp += char(Serial.read());
    //pads it up to 3 caracters

    if (APairsp != APairspold){ // checks to see if its different to the "old" reading

    lcd.setCursor(0, 0); //sets the cursor position for the first letter
    delay (0);
    lcd.print(APairsp); //Prints the data to the LCD
    APairspold = APairsp; // Writes the current reading to the "old" string.
    lcd.setCursor(3, 0);
    lcd.print(" ");

    }
    }

    if (j1 == 'd'){ // Found the reading "heading"
    delay (11);
    APhdg = "";
    APhdg += char(Serial.read());
    APhdg += char(Serial.read());
    APhdg += char(Serial.read());
    //pads it up to 3 caracters
    if (APhdg != APhdgold){

    lcd.setCursor(5, 0);
    delay (11);
    lcd.print(APhdg);
    APhdgold = APhdg;
    }
    }



    if (j1 == 'b'){ // Found the reading "altitude"
    delay (11);
    APaltit = "";
    APaltit += char(Serial.read());
    APaltit += char(Serial.read());
    APaltit += char(Serial.read());
    APaltit += char(Serial.read());
    APaltit += char(Serial.read());

    //pads it up to 5 caracters
    if (APaltit != APaltitold){

    lcd.setCursor(9, 0);
    delay (11);
    lcd.print(APaltit);
    APaltitold = APaltit;
    }
    }

    if (j1 == 'c'){ // Found the reading "VS"
    delay (11);
    VS = "";
    VS += char(Serial.read());
    VS += char(Serial.read());
    VS += char(Serial.read());
    VS += char(Serial.read());
    VS += char(Serial.read());

    //pads it up to 5 caracters
    if (VS != VSold){

    lcd.setCursor(15, 0);
    delay (11);
    lcd.print(VS);
    VSold = VS;
    }
    }

    if (j1 == 'A'){ // Found the reading "Com1 frequency"
    delay (11);
    com1 = "";
    com1 += char(Serial.read());
    com1 += char(Serial.read());
    com1 += char(Serial.read());
    com1 += char(Serial.read());
    com1 += char(Serial.read());
    com1 += char(Serial.read());
    com1 += char(Serial.read());
    //pads it up to 7 caracters
    if (com1 != com1old){

    lcd.setCursor(0, 2);
    delay (11);
    lcd.print(com1);
    com1old = com1;
    }
    }
    if (j1 == 'B'){ // Found the reading "Com1 stand-by"
    delay (11);
    com1sb = "";
    com1sb += char(Serial.read());
    com1sb += char(Serial.read());
    com1sb += char(Serial.read());
    com1sb += char(Serial.read());
    com1sb += char(Serial.read());
    com1sb += char(Serial.read());
    com1sb += char(Serial.read());
    //pads it up to 7 caracters
    if (com1sb != com1sbold){

    lcd.setCursor(8, 2);
    delay (11);
    lcd.print(com1sb);
    com1sbold = com1sb;
    }
    }
    if (j1 == 'E'){ // Found the reading "nav1 stand-by"
    delay (11);
    nav = "";
    nav += char(Serial.read());
    nav += char(Serial.read());
    nav += char(Serial.read());
    nav += char(Serial.read());
    nav += char(Serial.read());
    nav += char(Serial.read());

    //pads it up to 6 caracters
    if (nav != navold){

    lcd.setCursor(0, 3);
    delay (11);
    lcd.print(nav);
    navold = nav;
    }
    }
    if (j1 == 'F'){ // Found the reading "nav1 stand-by"
    delay (11);
    navsb = "";
    navsb += char(Serial.read());
    navsb += char(Serial.read());
    navsb += char(Serial.read());
    navsb += char(Serial.read());
    navsb += char(Serial.read());
    navsb += char(Serial.read());

    //pads it up to 6 caracters
    if (navsb != navsbold){
    //delay (11);
    lcd.setCursor(8, 3);
    delay (11);
    lcd.print(navsb);
    navsbold = navsb;
    }
    }
    if (j1 == 'J'){ // Found the reading "nav1 stand-by"
    delay (11);
    trans = "";
    trans += char(Serial.read());
    trans += char(Serial.read());
    trans += char(Serial.read());
    trans += char(Serial.read());

    //pads it up to 4 caracters
    if (trans != transold){
    //delay (11);
    lcd.setCursor(16, 3);
    delay (11);
    lcd.print(trans);
    transold = trans;
    }
    }

    } //end of serial loop
    } //end of void loop

    void ROTARYS() {//now the bit for the rotary encoder input
    X = (quad1.position()/2);
    if (X != Xold) { // checks to see if it different
    (Xdif = (X-Xold));// finds out the difference

    // Com1 rotary encoder output
    if (Xdif == 1) {
    if (digitalRead(10)==0 ) {
    Serial.println("A02");
    }
    else Serial.println("A04");
    }
    if (Xdif == -1) {
    if (digitalRead(10)==0 ) {
    Serial.println("A01");
    }
    else Serial.println("A03");
    }

    X1 = (quad11.position());
    if (X1 != Xold1) { // checks to see if it different
    (Xdif1 = (X1-Xold1));// finds out the difference

    // Com1 rotary encoder output
    if (Xdif1 == 1) {
    if (digitalRead(25)==0 ) {
    Serial.println("A13");
    }
    else Serial.println("A15");
    }
    if (Xdif1 == -1) {
    if (digitalRead(25)==0 ) {
    Serial.println("A14");
    }
    else Serial.println("A16");
    }
    }

    }// end of rotarys

    void INPUTPINS(){
    // Now the bit for the "keys" input
    stringnewstate = "";
    for (int pinNo = 10; pinNo <= 53; pinNo++){// checks all the pins 10 to 53
    pinStateSTR = String(digitalRead(pinNo));
    oldpinStateSTR = "";
    oldpinStateSTR += String(stringoldstate.charAt(pinNo - 10));
    if (pinStateSTR != oldpinStateSTR) {// yes it's different
    if (pinNo == 11 and pinStateSTR == "0") { //Change-over button is pressed
    Serial.println("A06");//com1
    }
    if (pinNo == 31 and pinStateSTR == "0" ) { //Change-over button is pressed
    Serial.println("A18");//com1
    }
    Serial.print ("D");
    if (pinNo < 10) Serial.print ("0");
    Serial.print (pinNo);
    Serial.println (pinStateSTR);
    delay(11);
    }
    stringnewstate += pinStateSTR;
    }

    stringoldstate = stringnewstate;
    delay(11);

    }

  4. #4
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    275
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: How to vonnct many rotay encoders

    I just drop things out of my head here
    In you're void setup, you have got
    Code:
    Serial.begin(115200); 
    for (int doutPin = 8; doutPin <= 33; doutPin++) 
    You have got a rotary encoder on pin 8 and 9. Youre next rotary enoder 22 and 23, are in the "void INPUTPINS()" defined as a switch, because it is in the range between 10 and 53.
    Code:
    void INPUTPINS(){
    // Now the bit for the "keys" input
    stringnewstate = "";
    for (int pinNo = 10; pinNo <= 53; pinNo++){// checks all the pins 10 to 53
    Telling that the pins 10 to 53 are switches.
    Change you're INPUTPINS range to:
    int pinNo = 34; pinNo <= 53; pinNo++)
    Plan which pins to be used for what.

    EDIT:
    Remember to change the entire statement.
    Code:
      for (int KpinNo = 34; KpinNo < 53; KpinNo++){    KpinStateSTR = String(digitalRead(KpinNo)); 
        KoldpinStateSTR = String(Kstringoldstate.charAt(KpinNo - 34));
        if (KpinStateSTR != KoldpinStateSTR)
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  5. #5
    75+ Posting Member
    Join Date
    Feb 2010
    Location
    London
    Posts
    87
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: How to vonnct many rotay encoders

    Hi there
    I made some chages,and tank you for pointing out my mystake
    Anyway the encoder connected to pin 8, 9 works but the other 2 do not work.

    Please have a look at my code,maybe yo find somthing

    /*

    ======================================================

    This sketch prints the airspeed, altitude,
    com1. frequency and com1. standby frequency to the LCD.

    It is set up to use with the Uno card but it will also run as-is on the Mega using
    the pins up to No. 19.
    If you have a Mega card and want all the pins, then
    there are only 3 things to change,,,
    where it says <= 19 change that to read <= 69 (on 2 lines)
    also,,
    stringoldstate = "1111111111111111 etc" you need to have the appropriate one active.

    =======================================================

    This example code is in the public domain.

    */

    // include the library code:


    #include
    #include "math.h"
    #include "Quadrature.h"
    #include
    Quadrature quad1(8, 9);
    Quadrature quad2(25, 24);
    Quadrature quad3(34, 35);
    // initialize the library with the numbers of the interface pins
    LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

    int mark; // shows where the cursor is in the likes of ADF etc
    int active; // the mode thats active
    long Xold1;// the first encoder "old" reading
    long Xold2;// the second encoder "old" reading
    long Xold3;// the second encoder "old" reading



    int j1;
    int j2;
    int pinState;
    int pinNo;
    int doutpin;
    String oldpinStateSTR, pinStateSTR, stringnewstate,stringoldstate, com1, com1old, com1sb, com1sbold, APairsp, APairspold,
    APaltit, APaltitold,APhdg, APhdgold, VS, VSold, nav, navold, navsb,navsbold,trans, transold,mach, machold,
    baro, baroold;

    void setup()
    {
    // set up the LCD's number of columns and rows:
    lcd.begin(20, 4);
    // Print a message to the LCD.
    delay (11);
    lcd.print("Witaj Bartku");
    delay (11);
    lcd.setCursor(0, 1);
    delay (11);
    lcd.print("Czekam na dane z FSX");
    delay (11);
    // the line below is for the Uno card

    //the line below is for the mega card
    stringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";

    Serial.begin(115200);
    for (int doutPin = 8; doutPin <= 54; doutPin++)
    {
    pinMode(doutPin, INPUT);
    digitalWrite(doutPin, HIGH);
    }
    Serial.flush();
    delay(5000);
    lcd.clear();

    lcd.setCursor(6,1);
    lcd.print("QNH");
    }

    void loop() {

    {
    INPUTPINS();
    } //Check the "button pressed" section
    {
    ROTARYS();
    } // go and check the rotary encoder


    // read the oldest byte in the serial buffer:
    if (Serial.available() > 0) {
    j1 = Serial.read();


    if (j1 == 'k'){ // Found the reading "mach"
    delay (0);
    baro = "";
    baro += char(Serial.read());
    baro += char(Serial.read());
    baro += char(Serial.read());
    baro += char(Serial.read());
    baro += char(Serial.read());
    //pads it up to 5 caracters
    if (baro != baroold){

    lcd.setCursor(0, 1);
    delay (0);
    lcd.print(baro);
    baroold = baro;
    }
    }

    if (j1 == 'g'){ // Found the reading "mach"
    delay (0);
    mach = "";
    mach += char(Serial.read());
    mach += char(Serial.read());
    mach += char(Serial.read());
    mach += char(Serial.read());
    //pads it up to 3 caracters
    if (mach != machold){

    lcd.setCursor(0, 0);
    delay (0);
    lcd.print(mach);
    machold = mach;
    }
    }

    if (j1 == 'f' ){ // Found the reading "airspeed indicated"
    delay (0); // It seems to need a delay here
    APairsp = "";
    APairsp += char(Serial.read());
    APairsp += char(Serial.read());
    APairsp += char(Serial.read());
    //pads it up to 3 caracters

    if (APairsp != APairspold){ // checks to see if its different to the "old" reading

    lcd.setCursor(0, 0); //sets the cursor position for the first letter
    delay (0);
    lcd.print(APairsp); //Prints the data to the LCD
    APairspold = APairsp; // Writes the current reading to the "old" string.
    lcd.setCursor(3, 0);
    lcd.print(" ");

    }
    }

    if (j1 == 'd'){ // Found the reading "heading"
    delay (11);
    APhdg = "";
    APhdg += char(Serial.read());
    APhdg += char(Serial.read());
    APhdg += char(Serial.read());
    //pads it up to 3 caracters
    if (APhdg != APhdgold){

    lcd.setCursor(5, 0);
    delay (11);
    lcd.print(APhdg);
    APhdgold = APhdg;
    }
    }



    if (j1 == 'b'){ // Found the reading "altitude"
    delay (11);
    APaltit = "";
    APaltit += char(Serial.read());
    APaltit += char(Serial.read());
    APaltit += char(Serial.read());
    APaltit += char(Serial.read());
    APaltit += char(Serial.read());

    //pads it up to 5 caracters
    if (APaltit != APaltitold){

    lcd.setCursor(9, 0);
    delay (11);
    lcd.print(APaltit);
    APaltitold = APaltit;
    }
    }

    if (j1 == 'c'){ // Found the reading "VS"
    delay (11);
    VS = "";
    VS += char(Serial.read());
    VS += char(Serial.read());
    VS += char(Serial.read());
    VS += char(Serial.read());
    VS += char(Serial.read());

    //pads it up to 5 caracters
    if (VS != VSold){

    lcd.setCursor(15, 0);
    delay (11);
    lcd.print(VS);
    VSold = VS;
    }
    }

    if (j1 == 'A'){ // Found the reading "Com1 frequency"
    delay (11);
    com1 = "";
    com1 += char(Serial.read());
    com1 += char(Serial.read());
    com1 += char(Serial.read());
    com1 += char(Serial.read());
    com1 += char(Serial.read());
    com1 += char(Serial.read());
    com1 += char(Serial.read());
    //pads it up to 7 caracters
    if (com1 != com1old){

    lcd.setCursor(0, 2);
    delay (11);
    lcd.print(com1);
    com1old = com1;
    }
    }
    if (j1 == 'B'){ // Found the reading "Com1 stand-by"
    delay (11);
    com1sb = "";
    com1sb += char(Serial.read());
    com1sb += char(Serial.read());
    com1sb += char(Serial.read());
    com1sb += char(Serial.read());
    com1sb += char(Serial.read());
    com1sb += char(Serial.read());
    com1sb += char(Serial.read());
    //pads it up to 7 caracters
    if (com1sb != com1sbold){

    lcd.setCursor(8, 2);
    delay (11);
    lcd.print(com1sb);
    com1sbold = com1sb;
    }
    }
    if (j1 == 'E'){ // Found the reading "nav1 stand-by"
    delay (11);
    nav = "";
    nav += char(Serial.read());
    nav += char(Serial.read());
    nav += char(Serial.read());
    nav += char(Serial.read());
    nav += char(Serial.read());
    nav += char(Serial.read());

    //pads it up to 6 caracters
    if (nav != navold){

    lcd.setCursor(0, 3);
    delay (11);
    lcd.print(nav);
    navold = nav;
    }
    }
    if (j1 == 'F'){ // Found the reading "nav1 stand-by"
    delay (11);
    navsb = "";
    navsb += char(Serial.read());
    navsb += char(Serial.read());
    navsb += char(Serial.read());
    navsb += char(Serial.read());
    navsb += char(Serial.read());
    navsb += char(Serial.read());

    //pads it up to 6 caracters
    if (navsb != navsbold){
    //delay (11);
    lcd.setCursor(8, 3);
    delay (11);
    lcd.print(navsb);
    navsbold = navsb;
    }
    }
    if (j1 == 'J'){ // Found the reading "nav1 stand-by"
    delay (11);
    trans = "";
    trans += char(Serial.read());
    trans += char(Serial.read());
    trans += char(Serial.read());
    trans += char(Serial.read());

    //pads it up to 4 caracters
    if (trans != transold){
    //delay (11);
    lcd.setCursor(16, 3);
    delay (11);
    lcd.print(trans);
    transold = trans;
    }
    }

    } //end of serial loop
    } //end of void loop

    void ROTARYS() {//now the bit for the rotary encoder input
    long X1 = (quad1.position());
    if (X1 != Xold1) { // checks to see if it different
    // Com1 rotary encoder output
    if (X1 > Xold1) {
    if (digitalRead(10)==0 ) {
    Serial.println("A02");
    }
    else Serial.println("A04");
    }
    if (X1 < Xold1) {
    if (digitalRead(10)==0 ) {
    Serial.println("A01");
    }
    else Serial.println("A03");
    }
    if (quad1.position() > 1000){ // zero the rotary encoder count if too high or low
    quad1.position(0);
    }
    if (quad1.position() < -1000){
    quad1.position(0);
    }
    Xold1 = X1; // overwrites the old reading with the new one.
    }
    long X2 = (quad2.position());
    if (X2 != Xold2) { // checks to see if it different
    // Com1 rotary encoder output
    if (X2 > Xold2) {
    if (digitalRead(27)==0 ) {
    Serial.println("A13");
    }
    else Serial.println("A15");
    }
    if (X2 < Xold2) {
    if (digitalRead(27)==0 ) {
    Serial.println("A14");
    }
    else Serial.println("A16");
    }
    if (quad2.position() > 1000){ // zero the rotary encoder count if too high or low
    quad2.position(0);
    }
    if (quad2.position() < -1000){
    quad2.position(0);
    }
    Xold2 = X2; // overwrites the old reading with the new one.
    }
    long X3 = (quad3.position());
    if (X3 != Xold3) { // checks to see if it different
    // Com1 rotary encoder output
    if (X2 > Xold2)
    Serial.println("B11");
    if (X2 < Xold2)
    Serial.println("B12");

    if (quad2.position() > 1000){ // zero the rotary encoder count if too high or low
    quad2.position(0);
    }
    if (quad2.position() < -1000){
    quad2.position(0);
    }
    Xold2 = X2; // overwrites the old reading with the new one.
    }
    }// end of rotarys

    void INPUTPINS(){
    // Now the bit for the "keys" input
    stringnewstate = "";
    for (int pinNo = 10; pinNo <= 23; pinNo++){// checks all the pins 10 to 53
    pinStateSTR = String(digitalRead(pinNo));
    oldpinStateSTR = "";
    oldpinStateSTR += String(stringoldstate.charAt(pinNo - 10));
    if (pinStateSTR != oldpinStateSTR) {// yes it's different
    if (pinNo == 11 and pinStateSTR == "0") { //Change-over button is pressed
    Serial.println("A06");//com1
    }
    if (pinNo == 23 and pinStateSTR == "0" ) { //Change-over button is pressed
    Serial.println("A18");//com1
    }
    Serial.print ("D");
    if (pinNo < 10) Serial.print ("0");
    Serial.print (pinNo);
    Serial.println (pinStateSTR);
    delay(11);
    }
    stringnewstate += pinStateSTR;
    }

    stringoldstate = stringnewstate;
    delay(11);

    }

  6. #6
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    275
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: How to vonnct many rotay encoders

    I'm a little confused here. It looks like you are mixing sketch for link2fs_inout and link2fs_multi. If you use Link2fs Multi, see in the programfolder for Link2fs_Multi. there you will find the "Multi_Keys_RotaryEncoders.ino" in the Demo iNOS folder.
    Start with this Sketc and take one encoder at the time, see that it works before adding the next and/or adding functions to the encoder.
    Removing and changing names and remarking / Description of the functions, before You understand the code, not so good idea.
    Start the sketch using the things that is difficult, the encoders. Exclude all the things, not connected to the encoders. and get the encoders to work.
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  7. #7
    75+ Posting Member
    Join Date
    Feb 2010
    Location
    London
    Posts
    87
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: How to vonnct many rotay encoders

    You right am mixing in out and multi,I was thinking tat it would be straight thing to adjust it.
    Anyway I will try that INO,
    I was thinking about one more thing as well

    pins 22 to 54 on arduino mega,as long as they are st as output and on HIGH they should not have a problem with encoders.
    I am asking because all the examples have the encodes set in pin from 2 to 7 or so.

    Anyway thank you one more time for you advice and help

  8. #8
    75+ Posting Member
    Join Date
    Feb 2010
    Location
    London
    Posts
    87
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: How to vonnct many rotay encoders

    I tried the example you advice me
    t does not work.
    It works fine on pins 8 and 9

    but if i o above 10 it gets nothing jst like the encoder is not there

    /*
    This code is in the public domain
    For use with "Link2fs_Multi"
    Jimspage.co.nz
    My thanks to the Guys that gave me snippets of code.

    This sets the Arduino Mega card for 3 rotary encoders and "keys" input except pin 13.
    Attach a switch to any pin from pin 8 upwards (except 13) and program that pin in "Multi"
    Everything to do with "Keys" starts with a "K" in this code.
    Everything to do with rotary encoders starts with a "R" in this code.
    The Quadrature2 library is available from my site Jimspage.co.nz. (Special thanks to Bill Holland)
    It's here ,, http://www.jimspage.co.nz/encoders2.htm (Near the bottom of the page)
    Rotary encoder 1 is on pins 2 and 3
    Rotary encoder 2 is on pins 4 and 5
    Rotary encoder 3 is on pins 6 and 7
    The "push" switch on each one is connected to a "Keys" input pin and just seen as a switch.

    To change this to suit a Uno,, do the following ,,,,
    Line 29 ,, change "70" to "20"
    Line 117 ,, change "70" to "20"
    That will make all the pins from pin 8 upwards on a Uno, as "Keys" input pins. (Except pin 13)

    */
    #include "math.h"
    #include "Quadrature.h"
    Quadrature quad1(36, 3;
    Quadrature quad2(28, 30);
    Quadrature quad3(6, 7);

    int CodeIn;// used on all serial reads
    int KpinNo;
    int Koutpin;

    String KoldpinStateSTR, KpinStateSTR, Kstringnewstate,Kstringoldstate;

    int R;// a variable
    int Rold;// the old reading
    int Rdif;// the difference since last loop
    int R2;// a second test variable
    int R3;// a second test variable
    int Rold2;// a second loop old reading
    int Rdif2; // the second test difference
    int Rold3;// a second loop old reading
    int Rdif3; // the second test difference

    void setup()
    {
    Kstringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";

    for (int KoutPin = 40; KoutPin < 54; KoutPin++)// Get all the pins ready for "Keys"
    {
    pinMode(KoutPin, INPUT);
    digitalWrite(KoutPin, HIGH);
    }
    Serial.begin(115200);
    }

    void loop() {
    {KEYS();} //Check the "keys" section
    {ENCODER();} //Check the Rotary Encoders
    if (Serial.available()) {// Check if serial data has arrived from PC
    CodeIn = getChar();
    if (CodeIn == '=') {EQUALS();} // The first identifier is "="
    if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<"
    if (CodeIn == '?') {QUESTION();}// The first identifier is "?"
    if (CodeIn == '/') {SLASH();}// The first identifier is "/" (Annunciators)
    }

    }

    char getChar()// Get a character from the serial buffer
    {
    while(Serial.available() == 0);// wait for data
    return((char)Serial.read());// Thanks Doug
    }

    void EQUALS(){ // The first identifier was "="
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {// Now lets find what to do with it
    case 'A'://Found the second identifier
    //Do something
    break;

    case 'B':
    //Do something
    break;

    case 'C':
    //Do something
    break;

    //etc etc etc
    }
    }

    void LESSTHAN(){ // The first identifier was "<"
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {// Now lets find what to do with it
    case 'A'://Found the second identifier
    //Do something
    break;

    case 'B':
    //Do something
    break;

    case 'C':
    //Do something
    break;

    //etc etc etc
    }
    }

    void QUESTION(){ // The first identifier was "?"
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {// Now lets find what to do with it
    case 'A'://Found the second identifier
    //Do something
    break;

    case 'B':
    //Do something
    break;

    case 'C':
    //Do something
    break;

    //etc etc etc
    }
    }
    void SLASH(){ // The first identifier was "/" (Annunciator)
    //Do something
    }
    void KEYS()
    {
    Kstringnewstate = "";
    for (int KpinNo = 40; KpinNo < 54; KpinNo++){
    KpinStateSTR = String(digitalRead(KpinNo));
    KoldpinStateSTR = String(Kstringoldstate.charAt(KpinNo - 40));
    if (KpinStateSTR != KoldpinStateSTR)
    {
    if (KpinNo != 13){
    Serial.print ("D");
    if (KpinNo < 10) Serial.print ("0");
    Serial.print (KpinNo);
    Serial.println (KpinStateSTR);
    }
    }
    Kstringnewstate += KpinStateSTR;
    }
    Kstringoldstate = Kstringnewstate;
    }
    void ENCODER(){
    R =(quad1.position()/2); //The /2 is to suit the encoder(See my website)
    if (R != Rold) { // checks to see if it different
    (Rdif = (R-Rold));// finds out the difference
    if (Rdif == 1) Serial.println ("A01");//Com1 Mhz down
    if (Rdif == -1) Serial.println ("A02"); //Com1 Mhz up
    Rold = R; // overwrites the old reading with the new one.
    }
    R2 =(quad2.position());
    if (R2 != Rold2) {
    (Rdif2 = (R2-Rold2));
    if (Rdif2 == 1) Serial.println ("A03"); // Com1 Khz down
    if (Rdif2 == -1) Serial.println ("A04");//Com1 Khz up
    Rold2 = R2;
    }
    R3 =(quad3.position());
    if (R3 != Rold3) {
    (Rdif3 = (R3-Rold3));
    if (Rdif3 == 1) Serial.println ("A55"); // VOR bug down
    if (Rdif3 == -1) Serial.println ("A56"); //VOR bug up
    Rold3 = R3;
    }

    }

  9. #9
    500+ This must be a daytime job Jim NZ's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    764
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: How to vonnct many rotay encoders

    I just loaded your above INO and fitted 3 rotarys where it's indicated and it works fine.

    What is wrong here is you haven't read the documentation with the download.

    Have a look at this thread ,,,
    http://www.mycockpit.org/forums/showthread.php?t=27171

    The reason that it is adjustable is, the higher you have it and if your INO is a large one ,, then there may be a speed impact on returns.
    (No use scanning pins not involved with rotarys)
    Soooo ,, if you are heading for a very long involved INO ,,, it's probably best to keep the Rotarys in the lower pin numbers.
    In an average INO tho ,, it wont matter two hoots. (My rotarys are generally all in the range 24 to 40)

    Jim

    Edit ,,, Just to explain ,, it wont actually scan the non-rotary pins but the library still has to "roll" itself up, in the library's 'for' loop to the required maximum pin No.
    Last edited by Jim NZ; 12-12-2013 at 09:54 PM.
    www.jimspage.co.nz/intro.htm
    All this and Liz still loves me ! !

  10. #10
    75+ Posting Member
    Join Date
    Feb 2010
    Location
    London
    Posts
    87
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: How to vonnct many rotay encoders

    Hi there Jim
    Thank you for all you help.
    Well I had a small mishap yesterday I was rewirering my mega but when put it all togather it as not working.
    Anyway now it's working but I have a new problem.

    When I was uploading new sketch before the mishap my lcd was going off and then back on again.
    ow It stays on all the time,the data on te display are updated but when I load the sketch that has no display in it,display still stays on with data from previous sketch.

    As foo the encoders changed the bit in the library but still no result.

    I thinking maybe I need to reset my mega or change tome settings.

    Again please HELP