#define AREA_1_RED_PIN 17
#define AREA_1_GREEN_PIN 16
#define AREA_1_BLUE_PIN 4
void setupPins(){
pinMode(AREA_1_RED_PIN, OUTPUT);
pinMode(AREA_1_GREEN_PIN, OUTPUT);
pinMode(AREA_1_BLUE_PIN, OUTPUT);
analogWrite(AREA_1_RED_PIN, 0);
analogWrite(AREA_1_GREEN_PIN, 0);
analogWrite(AREA_1_BLUE_PIN, 0);
}
void setup() {
// put your setup code here, to run once:
setupPins();
Serial.begin(115200);
Serial.println("Hello, ESP32!");
}
float easeInOut(float i){
return i * i * (3.0f - 2.0f * i);
}
void applyCurve(int durationMillis){
int i, r, g, b = 0;
float fps = 60.0;
int startMillis = millis();
int endMillis = startMillis + durationMillis;
int current = millis();
int lowerBound = 0;
int upperBound = 255;
int delta = upperBound - lowerBound;
char* buffer[100];
while(current < endMillis){
float curved = easeInOut( (current - lowerBound) / durationMillis * 1.0);
int value = floor(lowerBound + delta * curved);
Serial.print("curved: ");
Serial.print(curved);
Serial.print(" value: ");
Serial.print(value);
Serial.println("");
analogWrite(AREA_1_RED_PIN, value);
analogWrite(AREA_1_GREEN_PIN, value);
analogWrite(AREA_1_BLUE_PIN, value);
delay(floor(durationMillis / fps));
current = millis();
}
}
void loop() {
// put your main code here, to run repeatedly:
applyCurve(5000);
delay(3000); // this speeds up the simulation
}