Created
February 2, 2020 09:07
-
-
Save samilkorkmaz/cbeb237c50af6edb06040d413a7baa44 to your computer and use it in GitHub Desktop.
Control LED brightness with through digital pin 9 of Arduino with potentiometer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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