In a nut shell. I have a 4Dsystems monitor w/touch screen (uLCD43PT). I have created some Winbuttons that are to select some parameters. Touching one of the buttons will send down the serial port a 6 hex digit code. What I would like to do is read these into an array and then send the 3rd digit back to the 4D display that will now read a file from the uSD. My lack of knowledge is how to put these 6 elements into 6 positions of the array.
The code at this time is just dealing with reading these 6 elements into the array and then read just the one element at 3 position and then print it to the hardware serial port (console). I dont mind reading. Just cant find an example of how to do this.
Thanks for looking and any help you can pass on to an old dog. Where was this stuff 40 yrs ago when I was younger?
#include <SoftwareSerial.h>
#define RESETLINE 4
SoftwareSerial serial(10, 11);
void setup()
{
Serial.begin(9600);
serial.begin(9600);
pinMode(RESETLINE, OUTPUT);
digitalWrite(RESETLINE, 0); // Reset the Display via D4
delay(100);
digitalWrite(RESETLINE, 1);
delay (5000); //let the display start up after the reset (This is important)
}
void loop ()
{
if (serial.available())
{
int vaNum[6];
for (int n = 0; n < 6; n++);
byte x = serial.read();
vaNam[n] = x;
{
Serial.println(vaNam[2]);
}
}
}
Thanks gents. Trying to read and adapt code from others projects. Just didnt see anything like this. Much appreciate the help. Will try these suggestions tomorrow. Getting late here in the mid-west of USA.
Use the auto-format in the arduino IDE (Apple-T key on my machine). This will help catch errors like this: you would be able to see that the statements below the for() are not subordinate.
In general, C++ does not use white space to indicate program structure. A C++ program is unaltered if you strip out the comments and replace most of the white space (spaces, tabs, line-breaks) with a single space character and the whole thing winds up being one long line. Program structure is controlled by syntax and the characters that delimit syntax.
A function is: a function declaration folloed by a statement list.
A statement list is: a list of statements surrounded by braces.
Well one thing is for sure, this place is not dry with all of the joking. Ya I saw after the fact that I left off the "n" of learn. Was hoping that no one would pick up on it.
Ok, so I tried the above suggestions except for the changing out the chr for int. Was not sure as to which one you spoke of. I tried the old 101 ways to skin a cat to fix my problems. I have it down to one error now. Here is the revised code:
[code]
#include <SoftwareSerial.h>
#define RESETLINE 4
SoftwareSerial serial(10, 11);
void setup()
{
Serial.begin(9600);
serial.begin(9600);
pinMode(RESETLINE, OUTPUT);
digitalWrite(RESETLINE, 0); // Reset the Display via D4
delay(100);
digitalWrite(RESETLINE, 1);
delay (5000); //let the display start up after the reset (This is important)
}
void loop ()
void vaNum[6]
{
int n
if (serial.available())
for (int n = 0; n < 5; n++)
byte x = serial.read();
vaNam[n] = x;
{
Serial.println(vaNam[2]);
}
}
[/code]
And here is the error code:
Temp1:19: error: expected initializer before 'void'
expected initializer before 'void'
Shoot, figured that I would find a group of 14 to 26 yr old geeks. Not a group of old farts
Truth be told PaulS, I am not real sure either. LOL
My only means at this time to learn C++ is via others work / example. And what I have read and how I interpret what it means. "Void" can be put in front of things that have no return. And I have seen arrays being initialized with just a name and size such as my above "vaNum[6];". Ok, will try by removing the "void" and adding a semi colon at the end. I presume you want me to move it below the first curly bracket. Next time I will come back with a long list of errors. That is what I have seen before. But will give it a try cause I am really looking for help and I have no idea what it is going to take to get what I am looking to do.
Paul1958:
And I have seen arrays being initialized with just a name and size such as my above "vaNum[6];".
Not in C++ you haven't.
Variables are defined as:
type name;
always.
So, it would have to be:
int vaNum[6];
void is not a valid variable type. It is only used to say a function has no return value.
e.g;
void fn();
The semicolons are very, very, very important in C++. They mark the end of statements since whitespace means nothing in C++ (you can put as many statements on one line as you like, as long as the semilcolons are there). The whitespace we use in C++ (newlines, indents, etc.) is to help us read it, not the compiler.
If you please. Please read my first post. In it you will see that I have a line that reads:
int vaNum[6];
And the compiler did not like something in that rendering of the code.
Thanks for your help
What I am getting from the 4D display is a series of numbers that represent the code for the pressing of a Winbutton. This code is coming down its serial port to a softwareSerial into the Arduino. I now want to read in these 6 digits into an array. And then use the 3rd item (which is the actual number that represents the actual key pressed. This number will become part of a file name ('para'n'.txt') that will call up a file with parameters for the rest of the program.
I would know how to do this in basic. But C++ is kicking my butt. to many rules about syntic and scopes and functions that I reall do not fully understand yet. But I will keep reading and hope you all will help me over some of the rough spots. Thanks
If you please. Please read my first post. In it you will see that I have a line that reads:
int vaNum[6];
And the compiler did not like something in that rendering of the code.
I'd have to see the actual error message to diagnose the problem. We often think the problem is caused by one thing, and is caused by something else entirely. "int vaNum[6];" is perfectly valid C++, as I described above. There is nothing inherently wrong with that line of code.
This line of code "vaNam[n] = x;" would have caused a problem as "n" would not have been in scope.
This compiles. I have no idea whether it does what you want, or not.
#include <SoftwareSerial.h>
#define RESETLINE 4
SoftwareSerial serial(10, 11);
void setup()
{
Serial.begin(9600);
serial.begin(9600);
pinMode(RESETLINE, OUTPUT);
digitalWrite(RESETLINE, 0); // Reset the Display via D4
delay(100);
digitalWrite(RESETLINE, 1);
delay (5000); //let the display start up after the reset (This is important)
}
int valNum[6];
void loop ()
{
if (serial.available())
{
for (int n = 0; n < 5; n++)
{
byte x = serial.read();
valNum[n] = x;
}
Serial.println(valNum[2]);
}
}
Notice that serial.available() will evaluate to true (which is NOT the same as returning true) as soon as there is one byte to read. That does NOT mean that is then OK to read 5 bytes.
First thanks for the help. Like I said before I have no problem with reading and really wished that someone had pointed me to reading a reference that would have point to what I was doing wrong. This morning I was looking at my faulty code and kept seeing something about scope. So I went back to a site I found "Learn C++". Found a few examples and started working on the code some. And one of my errors is that I need to start to use a note pad so I can keep my variable names straight. Paraphrasing a line from the TV show Paper Chase. "I come in here with a muddied mind, and leave thinking like a programmer".
Sorry for the trouble. And thanks for showing me how it is done.