/*
==== Task 3 - Function With a Return Value ====
Author: Roberto Palozzo
===============================================
*/
const int ledPin = 13; // Pin connected to the LED
// This function turns the LED on or off
// and returns its new state
bool controlLED(bool turnOn) {
digitalWrite(ledPin, turnOn); // set LED to the given state
return turnOn; // return the state that was set
}
void setup() {
Serial.begin(115200); // start serial communication (for debugging)
pinMode(ledPin, OUTPUT); // set LED pin as output
}
void loop() {
bool ledState = controlLED(true); // Turn the LED ON
Serial.print("LED state: ");
Serial.println(ledState); // Prints 1 (ON)
delay(1000); // wait 1 second
ledState = controlLED(false); // Turn the LED OFF
Serial.print("LED state: ");
Serial.println(ledState); // Prints 0 (OFF)
delay(1000); // wait 1 second
}