EasyManuals Logo

Freenove ESP32 User Manual

Default Icon
159 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #93 background imageLoading...
Page #93 background image
Need support? support@freenove.com
91
Chapter 7 Built-in Led
www.freenove.com
44
45
46
47
}
lastLedUpdateTime = millis();
}
}
Onboard LED initialization function.
10
11
12
void setupBuiltInLed(){
pinMode(LED_BUILT_IN, OUTPUT);
}
The function that controls the on-board LED to turn on or off.
14
15
16
void setBuiltInLed(bool state){
digitalWrite(LED_BUILT_IN, state);
}
Enter the if statement every occasionally. This usage has the same effect as the delay() function, but it will not
cause the code to be pause.
21
if (millis() - lastLedUpdateTime > intervalTime){
Control the LED's on and off states by shifting a variable, sqValue, and taking the least significant bit as the
control signal.
If the current state of the LED is different from the previous state, control the LED to change its current state
and update the previous state to the current state.
24
25
26
27
28
29
ledStatus = ((sqValue >> bitIndex) & 0x01) ? true : false;
if (ledStatus != lastLedStatus){
digitalWrite(LED_BUILT_IN, (uint8_t)ledStatus);
lastLedStatus = ledStatus;
bitDiff++;
}
Introducing a variable called bitIndex to control the shift amount, so as to change the number of shifts
performed on sqValue each time,. If the number of shifts exceeds 9, the next time entering the if condition
will be delayed by 600ms, and sqValue starts shifting from the 0th bit again.
30
31
32
33
34
35
36
bitIndex++;
if (bitIndex >= 10){
intervalTime = 600;
ledRunnigStatus = 1;
bitDiff = 0;
bitIndex = 0;
}
If the previous shift cycle is completed, set the time for entering the if condition to 100ms each time and
proceed to the next shift cycle.
38
39
40
41
case 1: // off
intervalTime = 100;
ledRunnigStatus = 0;
break;

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Freenove ESP32 and is the answer not in the manual?

Freenove ESP32 Specifications

General IconGeneral
BrandFreenove
ModelESP32
CategoryComputer Hardware
LanguageEnglish

Related product manuals