Results 1 to 3 of 3
  1. #1
    25+ Posting Member
    Join Date
    Nov 2011
    Location
    UK
    Posts
    74
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    I am going to cry

    So I am using this short and simple code which contains 2 push buttons to increase/decrease my vertical speed and a rotary encode to increase/decrease altitude. When plugged into my arduino nano works fine. But as soon as I wire it all up to my mega the buttons work but the encoder won't do a thing. I have changed all of the necessary info to ensure that I am loading onto the right board.
    Any help would be sure to keep me sane.
    Thanks
    Marc

    Code:
    #include "math.h"
    #include "Quadrature.h"
    Quadrature quad1(22, 23);
    
    
    
    
    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
    
    
    
    
    void setup() 
    {
      Kstringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";
      
      for (int KoutPin = 22; KoutPin <=53; KoutPin++)// Get all the pins ready for "INPUTS"  
      {
        pinMode(KoutPin, INPUT);
        digitalWrite(KoutPin, HIGH);  
      }
     Serial.begin(115200);   
    }
    
    
    void loop() {
      {INPUTS();} //Check the "INPUTS" section
      {ENCODER();} //Check the Rotary Encoders
      if (Serial.available()) {// Check if serial data has arrived from PC
        CodeIn = getChar();
      }
    }
    
    
    char getChar()// Get a character from the serial buffer
    {
      while(Serial.available() == 0);// wait for data
      return((char)Serial.read());// Thanks Doug
    }
    
    
    
    
    void INPUTS() 
    {
      Kstringnewstate = "";
      for (int KpinNo = 22; KpinNo <=53; KpinNo++){
        KpinStateSTR = String(digitalRead(KpinNo)); 
        KoldpinStateSTR = String(Kstringoldstate.charAt(KpinNo - 22));
        if (KpinStateSTR != KoldpinStateSTR)
        {
          if (KpinNo != 13){
    
    
            if (KpinNo == 24 && KpinStateSTR == "0"){Serial.println ("B13");} //Increase vert speed
            if (KpinNo == 25 && KpinStateSTR == "0"){Serial.println ("B14");} //Decrease vert speed
            
          }
        }
        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 ("B11");//Increase reference altitude
       if (Rdif == -1) Serial.println ("B12"); //Decrease reference altitude
       Rold = R; // overwrites the old reading with the new one.
      }   
    }

  2. #2
    Our new friend needs to reach 10 posts to get to the next flight level
    Join Date
    May 2015
    Location
    china
    Posts
    5
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: I am going to cry

    You may need to edit Quadrature.h

  3. #3
    25+ Posting Member
    Join Date
    Nov 2011
    Location
    UK
    Posts
    74
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: I am going to cry

    Many thanks. I went into the 'quadrature.h' file and edit the line '#define DIGITAL_PINS (14)' and changed the 14 to what ever pin no. is going to be was my highest pin on my card.