Page 3 of 5 FirstFirst 12345 LastLast
Results 21 to 30 of 50

Thread: Magnetic compass build and code

  1. #21
    75+ Posting Member vikingsraven's Avatar
    Join Date
    Dec 2012
    Location
    UK
    Posts
    89

    Re: Magnetic compass build and code

    youve created an array
    just use
    Digit = ""; // Clear Digit
    Digit += getChar(); // Get a character put it in the String "Digit"
    Digit += getChar();
    Digit += getChar();
    then convert to int.
    += appends the numbers one after the other then to int converts to an integer number.

  2. #22
    25+ Posting Member Doug77's Avatar
    Join Date
    Aug 2012
    Location
    scotland
    Posts
    49

    Re: Magnetic compass build and code

    Thanks Mark,

    This is what I used to extract the heading from LINK2FS so that seems to tally??

    case 'J'://Found the reading "HEADING"
    Count = 0;
    while (Count < 3 )
    {
    Digit = "";
    Digit += getChar();
    if (Digit ==".")
    {
    Digit = "";
    Digit += getChar(); }
    Compass[Count] = Digit.toInt();
    Count++;

    so am I correct the "Compass" would be the heading integer of say 345 (or whatever the heading is)..??

    should Compass[Count] = Digit.toInt(); be written as int Compass = Digit.toInt();

    How can I then make that (and other integers I want to check) print to card out in LINK2FS ?? would Serial.println (Compass); do the trick??

    Thanks matey
    Doug..

  3. #23
    75+ Posting Member vikingsraven's Avatar
    Join Date
    Dec 2012
    Location
    UK
    Posts
    89

    Re: Magnetic compass build and code

    Code:
    case 'J';
    Digit="";                                //this will clear the string register
    Digit += getChar();                // this gets a char ( chars are indiviual ascii numbers) and append to Digit, so Digit will now be 3 for example
    Digit += getChar();               // this will get the second digit and stick it onto Digit so it now = 32 for example
    Digit +=getChar();                // this will get the third character and append it to Digit soe now for example 325
    Compass = Digit.toInt();       // this converts the string 325 to the number 325 decimal
    youll have to change Compass at the begining to Int Compass. otherwise youll get errors.
    not sure what you mean by
    How can I then make that (and other integers I want to check) print to card out in LINK2FS ?? wouldSerial.println (Compass); do the trick??
    Serial.println(Compass) will send that to your serial port, so if you have the ide setup to monitor it will come up on there println puts a line return and carriage return on it so it will print once per line.

  4. #24
    25+ Posting Member Doug77's Avatar
    Join Date
    Aug 2012
    Location
    scotland
    Posts
    49

    Re: Magnetic compass build and code

    Thanks Mark,

    Yup Ive changed the beginning to int Compass,

    The IDE Monitor will not operate (COM port in use by LINK2FS) when Im running LINK2FS so to see if my integers are showing what they should be I turn on the Card Monitor in LINK2FS and it displays anything the arduino card is sending over the Serial...hence if I send
    Serial.println(Compass) it will echo in the Card monitor

    Excellent stuff mate your help has been very useful

    Doug..

  5. #25
    75+ Posting Member vikingsraven's Avatar
    Join Date
    Dec 2012
    Location
    UK
    Posts
    89

    Re: Magnetic compass build and code

    doug give this a go, make sure your in monitor and have the card 1 selected and that extraction
    Code:
    /*     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. 
        
        Here is the basic concept of my lay-outs.
        You could actually use this INO as a starting point for your own project.
        Deleting all the comments makes it really simple to follow once you understand the concept
    */
    
    
    
    
    int CodeIn;// The normal declearations go here
    int Compass;
    String Digit;
    void setup(){
       Serial.begin(115200); 
           // The normal startup stuff goes here
    }
    
    
    void loop() {
      {OTHER();}// Check for "Other" things to do. (Non extraction stuff)
      if (Serial.available()) {  //Check if anything there
        CodeIn = getChar();      //Get a serial read if there is.
        if (CodeIn == '=') {EQUALS();} // The first identifier is "=" ,, goto void EQUALS
        if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<" ,, goto void LESSTHAN
        if (CodeIn == '?') {QUESTION();}// The first identifier is "?" ,, goto void QUESTION
        if (CodeIn == '/') {SLASH();}// The first identifier is "/"  ,, goto void SLASH (Annunciators)
      }
    }
    
    
    char getChar()// Get a character from the serial buffer(Dont touch)
    {
      while(Serial.available() == 0);// wait for data (Dont touch)
      return((char)Serial.read());// (Dont touch) Thanks Doug
    }
    
    
    void OTHER(){
    /* In here you would put code that uses other data that
    cant be put into an "extraction void" that references something else.
    Also in here you would put code to do something that was not
    relying on a current extraction.
    (Remember - The identifier voids only trigger when it receives that identifier)
    */
    }
    
    
    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 'W':
           //Do something
        break;
         
        case 'a':
           //Do something
        break;
           //etc etc etc
           // You only need the "Case" testing for the identifiers you expect to use.
         }
    }
    
    
    void LESSTHAN(){    // The first identifier was "<"
          CodeIn = getChar(); // Get another character
      switch(CodeIn) {// Now lets find what to do with it
         case 'J':
    Digit="";                                //this will clear the string register
    Digit += getChar();                // this gets a char ( chars are indiviual ascii numbers) and append to Digit, so Digit will now be 3 for example
    Digit += getChar();               // this will get the second digit and stick it onto Digit so it now = 32 for example
    Digit += getChar();                // this will get the third character and append it to Digit soe now for example 325
    Compass = Digit.toInt();       // this converts the string 325 to the number 325 decimal //Do something (See void EQUALS)
    
    Serial.print("Compass");
    Serial.println(Compass);
    break;
    }
    }
    
    
    void QUESTION(){    // The first identifier was "?"
           //Do something (See void EQUALS)
    }
    
    
    void SLASH(){    // The first identifier was "/" (Annunciators)
      //Do something (See void EQUALS)
    }

  6. #26
    25+ Posting Member Doug77's Avatar
    Join Date
    Aug 2012
    Location
    scotland
    Posts
    49

    Re: Magnetic compass build and code

    Hi Mark,

    wont compile missing >> " << from Serial.print("Compasserial.println(Compass) ; and if I amend to Serial.print("Compasserial.println"(Compass) ; or Serial.print(Compasserial.println(Compass) ;
    it doesnt like it

    Doug..


  7. #27
    25+ Posting Member Doug77's Avatar
    Join Date
    Aug 2012
    Location
    scotland
    Posts
    49

    Re: Magnetic compass build and code

    This is my version..

    case 'J'://Found the reading "HEADING"
    Count = 0;
    while (Count < 3 ) // Counting fro 0 to 3. three digits to store as the compass
    { //
    Digit = ""; // Clear Digit
    Digit += getChar(); // Get a character put it in the String "Digit"
    if (Digit ==".") // ****** This looks for the "." *************
    {
    Digit = ""; // If we find the "." we clear it and get the next digit
    Digit += getChar(); // Because we know where the "." always goes.
    }
    int compass = Digit.toInt(); // Turn String Digit into an Integer and store it in the Array for later
    Count++; // add one to the count

    {
    Serial.print("compass=") ;
    Serial.print(compass);
    }

    but it still seems to break down the number into 3 parts and prints them one at a time 3, 4, 5, instead of 345

  8. #28
    75+ Posting Member vikingsraven's Avatar
    Join Date
    Dec 2012
    Location
    UK
    Posts
    89

    Re: Magnetic compass build and code

    wont compile missing >> " << from Serial.print("Compasserial.println(Compass) ; and if I amend toSerial.print("Compasserial.println"(Compass) ; or Serial.print(Compasserial.println(Compass) ;
    it doesnt like it
    just copied and pasted it back into compiler and its fine, looks like its missed a linefeed
    should be
    Serial.print("Compass"); // this just prints the word compass
    Serial.println(Compass);// this will print the value and line feed.
    you dont need to do the while loop in your code, thats not needed. try that and get back if it still doesn't work.

  9. #29
    25+ Posting Member Doug77's Avatar
    Join Date
    Aug 2012
    Location
    scotland
    Posts
    49

    Re: Magnetic compass build and code

    Thats the one Mark... works great

    thank you good Sir!!!

    Im now going to go compare what I did to how it actually should be lol ..Gracias

    Doug..

  10. #30
    75+ Posting Member vikingsraven's Avatar
    Join Date
    Dec 2012
    Location
    UK
    Posts
    89

    Re: Magnetic compass build and code

    no problem, we will walk through this, the best way to learn is jump in, im no expert but they say you learn from your mistakes , thats why i know so much! lol
    case 'J'://Found the reading "HEADING"
    Count = 0;
    while (Count < 3 ) // Counting fro 0 to 3. three digits to store as the compass
    { //
    ok the above isnt needed from Count, its creating a loop so your doing the next lines 3 times

    Digit = ""; // Clear Digit
    Digit += getChar(); // Get a character put it in the String "Digit"
    ok this bit is basically saying, make string Digit = "" , then append the char value, then it loops clears digit and then adds the next char into .... hence why your only getting one number.

    if (Digit ==".") // ****** This looks for the "." *************
    {
    Digit = ""; // If we find the "." we clear it and get the next digit
    Digit += getChar(); // Because we know where the "." always goes.
    }
    now this bit is looking for a "." ,now as your not getting one it wont run this bit of code and is a repeat of the above

    int compass = Digit.toInt(); // Turn String Digit into an Integer and store it in the Array for later
    Count++; // add one to the count
    this bit converts what is in Digit ( a String, so a list of ascii characters of variable length) into a human readable integer thats stored in compass register
    the count ++ just adds 1 to count then the whole loops starts again

    {
    Serial.print("compass=") ;
    Serial.print(compass);
    }
    this bit will run after the other bit, it doesn't need to have the curly brackets round it. if you think of the brackets as an envelope that your putting the info in, you can put envelopes within envelopes etc, but if you stuck the back of one envelope to the other it all gets messed up.
    in the ide if you double click on a curly bracket it will highlight all the code that is within that section.
    Hope this helps clear up what was happening.
    if anyone spots anything i missed please say.

Page 3 of 5 FirstFirst 12345 LastLast