const int PotPin=12;
const int LedPin=A0;
const int PotOut=A2;
unsigned int PotVal;
float Ledval;
float BrightPercentage;
void setup() {
// put your setup code here, to run once:
pinMode(PotOut, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(PotPin, HIGH);
PotVal=analogRead(PotOut);
Ledval=(255./1023.)*PotVal;
analogWrite(LedPin,Ledval);
BrightPercentage=(100./255.)*Ledval;
Serial.print("The brightness in percentage is: ");
Serial.println(BrightPercentage);
}