Analog Input with Arduino (P Comp Lab)


This is the lab using analog inputs. I used a potentiometer to control the brightness of the LED.

Here’s the code:
const int ledPin = 9; // pin that the LED is attached to
int analogValue = 0; // value read from the pot
int brightness = 0; // PWM pin that the LED is on.

void setup(){
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}

void loop(){
//read analog value
analogValue = analogRead(A0);
brightness = analogValue / 4;
analogWrite(ledPin, brightness);
Serial.print(analogValue + "/n");
}

Proudly powered by WordPress
Theme: Esquire by Matthew Buchanan.