We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hello all,
I am just starting with arduino.
I just try to port a program from p5 to arduino and get lots of errors .
1st I use final int to declare const and use them in switch
aduino seems not to know final, but when I delete final, my switch doesn't work. So how can I declare a const? (I mean I could use 0 and 1 and 2 in the switch but urghs...)
2nd: I use lot of 2D arrays, but the [][] puzzles the Arduino compiler... how can I do a 2D array here?
Thanks a lot!
Chrisir ;-)
Answers
It's important to remember that Arduino programming isn't Processing/Java, it's C (and C++ I think). Here are a couple of pages I Googled up:
http://www.tutorialspoint.com/cprogramming/c_constants.htm
http://www.tutorialspoint.com/cprogramming/c_multi_dimensional_arrays.htm
thanks
it's really a pain...
First
is that correct:
int SpielfeldGlobal[intConstEnde] [intConstEnde]; // array
Second
I got a lot of errors I don't understand. Therefore let me ask please:
Do tabs play any other role in arduino than in p5?
I mean when I declare something with global scope on tab 1, is it valid in other tabs?
Does white space play any role? Does a white space (empty space) cause an error somehow? Because some errors don't make any sense otherwise...
Thanks a lot !
Chrisir
The declaration looks good.
It looks to me like Arduino does not combine multiple files as Processing does. (I've never tried it, so I can't be sure.)
Whitespace shouldn't matter.
I'd suggest trying the Arduino programming questions in the forum at http://forum.arduino.cc/ . You're more likely to get folks more knowledgeable than I am.
Closest match for Java's
final
for C isconst
. B-)Alternatively, we can define constants using the pre-processor's directive:
#define
. *-:)I wish Processing's own pre-processor had at least
#define
&#ifdef
. :o3As far as I remember, C arrays are statically compiled. Therefore we can't use variables to define its length! :O
Rather, we can
#define
constants like:Dunno how correct is the snippet above since it's been ages I've programmed in C! ~:>
Another option is more advanced, using malloc() in order to separate a dynamically contiguous block of memory in the heap!
thanks a lot, I use #define now
but the other bugs remain
It worries me that the arduino IDE supports tabs but the compiler doesn't.....
also the line numbers of the error messags are totally off (because of comments and empty lines)
I solved it somehow replacing the 2D array with a 1D array
it was not as hard because I used a function that converted my former 2 indexes for 2D into 1 index for 1D
so when calling functions using x and y I can still use x and y
so that made it easy to rewrite the sketch going from 2D to 1D array
Thanks for all the help.
Chrisir