@paulpaulson: in most cases you are contributing good postings.
in this posting your wish "enjoy C++-coding" is very unlike to become true
- not working at all
- too complex, too less comments
- too short variable names
I copied and pasted your code into the WOKWI-simulator. It compiles and blinks the onboard-LED but the other IO-pins with LEDs connected do not blink
Here is a modified version of your code that has more self-explaining names and comments that are still pretty short but do some basic explaining.
even such small things like using a variable-name "Output_Pins" instead of "Output_" guides a newbee to understand what the variable is for.
// BLOCK COMMENT
// ATTENTION: This Sketch contains elements of C++.
// https://www.learncpp.com/cpp-tutorial/
// https://forum.arduino.cc/t/newbie-just-tsrating-need-help-with-a-sketch/908165/31
#define ProjectName "Newbie just tsrating, need help with a sketch"
// CONSTANT DEFINITION
// you may need to change these constants to your hardware and needs.
constexpr byte Output_Pins[] {2, 3, 4, 5, 6}; // portPin o---|220|---|LED|---GND
constexpr unsigned long Interval {1000};
// VARIABLE DECLARATION AND DEFINTION
struct BULB_on_Off_PATTERN {
bool bulbs[sizeof(Output_Pins) / sizeof(Output_Pins[0])];
} on_off_pattern [] = {
{true, false, false, false, false},
{false, true, false, false, false},
{false, false, true, false, false},
{false, false, false, true, false},
{false, false, false, false, true},
{false, false, false, true, false},
{false, false, true, false, false},
{false, true, false, false, false},
};
unsigned long currentTime;
struct TIMER {
unsigned long duration;
unsigned long timeStamp;
};
// create a structured variable with name "blink_Timer" of type TIMER
TIMER blink_Timer{Interval, 0};
// FUNCTIONS
bool checkTimer(TIMER & p_time) { // generic time handler using TIME struct
// if more time than given in p_time.duration is over
if (currentTime - p_time.timeStamp >= p_time.duration) {
p_time.timeStamp = currentTime; // update timestamp
return true; // duration over return value "true"
}
else // duration not over return value "false"
return false;
}
void setup() {
Serial.begin(9600);
Serial.println(F("."));
Serial.print(F("File : ")), Serial.println(__FILE__);
Serial.print(F("Date : ")), Serial.println(__DATE__);
Serial.print(F("Project: ")), Serial.println(ProjectName);
pinMode (LED_BUILTIN, OUTPUT);
// run through all elements of struct "Output_Pins" setting them as OUTPUT
// Output_Pins is an array that contains the IO-pin-numbers
// for (auto ....
// iterates through all elements of the array
// and sets variable Pin_Nr to the values defined in the array Output_Pins
// execute command "pinMode(Pin_Nr, OUTPUT)" for each element
for (auto Pin_Nr : Output_Pins) pinMode(Pin_Nr, OUTPUT);
}
void loop () {
currentTime = millis();
// blink the onboard-LED with 500 milliseconds
digitalWrite(LED_BUILTIN, (currentTime / 500) % 2);
// check if blink_Timer has expired
if (checkTimer(blink_Timer)) {
int element = 0;
static int number = 0;
// run through all elements of struct "Output_Pins"
// and use the defined pattern to switch On/off each IO-pin
// each time the timer expires one row of the defined "on_off_pattern"
// is used to switch on/off all five IO-pins
// by executing the command "digitalWrite(Pin_Nr,on_off_pattern[number].bulbs[element++]);"
for (auto Pin_Nr : Output_Pins) digitalWrite(Pin_Nr,on_off_pattern[number].bulbs[element++]);
// set number to a value that is the begin of the next row
number++;
number = number % (sizeof(on_off_pattern) / sizeof(on_off_pattern[0]));
}
}
I'm a somehow advanced hobbyprogrammer. maybe even some comments of me are wrong.
I estimate it would take me 2 to 3 hours to analyse why the LEDs are not blinking. Something like this is not newbee-friendly.
If you managed to learn c++ with such examples I pull my hat because you showed
exceptional perseverance and a high tolerance for frustration
best regards Stefan