how do I check if an input from the monitor is in a array and tell user to try again if no match or carry on if there is. I have looked all over for something to use.
Thank's Bob
Hello radio friend
Post your current sketch, well formated, with comments and in so called code tags "</>" and schematic to see how we can help.
73 es have a nice day and enjoy coding in C++.
Our first thought is always … show us your latest attempt (in code tags), then we can lead you forward from there.
An input from the monitor is a string.
You take in the string and subdivide it in numbers based on some separator.
So you first need to tell the user how your the input should be formatted.
During parsing of your string, you should check if the user used a correct format.
When you have your number in a substring, you need to convert it to a number type (int or float). and put it in your array (prevent writing data outside bounds)
There ar handy string handling functions to do these operations. But for a beginner it won' t be easy.
Maybe start reading 1 number, then one number and a separator, then 2 numbers.
That way you can tackle one problem at a time .
For a 2D array you will need 2 types of separators.
The serial input basics tutorial may be of interest. Serial Input Basics - updated
//I don't know if this is how to post a sketch.
// What I'm trying to do with this program is to get input
// that can be sent to a G-code sender program to move steppers
// to a positon that will be put in the n array.
int n[ 27 ] = {
9000, 9001, 9002, //6m
8000, 8001, 8002, //10m
7000, 7001, 7002, //12m Pac band numbers????
6000, 6001, 6002, //15m
5000, 5001, 5002, //17m
4000, 4001, 4002, //20m
750, 100, 450, //40m
2000, 2001, 2002, //80m
1000, 1001, 1002 //160m
} ;
char X = (0);
char Y = (0);
char Z = (0);
int band;
int a = n [0];
int b = n [0];
int c = n [0];
String msg = (" Enter Operating Band");
String msg2 = ("Your Operating Band is: ");
String msg3 = (" 6,10,12,15,17,20,40,80,160");
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
//delay(250);
Serial.println(msg);
Serial.println(msg3);
while (Serial.available() == 0);
band = Serial.parseInt();
Serial.print(msg2);
Serial.print(">>>> ");
Serial.print(band);
Serial.println(" <<<<");
{ if ((band) == (6))(a) = n[0], (b) = n[1], (c) = n[2];
else;
}
{ if ((band) == (10))(a) = n[3], (b) = n[4], (c) = n[5];
else;
}
{ if ((band) == (12))(a) = n[6], (b) = n[7], (c) = n[8];
else;
}
{ if ((band) == (15))(a) = n[9], (b) = n[10], (c) = n[11];
else;
}
{ if ((band) == (17))(a) = n[12], (b) = n[13], (c) = n[14];
else;
}
{ if ((band) == (20))(a) = n[15], (b) = n[16], (c) = n[17];
else;
}
{ if ((band) == (40))(a) = n[18], (b) = n[19], (c) = n[20];
else;
}
{ if ((band) == (80))(a) = n[21], (b) = n[22], (c) = n[23];
else;
}
{ if ((band) == (160))(a) = n[24], (b) = n[25], (c) = n[26];
else ;
}
//int (m)=[9]{int(6,10,12,15,17,20,40,80,160) ;}
/*Serial.print(a);
Serial.print("---");
Serial.print(b);
Serial.print("---");
Serial.println(c);
(a) = 750;
(b) = 155;
(c) = 400;
Serial.print(a);
Serial.print("---");
Serial.print(b);
Serial.print("---");
Serial.println(c);
*/
X=Serial.print("G00");Serial.print("X");Serial.println(a);
Y=Serial.print("G00");Serial.print("Y");Serial.println(b);
Z=Serial.print("G00");Serial.print("Z");Serial.println(c);
delay (5000);
}
Before we mention code tags that are needed to format the code for the forum, I see multiple flagrant violations of C/C++ semantics/syntax...
It would have been a good idea to mention that it won't compile or work. It won't be a good idea to add functionality to code that is completely non-functional.
//I don't know if this is how to post a sketch.
// What I'm trying to do with this program is to get input
// that can be sent to a G-code sender program to move steppers
// to a positon that will be put in the n array.
int n[ 27 ] = {
9000, 9001, 9002, //6m
8000, 8001, 8002, //10m
7000, 7001, 7002, //12m Pac band numbers????
6000, 6001, 6002, //15m
5000, 5001, 5002, //17m
4000, 4001, 4002, //20m
750, 100, 450, //40m
2000, 2001, 2002, //80m
1000, 1001, 1002 //160m
} ;
char X = (0);
char Y = (0);
char Z = (0);
int band;
int a = n [0];
int b = n [0];
int c = n [0];
String msg = (" Enter Operating Band");
String msg2 = ("Your Operating Band is: ");
String msg3 = (" 6,10,12,15,17,20,40,80,160");
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
//delay(250);
Serial.println(msg);
Serial.println(msg3);
while (Serial.available() == 0);
band = Serial.parseInt();
Serial.print(msg2);
Serial.print(">>>> ");
Serial.print(band);
Serial.println(" <<<<");
{ if ((band) == (6))(a) = n[0], (b) = n[1], (c) = n[2];
else;
}
{ if ((band) == (10))(a) = n[3], (b) = n[4], (c) = n[5];
else;
}
{ if ((band) == (12))(a) = n[6], (b) = n[7], (c) = n[8];
else;
}
{ if ((band) == (15))(a) = n[9], (b) = n[10], (c) = n[11];
else;
}
{ if ((band) == (17))(a) = n[12], (b) = n[13], (c) = n[14];
else;
}
{ if ((band) == (20))(a) = n[15], (b) = n[16], (c) = n[17];
else;
}
{ if ((band) == (40))(a) = n[18], (b) = n[19], (c) = n[20];
else;
}
{ if ((band) == (80))(a) = n[21], (b) = n[22], (c) = n[23];
else;
}
{ if ((band) == (160))(a) = n[24], (b) = n[25], (c) = n[26];
else ;
}
//int (m)=[9]{int(6,10,12,15,17,20,40,80,160) ;}
/*Serial.print(a);
Serial.print("---");
Serial.print(b);
Serial.print("---");
Serial.println(c);
(a) = 750;
(b) = 155;
(c) = 400;
Serial.print(a);
Serial.print("---");
Serial.print(b);
Serial.print("---");
Serial.println(c);
*/
X=Serial.print("G00");Serial.print("X");Serial.println(a);
Y=Serial.print("G00");Serial.print("Y");Serial.println(b);
Z=Serial.print("G00");Serial.print("Z");Serial.println(c);
delay (5000);
}
In the past I have built 2 Tuners with DC motors they work well but I thought I would try to use steppers. They would be much faster than having to hold a button.
You're adding another item to the Jambalaya, but the rice is burned.
I am not a wizz on the computer but am trying to learn. I added and lost the code tags when I tryed to shorten the program. They were:
Line 73 | Was to be used as input checker |
---|---|
Lines 74-87 | Was for testing the program |
Lines 88-90 | Is what I want to send to G-code sender |
Lines 16-18 | Was an atenpt to get something to use |
The jambalaya compiles fine and runs on my computer |
Hello AC8ZX
The IDE compiler drops a lot of warnings to be checked first.
On the other hand your design has some missing functions like intial state after power up. Take some time, study the IPO Modell and design as paper work a program plan to identify the needed software functions.
73 de gd dx Paul
p.s.
Do you using EchoLink?
If you insert 1234 in the InputBox of Serial Monitor, then these ASCII codes: 31 32 33 34 (one after anothet in hex base and without any space) travel towards the Serial Port of Arduino. So this is an array of ASCII codes for the charcarers 1 2 3 4. If you have a Newline option selected for the "Line ending tab" of the Serial Monitor, then this code: 0A (in hex base) will be transmitted as the last data item.
Just to clarify, this is an example of code you wrote, that will compile, but 100% will not do what you think it does.
runs on my computer
If you run it and it does what you want, please mark the thread "solved".
AARG
you have no idea of what is trying to be done. All of your Help so far is why I did not want to ask for help in the first place. So please ignore any thing involving AC8ZX from now on.
I read the IPO Model, and made a list of steps to take, but I think I let what I aready wrote influnce me. I'm useing a new computer so I had to download EchoLink and setup so the answer is yes. The bigest problem is I had neck cancer and after they did there thing I do not talk that plain, but most people can understand me. So if you want to set up a time let me know. I'm free most any time. Thank's and 73
Well, you had several good responses, starting with reply #4 and reply #5. I think it's not productive to be defensive about your code quality. You won't be able to complete this project without improving it. It has nothing to do with me, or what I say or don't say.
Hello AC8ZX
Post a picture of thr tuner hardware to get a better understanding of the CNC interface.
Have a nice day and enjoy coding in C++.
Also I know what a tuner is, I use a Johnson Viking Matchbox.
I'a'm in AZ for the winter, the tuners are in MI, so I sent what I had. One I used at 100w the other at 1500w. I put the tuners at the base of a 43' vertical with the control in the basement.
Yeah, sometimes it's much better to place the tuner at the antenna feed, like with an EFHW.
Going back to your original question, finding an element in a list is a standard algorithm, it's given to CS students as an exercise at the beginning of year one. So you should be able to find it pretty easily. But the logic is not complex if you have to program it. Basically you set a logical variable to "not found" at the start, and then just step through the array doing comparisons. If any comparison succeeds, you set the variable to "found", sometimes note the position, and exit the loop. If you reach the end, you can tell if it was not found because the variable will still be in a state of "not found". Every respectable high level language has constructs for stepping through a loop with an index, and also string comparisons, it's basic.
It's not rocket science.