Help Troubleshooting My Code

Hello everyone,
I have two pieces of code that work as intended, and now that I am trying to combine them, they are not fully working. I am relatively new to this, so I am thinking its a simple syntax error or myself completely misunderstanding how something works. Both of the pieces I am working with are taken from tutorials and slightly modified by myself as I am not competent enough to right my own code from scratch yet.

My attempt at combining two codes:
2Stepper_and_Parsing_Test.ino

Code 1:
Stepper_Test_2_Motors_pt2.ino

Code 2:
Serial_Parsing_Test2.ino

(tried posting code but exceeds character limit sorry )

In the combined code, I am inputting and parsing <01> instead of <01,1000>, removing one of the two parsed integers. I deleted a couple lines in the reference code pertaining to the second integer when I added it to simplify things. I will be writing code in the future that needs both, but this current one does not.
When I run this code I see in the serial monitor:
"Motor Position Testing
Positions Available 1-9
Syntax <01>"
When I input and send <02> into the serial monitor I get an extra line:
"Received Bottle Number: 2"
I was expecting to see two extra lines, one like the above but also:
"Moving to Position 2"
which would indicate to me that the coordinateX and Y variables are getting recorded, but unfortunately I do not think that portion of the code is working.
I do not have the motors wired in, I have not gotten to that portion of the project yet, so for now I am relying on the serial monitor output to troubleshoot.
Thanks in advance for any help!

Serial_Parsing_Test2.ino (3.33 KB)

Stepper_Test_2_Motors_pt2.ino (5.56 KB)

2Stepper_and_Parsing_Test.ino (8.39 KB)

why don't you try to start from scratch to build something that matches your exact needs.

--> start by defining the system (seems there is an emitter and receiver) and the expected behavior

consider

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char * strs [] = {
    "<0,1>",
    "<1,3>",
    "<1,2,3>",
};

#define N_STRS  (sizeof(strs)/sizeof(char*))

int
parseStr (
    char *str,
    int  *vals )
{
    int     n = 0;
    char    s [80];

    strcpy (s, str+1);   // skip "<"

    char *t = strtok ( s, ",");
    while (t)  {
        vals [n++] = atoi (t);
        t          = strtok ( NULL, ",");
    }

    return n;
}

int main ()
{
    int  vals [10];

    for (int i = 0; i < N_STRS; i++)  {
        printf ("  %s -- ", strs [i]);

        int n = parseStr ((char*) strs [i], vals);
        for (int j = 0; j < n; j++)
            printf (" %d", vals [j]);
        printf ("\n");
    }
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.