#include <Arduino.h>
#include <stdarg.h>
class BooleanArray {
private:
bool* boolArray;
size_t count;
public:
// Constructor that takes a variable number of boolean arguments
BooleanArray(size_t count, ...) {
this->count = count;
boolArray = new bool[count];
va_list args;
va_start(args, count);
for (size_t i = 0; i < count; i++) {
boolArray[i] = va_arg(args, int); // va_arg(args, bool) is not valid, use int instead
}
va_end(args);
}
// Destructor to free the allocated memory
~BooleanArray() {
delete[] boolArray;
}
// Function to get the boolean value at a specific index
bool get(size_t index) const {
if (index < count) {
return boolArray[index];
}
return false; // or handle the error as needed
}
// Function to get the size of the array
size_t size() const {
return count;
}
};
void setup() {
Serial.begin(115200);
// Create an instance of the class with a variable number of boolean arguments
BooleanArray bools(8, true, false, true, false, true, false);
// Print the values to the Serial Monitor
for (size_t i = 0; i < bools.size(); i++) {
Serial.print("Value at index ");
Serial.print(i);
Serial.print(": ");
Serial.println(bools.get(i));
}
}
void loop() {
// Your main code here
}