bio photo

Email

####Analog with Arduino


const int ledPin = 9; // pin that the LED is attached to
int analogValue = 0;  // value read from the potentiometer
int brightness = 0;  // PWM pin that the LED is on. 

void setup() {
  // put your setup code here, to run once:
//initialize serial communications at 9600bps:
Serial.begin(9600);
//declare the led pin as an output:
pinMode(ledPin, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
analogValue = analogRead(A0); //reading the potentiometer value
brightness = analogValue /4; //dividing by 4 to fit in a byte
analogWrite(ledPin, brightness); //PWM the LED with the brightness
Serial.println(brightness);  //print the brightness value

}