Physical computing sits between hardware and software: reading the world with sensors and acting on it with light, sound and motion.
The loop
- Sense — buttons, potentiometers, light and distance sensors
- Think — read state on a microcontroller
- Act — drive LEDs, motors and speakers
cpp
const int BUTTON = 2;
const int LED = 13;
void setup() {
pinMode(BUTTON, INPUT_PULLUP);
pinMode(LED, OUTPUT);
}
void loop() {
digitalWrite(LED, digitalRead(BUTTON) == LOW);
}Safety
Never exceed a pin's current rating — use a transistor for motors.