Preparing for my exam, gathering functions

Hello everyone!

Next week I have an exam in Microcontrollers, 1st semester bachelor of Automation engineering. We are using the Arduino program when programming. 

The exam is for many of you probably very simple, tho thats not the case for me. The exam is two split, where one part is explaining and calculating different cuircuts, but the other part, the one I find rather difficult, is making a complete program that will be used to control a “real-life” gadget.

Exaples in exams given earlier contained:

Make a program to:

  • A stop watch, with 3 buttons, that can keep track on time and laps

  • A detonator with buttons used to initialize a charge of explosives


I’ve noticed that “time” is a theme that shows up often in these exams, but that is not always the case.

Now for my question.

For most of the programs we make, we re-use functions that we made have made, and found, during out studies.

These are functions that are sort off “stand-alone”, meaning we can use them on a broad amount of programs with little, if any, changes to the original functions.

I’m looking for a place where these sort of functions are shared by a community, so that I might browse, and have them ready to use in my exam. I’ve been searching for some time now, and I have not found a place for such stand-alone functions.

A few examples of the functions we made:

Returns true if the button connected to the pin given by
the parameter pin is pressed. If the button is not pressed, false
is returned.

This function assumes the button to coupled using a pull down resistor.

@param pin the pin that the button is connected to.
@return true if button is pressed, false if button is not pressed.
boolean isButtonPressed(int pin)
boolean buttonPressed = false;
if (digitalRead(pin) == HIGH)
buttonPressed = true;
buttonPressed = false;
return buttonPressed;

Starts the timer and set the timer to expire after the
number of milliseconds given by the parameter duration.

@param duration The number of milliseconds until the timer expires.
void startTimer(unsigned long duration)
nextTimeout = millis() + duration;

Checks if the timer has expired. If the timer has expired,
true is returned. If the timer has not yet expired,
false is returned.

@return true if timer has expired, false if not
boolean timerHasExpired()
boolean hasExpired = false;
if (millis() > nextTimeout)
hasExpired = true;
hasExpired = false;
return hasExpired;

Change the state of the statemachine to the new state
given by the parameter newState

@param newState The new state to set the statemachine to
void changeStateTo(int newState)
// At this point, we now what the current state is (the value
// of the global variable currentState), and we know what the
// next state is going to be, given by the parameter newState.
// By using the printState()-funksjon, we can now print the
// full debug-message:
Serial.print("State changed from “);
Serial.print(” to ");
Serial.println(); // To add a new line feed

// And finally, set the current state to the new state
currentState = newState;

Hi @nr1programmer,

This post was moved to a different board that fits your topic of discussion a bit better. This means you’ll get better engagement on your post, and it keeps our community organized so users can more easily find information.

As you’ll notice, your topic is now here in the Project Development Help and Advice board. No action is needed on your part; you can continue the conversation as normal here.