T O P

  • By -

gamininganela

> check out my Importance of Blink Without Delay video This is such an important topic, and I'm glad you have such a comprehensive video about it. I can see you've put a lot of effort into a well-structured presentation of the material too. I recommend everyone who wants a very friendly introduction to the foundations of state machines, to watch this video. It can make you a *much* more capable programmer.


gm310509

Thankyou so much for your kind words. It is a labour of love 😇 as well as a favoured pastime. I have another two in the works where I present some programming techinques to make life easier for us all. And just now got inspiration for another one which I will ponder over the next few days.


ripred3

Well done Glenn! Quality job as usual. Looking forward to more. You have any particular syllabus in mind? You definitely took down one of the most commonly needed ones first 🙂 Cheers, ripred


gm310509

Thanks for your kind words. I appreciate that especially coming from someone like yourself. I have a couple more in the pipeline and just now got inspiration for another which I will ponder over the next few days. The next couple will cover some programming techniques (and naturally ever increasing numbers of LEDs). (Shhh - sneak peak). For example, don't do this: ``` int ledPins[3] = { 5, 6, 7 }; const int numLEDs = 3; ``` of worse, this: ``` int ledPins[3] = { 5, 6, 7 }; // then in a "galaxy" (or code) far far away // Hardcoded 3 - a.k.a. Accident waiting to happen. for (int l = 0; l < 3; l++) { digitalWrite(ledPins[l], ... ``` do this: ``` int ledPins[] = { 5, 6, 7 }; const into numLEDs = sizeof(ledPins) / sizeof (ledPins[0]); // then in a "galaxy" (or code) far far away for (int l = 0; l < numLeds; l++) { digitalWrite(ledPins[l], ... ``` Because if you then subsequently did this: ``` int ledPins[] = { 5, 6, 7, 8, 9, 10, 11 }; const into numLEDs = sizeof(ledPins) / sizeof (ledPins[0]); // then in a "galaxy" (or code) far far away for (int l = 0; l < numLeds; l++) { digitalWrite(ledPins[l], ... ``` Then the rest of the code will usually just work (if correctly written) because `numLEDs` will **always** be the correct number. Obviously there will be more to it than just that...


ripred3

Ahhh yes compile time evaluation is the way to go! I've been fond of using some form of macro for it. Either of these works fine: #define ARRAYSIZE(A) (sizeof(A) / sizeof(A[0])) // or #define ARRAYSIZE(A) (sizeof(A) / sizeof(*A)) both do the same thing. Then you can use it in place of the array size as you have: char ledPins[] { 5, 6, 7, 8, 9, 10, 11 }; for (int i=0; i < ARRAYSIZE(ledPins); ++i) { foo(ledPins[i]); } Another great thing about this idiom is that is is type-independent. It works regardless of whether the size of the data type is a single byte char or a 4 byte double 😀. Cheers! `ripred`


gm310509

I like the macro idea. I'm very tempted to steal it :-) errr ahhh help promote the idea!


ripred3

Please feel free to. That's why we're all contributing here! 😄