const int potPin1 = A0;
const int potPin2 = A1;
const int potPin3 = A2;
const int potPin4 = A3;
const int ledPin1 = 9;
const int ledPin2 = 10;
int potValue1 = 0;
int potValue2 = 0;
int potValue3 = 0;
int potValue4 = 0;
int ledBrightness1 = 0;
int blinkInterval1 = 0;
int ledBrightness2 = 0;
int blinkInterval2 = 0;
unsigned long previousMillis1 = 0;
unsigned long previousMillis2 = 0;
bool ledState1 = LOW;
bool ledState2 = LOW;
void setup() {
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
Serial.begin(9600);
}
void loop() {
// Read potentiometer values
potValue1 = analogRead(potPin1);
potValue2 = analogRead(potPin2);
potValue3 = analogRead(potPin3);
potValue4 = analogRead(potPin4);
ledBrightness1 = exponentialMap(potValue2, 0, 1023, 0, 255);
blinkInterval1 = map(potValue1, 0, 1023, 100, 2000);
ledBrightness2 = exponentialMap(potValue4, 0, 1023, 0, 255);
blinkInterval2 = map(potValue3, 0, 1023, 100, 2000);
unsigned long currentMillis = millis();
// Update LED 1
if (currentMillis - previousMillis1 >= blinkInterval1) {
previousMillis1 = currentMillis;
// Toggle the LED 1 state
ledState1 = !ledState1;
if (ledState1) {
analogWrite(ledPin1, ledBrightness1); // Set the LED 1 brightness
} else {
analogWrite(ledPin1, 0); // Turn off LED 1
}
}
// Update LED 2
if (currentMillis - previousMillis2 >= blinkInterval2) {
previousMillis2 = currentMillis; // Save the last time LED 2 was updated
// Toggle the LED 2 state
ledState2 = !ledState2;
if (ledState2) {
analogWrite(ledPin2, ledBrightness2); // Set the LED 2 brightness
} else {
analogWrite(ledPin2, 0); // Turn off LED 2
}
}
// Print values for debugging
Serial.print("Pot1 Value (Interval LED 1): ");
Serial.print(potValue1);
Serial.print("\tBlink Interval LED 1: ");
Serial.print(blinkInterval1);
Serial.print("\tPot2 Value (Brightness LED 1): ");
Serial.print(potValue2);
Serial.print("\tBrightness LED 1: ");
Serial.println(ledBrightness1);
Serial.print("Pot3 Value (Interval LED 2): ");
Serial.print(potValue3);
Serial.print("\tBlink Interval LED 2: ");
Serial.print(blinkInterval2);
Serial.print("\tPot4 Value (Brightness LED 2): ");
Serial.print(potValue4);
Serial.print("\tBrightness LED 2: ");
Serial.println(ledBrightness2);
}
// Exponential mapping function for finer control over LED brightness
int exponentialMap(int val, int inMin, int inMax, int outMin, int outMax) {
float normalized = (float)(val - inMin) / (inMax - inMin);
float exponent = pow(normalized, 3); // Adjust the exponent value (e.g., 2, 3, 4) to change the curve
return (int)(exponent * (outMax - outMin) + outMin);
}