#define NUM_PINS_1_TO_7 7
#define NUM_PINS_8_TO_11 4
const int pins_1_to_7[NUM_PINS_1_TO_7] = {4, 0, 2, 15, 13, 12, 14};
const int pins_8_to_11[NUM_PINS_8_TO_11] = {27, 26, 25, 33};
const int freq_pin_1_to_7 = 285714; // Hz
const int freq_pin_8_to_11 = 1000000; // Hz
void setup() {
// Set pin modes
for (int i = 0; i < NUM_PINS_1_TO_7; ++i) {
pinMode(pins_1_to_7[i], OUTPUT);
}
for (int i = 0; i < NUM_PINS_8_TO_11; ++i) {
pinMode(pins_8_to_11[i], OUTPUT);
}
}
void loop() {
// Delay calculations
int delay_pin_1_to_7 = 1000000 / freq_pin_1_to_7; // in microseconds
int delay_pin_8_to_11 = 1000000 / freq_pin_8_to_11; // in microseconds
// Loop through pins 1 to 7
for (int i = 0; i < NUM_PINS_1_TO_7; ++i) {
// Activate current pin
digitalWrite(pins_1_to_7[i], HIGH);
delayMicroseconds(delay_pin_1_to_7); // Delay for 1 cycle
// Deactivate all other pins
for (int j = 0; j < NUM_PINS_1_TO_7; ++j) {
if (j != i) {
digitalWrite(pins_1_to_7[j], LOW);
}
}
// Delay for pin 1 to 7 frequency
delayMicroseconds(delay_pin_1_to_7);
}
// Loop through pins 8 to 11
for (int i = 0; i < NUM_PINS_8_TO_11; ++i) {
// Activate current pin
digitalWrite(pins_8_to_11[i], HIGH);
delayMicroseconds(delay_pin_8_to_11); // Delay for 1 cycle
// Deactivate all other pins
for (int j = 0; j < NUM_PINS_8_TO_11; ++j) {
if (j != i) {
digitalWrite(pins_8_to_11[j], LOW);
}
}
// Delay for pin 8 to 11 frequency
delayMicroseconds(delay_pin_8_to_11);
}
}