Go Down

Topic: Apprentice coder (Read 5 times) previous topic - next topic

Pedro147

#50
Nov 01, 2012, 03:59 am Last Edit: Nov 01, 2012, 06:07 am by Pedro147 Reason: 1
I'll remember that. Yes I think that I read somewhere, that you can use some C++ syntax in the Arduino environment, but anything that requires the use of C++ libraries will not work. Thanks again for your help lloyddean.
Update -
Hello lloyddean, I thought that you would like to know how your code performed and there is a slight problem. It flashes the first LED eight times (the number of array elements as far as I can ascertain from the code) but then does not loop through the rest of the LED's . Now I do not wish to make a nuisance of myself (anymore than I already have) and I really only wanted to work this code out as a learning exercise thinking that it can't be that hard, and you know the rest of the story. I adjusted the "const unsigned long tmTENTH_SECOND" from 100 UL TO 500 UL to more clearly see the number of flashes and the interval between groups of flashes, and shot this short clip to show you. I will not be offended if you wish to leave it at that as I'm sure you have other things you would rather be doing than this  8) but if your up for a challenge‚Ķ Thanks again Pedro.
https://www.youtube.com/watch?v=0ybwXILwH5I&feature=plcp

lloyddean

Again sorry, a silly error on the 'ARRAY_ENTRIES' macro.

Changed code above.

Nick Gammon


you can use some C++ syntax in the Arduino environment, but anything that requires the use of C++ libraries will not work.


What are you talking about? The Arduino IDE uses C++. There is nothing about "some" C++ syntax.

Quote
... anything that requires the use of C++ libraries will not work ...


No. Some libraries are implemented. Next you'll be saying that strcpy doesn't work. A library is a library. If it is present you can use it. For example, you can use the STL library if you install it.

Pedro147

Thanks lloyddean it is working like a charm now, and all because of a missing set of square braces and a zero  8)

lloyddean

#54
Nov 01, 2012, 05:16 pm Last Edit: Nov 01, 2012, 06:57 pm by lloyddean Reason: 1
EDIT: Making the 'for' loops 'i' variable 'unsigned' normalize the 'potential' for overflow vs the original

You can shorten the code a bit with a simple change to 'flashLED'.

Code: [Select]

void flashLED(uint8_t pin, int repeat)
{
   for ( unsigned int i = repeat * 2; i--; )
   {
       digitalWrite(pin, !digitalRead(pin));
       delay(tmTENTH_SECOND);
   }
}

Go Up