Skip to content

Instantly share code, notes, and snippets.

@samilkorkmaz
Created February 2, 2020 09:07
Show Gist options
  • Save samilkorkmaz/cbeb237c50af6edb06040d413a7baa44 to your computer and use it in GitHub Desktop.
Save samilkorkmaz/cbeb237c50af6edb06040d413a7baa44 to your computer and use it in GitHub Desktop.
Control LED brightness with through digital pin 9 of Arduino with potentiometer
const int ledPin =9; //D9 = PWM pin
void setup(){
Serial.begin(9600);
pinMode(ledPin, OUTPUT) ;
}
void loop(){
int val = analogRead(A0);
Serial.print("val = "); Serial.print(val);
int brightness = map(val, 0, 1023, 0, 255);
Serial.print(", brightness = "); Serial.println(brightness);
analogWrite(ledPin, brightness);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment