Newcomers PRG-course 1 finish your project faster

So what were the reasons do to avoid functions intentionally?

How about

void setup() {

void loop() {
  digitalWrite(LED_BUILTIN, (millis() / 1000) % 2);

It works. Do the same. Without delay(). :slight_smile:

Wow Boffin,

that's probably the most compact LED-blink ever possible.
Though if somebody wants to start a competition about this please start another thread dedicated to that.

If I remember right modulus needs a bit more executiontime than subtracting. Will have to do some measurings about that in which timescale it might become relevant.

best regards Stefan

Have done a lot of training with people just starting in programming.

Stay away from libraries like a plague.

Libraries hide code from new people and do not promote learning.

Libraries are added further down the training cycle.

Functions on the other hand are well accepted after just one or two days of starting training.

Introduce one concept at a time.

LOL. The whole point of Arduino is to hide code from new people precisely to promote learning.


Promotes cut n paste.

when just starting, need to learn both how to program and a programming language

developing and delivering a program of study in the field of physical computing

Not only is that true, but the modulus approach to blink delay fails at rollover for any delay value that is not an integer power of two.

Well, where the border between learning and copy&paste? And if I do copy and paste does it mean that I'm not learning? I think, it depends on your project.
Talking about my own project, I'm very happy that I have not to read all 555 pages of ATmega328P handbook just to properly configure(!) the MCU before I can start with the function I like to implement - so I learn one layer above setting registers, writing a bootloader on my own, etc.
I also like my oscilloscope without being able to design one. I have a understanding of how it works, but that's it. I just bought it (which is a little like copy and paste).
At the end of the day it is more about someone's attitude. Do I take the project as mine with willingness to learn, taking time, having a certain amount of amibition to do it good? Or do I want just something at lowest efforts possible?
But even I'm willing to learn and to do it good, I don't have to learn all! I can make decisions of what I copy and paste (library, etc), and what I develop on my own. digitalRead() and digitalWrite() are nice functions - I don't have to code them. But, well, to set up 4 PWM channels with desired behaviour plus an interrupt-routine without using timer0 not to abandon library functions linked to that timer, I actually had to read the ATmega328P handbook in its very detail.
Finally, to say learning or not depends on personal view. System-Engineering acts on a different level than detailed design. None of them is better than the other.

1 Like

Will keep that in mind :wink: .

among several languages, my first programing course was focused on Pascal. our mid-term was whatever our professor wanted, but we needed to take the same final as all the other sections which were taught Fortran.

the professor said we should know how to program and just needed a reference for the language. he had a stack of fortran books which we used during our final

Intersting. I didn't see all the implications.

I think I can say it better my point is that when I am learning something new, I like to see it expressed with the smallest subset of the language required. The fewest and least exotic use of control structures, plain variables, no fancy or oddball computer logic or binary tricks &c., unless they are the point.

So this example should be done without functions.


that's OK but a completely different approach to the subset of users I want to adress
which are:
quoting myself:

best regards Stefan

Maybe this thread will be usefull for you Speed of math operations (particularly division) on Arduino

My humble contribution to the "copy & paste" approach for beginners, based on one-liner millis() code. Pros and cons: no delay(), no prevMillis and state variables but integer division and modulus.

const int redLed =   12;
const int greenLed = 11;
const int blueLed =  10;
const unsigned long redTime =   1000;
const unsigned long greenTime = 1500;
const unsigned long blueTime =  4000;

void setPin(int pin, unsigned long msec) {
  int state = (millis() / msec) % 2;
  digitalWrite (pin, state);

void setup() {
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(blueLed, OUTPUT);

void loop() {
  // do something
  setPin(redLed, redTime);
  setPin(greenLed, greenTime);
  setPin(blueLed, blueTime);

I am not a beginner, it is difficult for me to estimate how easy it is to understand this or that code for beginners. Maybe beginners will give their opinion.

not a beginner programmer, but a physical computerist who may be more of an artist, just trying to animation their project and interested in the minimal amount of effort to make an arduino work

There is simply nothing in your argument calling for making anything at anytime more complicated than it has to be.

In this case, for example, you do not need to use functions.

In this case, for example, you do not need to use a function with a call by reference.

Unless you have your "students" nailed to chairs in your classroom, you have no idea what they are bringing to the table; you limit the range and effect of your work by selecting any so-called subset.

The selection process with a public tutorial is one the learners do. If they like the stuff you publish, they may follow you. They may even try to do it in your master order if you are lucky.