I can't get that to compile because the IDE goes into a loop so I can't test anything.
However, you haven't bracketed the if statement properly. When there's only one statement it should be:
if () statement1; else statement2;
but you have
if () statement1 else statement2
Best thing to do would be to add brackets to the if so that it has this structure:
Best thing to do would be to add brackets to the if so that it has this structure:
Code:
if () {statement1} else {statement2}
and then the semicolon isn't required.
What? So the code below should compile?
void setup() {
int a;
if (true) {
a = 5
} else {
a = 6
}
}
void loop() {
}
CrossRoads:
All the # statements need to be at the top of the sketch.
Nope, #defines can show up anywhere, but they will only be visible to code below it in the file, which can be problematic on the arduino since it munges files together.
Sorry about confusion...
It's a macro inside LED_2416.cpp (matrix driver library). I didn't write it.
It supposed to translate Arduino pin numbers into hardware pins thus making digitawrites 100x faster. And it works, I just couldn't get this Macro to compile for some reason.
"/" are meant to be carryover to next line, without them whole thing will need to be written on single line.
And basically syntax is correct. If I make into a function (i.e. "void fWriteB(byte pin, byte val) ") it compiles, but doesn't give me fast pin write effect for some reason. C++ macros apparently have their own syntax, and this is too advanced for me at this point
Fortunately I finally found substitution macro that works:
P.S. I'm writing sketch for my wearable LED display (w/ dual 24x16 LEDs) that I plan to show off at Maker's fair. It was working fine with my ATMega1284p board, but that was too big to fit inside the case, so I'm rewriting it to run off small ATMega328 board. I was stuck on this fastwrite for a while, thus my question. But it's good now! Thank you all!
KeithRB:
CrossRoads:
All the # statements need to be at the top of the sketch.
Nope, #defines can show up anywhere, but they will only be visible to code below it in the file, which can be problematic on the arduino since it munges files together.
I think you both right. In main sketch it should be at the top, but if you including external library (like in my case), that library can have it anywhere.
I don't know why you would use a macro to implement a long-winded function like that. Your program will include that code at every instance in your code where you invoke your pinWrite( ) pseudo function. If you called that function more than a few times, you would very quickly run out of program memory. And, if execution speed is important, as you seem to think it is, there are several much faster ways to identify the correct pin, than those long switch statements.