Instead of bool direction true and false, byte deltaT could be 50 or -50 and then add deltaT to timer and check limits to reverse. That removes one if() and IIRC Arduino bool is 16 bits, hope I'm wrong!
A lot of interesting things about blinking an LED have been discussed here, if you'd like to have a look.
Based on the idea discussed there, you could also do something like this. Since you're just learning programming, you might find the following code interesting to look at.
Of course, you don't have to do it this way ā it's just an idea.
#include <math.h>
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
// Time since startup in seconds
double t = millis() / 1000.0;
// One complete slow -> fast -> slow cycle takes 10 seconds
const double cycle = 10.0;
// Minimum and maximum blink frequency
const double fMin = 0.5;
const double fMax = 1.0 / 0.3;
double fMean = (fMin + fMax) / 2.0;
double fAmp = (fMax - fMin) / 2.0;
double omega = 2.0 * PI / cycle;
// Calculate a continuous phase from the changing frequency
double phase = fMean * t - (fAmp / omega) * sin(omega * t);
// Switch the LED state every half period
digitalWrite(LED_BUILTIN, ((unsigned long)(phase * 2.0)) & 1);
}
This makes the LED blink continuously faster and then slower again, without using delay(), previousMillis, a direction variable, or a stored LED state.
The interesting part is that the LED state is calculated directly from millis().
You don't need to understand all the math behind it yet. I just thought it might be interesting to see what can be derived directly from millis().