Let's say you have a line like "G90G01X4.532Y2.750F15"
Coming from sd card how do you break it down to characters integers and floats
The incoming lines are always different
I need to get the different values and do something with them I don't need to print either
Thanks for any help.
Can you give an example of how you would want that line decoded (i.e. as you tear it apart, what should be done with the pieces)? Are there any discernible patterns you always expect to get from the input (e.g. can you say the input will always be organized as a string of pairs consisting of a character(s) followed by a number)?
If G90 then do this
If G01 do this
If X1.532 do this
I'm very new to programming .
The line will always have character then number or two after the x y and z will always have a float after
I'd like to use grbl and have it read from sd card and a touch screen
Is it possible ?
I have something that I made to get the values for a RGB led. It doesn’t work with floats though. I can probably make it handle floats but i’m really tired right now. Perhaps tomorrow when I get a chance.
Give me a second to find the code.
Serial RGB Control
#define IsWithin(x,a,b) ((x >= a) && (x <= b))
#define R_pin 2
#define G_pin 3
#define B_pin 4
typedef struct myColors
// put your setup code here, to run once:
// put your main code here, to run repeatedly:
if (Serial.available() > 0)
myColors ReturnedColors = GetColors(Serial.read());
struct myColors GetColors(char tmp)
static myColors C;
static int Value = 0;
static char Color = 'R';
if (IsWithin(tmp, '0', '9'))
Value = (Value * 10) + tmp - '0';
else if (IsWithin(tmp, 'a', 'z') || IsWithin(tmp, 'A', 'Z'))
Color = tmp;
Value = 0;
C.R = Value;
C.G = Value;
C.B = Value;