There are 4 basic tasks or abilities that the i/o (input/output) pins on devices like Arduinos and ESP32s have.
Digital output: Using digitalWrite we can turn the pins on and off. The pinMode of the pin is set to OUTPUT. We can use this action to switch on/off devices or things external to the microprocessor. Of course, the microprocessor is a tiny little integrated circuit (chip) and is not capable of delivering very much power. There is no way we can connect something that uses more than a few milliamperes of current to a microprocessor. Something like a light bulb would draw too much current and/or need too high a voltage. Later we'll see how we can use transistors or relays to switch on/off higher current loads.
Digital input: Here instead of turning something on or off we are checking to see if something external to the microprocessor is turned on or off. This time the pin is going to "detect" the presence or absence of voltages. The voltages we check for should be high (around the same as the chips' supply voltage) or low (at or near ground or zero volts). The command is digitalRead but this time we need to set some other variable equal to the state of the input. First we need to set the pin to input mode use pinMode(pin,INPUT). Pin refers to one of the tiny leads or "legs" on the chip. Next we use int myVariable = digitalRead(pin). int myVariable creates a new integer variable called myVariable. This new variable is set to 1 or 0 depending on the state of the pin. The ESP32 supply voltage is 3.3V
A note on parameters. A "parameter" is a value that a command needs to be able to function correctly. pinMode needs 2 variables. Therefore it has 2 parameters. Which pin and which state (input or output)?digitalWrite has 2 parameters, which pin and what am I pushing out of this pin?digitalRead has 1 parameter, which pin? Some commands like setup or loop have no parameters - but you still need the brackets ().
Analog input: Here we have the ability to measure how much voltage is present at the pin. Not every pin on a typical microprocessor can do this. The voltage must be between zero and the supply voltage (3.3 volts on ESP32). The pin uses a circuit called an ADC or Analog to Digital Converter that "measures" the voltage and converts it into a value . The value produced depends on how many bits the processor uses. An Arduino uses 10 bits (values from 0 to 1023. The ESP32 uses 12 bits (values from 0 to 4095). 1023 is 11 1111 1111 or 10 ones in binary, 4095 is 1111 1111 1111 or 12 ones in binary. Here's a review of binary.
The analogRead(pin) command is used. Like digitalRead, we need to set some other variable equal to the value this command generates. myVoltage = analogRead(pin). We can use this when we want finer control over a process. For instance, we can use a rotary variable resistor and analogRead to control how fast we spin a motor.
Analog output: Here we would like to output a voltage between 0 and supply. The problem is that is not easy. Instead microprocessors use a PWM output. PWM is Pulse Width Modulation. Essentially we are going to switch the output ON and OFF very rapidly. The "Pulse Width" is the ratio between the amount of time the output is ON to OFF. Check out this video. A pseudo analog output is achieved using this method. The analogWrite(pin,value) command is used. The 2 parameters are which pin and what value? The value is usually 8 bit or 0 to 255 (0000 0000 to 1111 1111 in binary). It turns out that PWM signals are handy for doing other tasks like controlling servo motors.