Input & output in the Arduino IDE
Prototyping electronics on a breadboard and writing code
Arduino
Writing on/off: digitalWrite
Blink_LED.ino
HIGH/LOW
Output
Writing a range of values: analogWrite()
Fade_LED.ino
PWM: 0-255
Output
Reading on/off: digitalRead()
digital_switch_LED.ino
You can detect if a pin is HIGH or LOW
For example: in the case of a switch, whether it’s pressed or not
pinMode(INPUT_PULLUP); to use internal pullup resistor
Input
Measuring resistance: analogRead()
LDR_Fade_LED.ino
With a microcontroller you can measure how much resistance a (DIY) sensor (input) gives. The more difficult the current moves through it, the higher the resistance.
You can read this with analogRead(): voltages (between 0-3.3V in our case) are converted to numbers (0-4095).
You can then link these numbers to something else (output) with map().
Input
Measuring capacitance: touchRead()
touch_keyboard_speaker.ino
Detects variations in anything that holds an electrical charge - including you!
Input
Writing a range of values: servo motor angle
LDR_Servo_motor.ino
Library: ESP32Servo.h
References