ITP blog ยท physical-computing

Week 3 - Lab 3 - Analog In with an Arduino

26 September 2018

Lab 3 documentation

A simple circuit which reads a potentiometer (analog input) to control the brightness of an LED.

analog-in

Code

const int ledPin = 9;
int analogValue = 0;
int brightness = 0;

void setup() {
    pinMode(ledPin, OUTPUT);
}

void loop() {
    analogValue = analogRead(A0);
    brightness = analogValue / 4;
    analogWrite(ledPin, brightness);
}