/*
This sketch and the following series is an introduction for beginners to the use of structs and
finally classes based on an example using LEDs.
2023-04-13
ec2021
Content
1. Without Struct I
https://wokwi.com/projects/361903925541445633
Basic solution to switch a LED on and off in given time periods
2. Without Struct II
https://wokwi.com/projects/361904006150737921
Brute Force method to control three LEDs by copying variables and functions three times
as often done by beginners
3. Without Struct III
https://wokwi.com/projects/361904503533363201
Solution to control three LEDs using one dimensional arrays for the variables
Much easier to maintain and add further LEDs.
4. With Struct I
https://wokwi.com/projects/361905006314083329
Solution to control three LEDs with a struct for the LED specific variables and a function to switch
the LEDs that uses the address operator & to handle the struct and not a copy of its data. There is
a separate struct defined per LED.
5. With Struct II
https://wokwi.com/projects/361905620550035457
The same solution as in 4. but this sketch defines an array of structs. This way it combines structs
with the advantage of arrays as in 3.
6. With Struct III
https://wokwi.com/projects/361905909896214529
This sketch is based on solution 4. but the struct includes now functions to initialize data and
pins as well as the function to switch the LED on/off. The variables inside the struct are declared
as "private" so that they can only be accessed and changed via the public functions.
7. With Class I
https://wokwi.com/projects/361906535848964097
This sketch is identical to solution 6. except that the definition of "struct" has now been named
"class". It shows that both are almost the same in C++. Just that every entry in a struct is public
if not declared as private while in a class every entry is private if not explicitly declared as
public.
8. With Class II
https://wokwi.com/projects/361906656826329089
This sketch shows how to declare and use the constructor of a class to set variables and to perform
required initialisation processes (like pinMode()).
9. With Class III
https://wokwi.com/projects/361908581431120897
This sketch is identical to 8. but the class declaration has been moved to a separate file that is
included in the main file by the #include instruction.
last modification 2023-04-13 22:35 ec2021
*/
#include "ledType.h"
ledType greenLED( 13, 1000, 500);
ledType yellowLED(12, 500, 500);
ledType redLED( 14, 500, 1000);
void setup() {
Serial.begin(115200);
Serial.println("Start ");
greenLED.begin();
yellowLED.begin();
redLED.begin();
}
void loop() {
greenLED.switchLED();
yellowLED.switchLED();
redLED.switchLED();
}
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
led1:A
led1:C
r1:1
r1:2
led2:A
led2:C
led3:A
led3:C
r2:1
r2:2
r3:1
r3:2