#include <Arduino.h>
#include "vector.h" // Include your vector implementation
// Define your functions
void function1() {
Serial.println("Function 1 executed");
delay(1000);
}
void function2() {
Serial.println("Function 2 executed");
delay(1000);
}
void function3() {
Serial.println("Function 3 executed");
delay(1000);
}
void function4() {
Serial.println("Function 4 executed");
delay(1000);
}
void function5() {
Serial.println("Function 5 executed");
delay(1000);
}
// Define a typedef for function pointers
typedef void (*FunctionPointer)();
// Define a vector to hold function pointers
vector<FunctionPointer> functionVector;
// Define current index
int currentIndex = 0;
// Function to execute next function
void next() {
if (currentIndex < functionVector.size() - 1) {
currentIndex++;
functionVector[currentIndex]();
} else {
Serial.println("Already at the last function");
}
}
// Function to execute previous function
void previous() {
if (currentIndex > 0) {
currentIndex--;
functionVector[currentIndex]();
} else {
Serial.println("Already at the first function");
}
}
void setup() {
Serial.begin(115200); // Initialize serial communication
// Populate the function vector
functionVector.push_back(function1);
functionVector.push_back(function2);
functionVector.push_back(function3);
functionVector.push_back(function4);
functionVector.push_back(function5);
}
void loop() {
if(Serial.available()>0){
String data = Serial.readStringUntil('\n');
if(data == "n"){
next();
}
else if(data == "p")
{
previous();
}
}
}