Hello,
This is my first post and using the Arduino uno R3 board from Elegoo.
I'm a newbie to C++ but i want to learn it a bit as i go (tutorials with some of my own modifications to understand how the code works) Because i'm a bit 'slow' and don't have the courage to learn C++ for the first few months.
Code below:
I'm trying to understand what the void functions are used for. I suppose to create clarity and convenience in the code.
I'm trying to use the extra 'void' as some kind of a subroutine. The extra void function works fine to store a int and then use this int in the main void loop to do something with it (in this case just Serial.println to check if it works).
I'm not able to do this with a piece of text that i store as a string or as a char array. It just keeps giving two empty line or a strange character what suggests that i'm 'understanding' something fundamentally wrong about the use of voids.
Although 'Serial.print' works within the limits of the void itself (both in void loop and in void sentence. you can see the extra code after //).
In the future i want a easy&fast way to adjust a piece of text; that needs to be shown on a display; in the code. Preferable with a separate piece of code (void?) that can get repeated in the main loop.
It breaks my mind that i can use the content of the memory location for the int's but not the memory locations for the char array. I'm able to use strings instead of char array's (with the same bad result) but i read that the use of strings is very memory inefficient.
Sorry for this post but i'v been searching and trying for two days now and i can't find a answer. I'm almost done with it....and ready to throw my experimenting kit in the bin.
Please correct any blunders.
THX!!
int returnvalue_one;
int returnvalue_two;
char mysentencearray;
void setup() {
Serial.begin(9600);
returnvalue_one = 0;
returnvalue_two = 0;
}
void loop() {
randomnumberlow();
randomnumberhigh();
sentence();
Serial.println(returnvalue_one);//this works
Serial.println(returnvalue_two);//this works
//String mysentence = "This is a sentence";
//Serial.println(mysentence);
//char mysentencearray[19] = "This is a sentence";//a sentence as characters in a array
Serial.println(mysentencearray);//this works not!
delay(500);
}
void randomnumberlow() {
returnvalue_one = random(0,200);//random number from to
}
void randomnumberhigh() {
returnvalue_two = random(201,400);//random number from to
}
void sentence(){
//String mysentence = "This is a sentence";
//Serial.println(mysentence);
char mysentencearray[19] = "This is a sentence";//a sentence as characters in a array
//Serial.println(mysentencearray);
}