// Define Pins
const int LED = 11; //allows LED to be digitally written
const int Pot = A2;
// Define Global variables
int Potread = 0;
int LEDbright = 0;
void setup() {
// put your setup code here, to run once:
pinMode(LED, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
Potread = analogRead(Pot); // or could have done int Potread = ... and define it as a local variable
LEDbright = map(Potread, 0, 1023, 0, 255); //maps the potentiometer reading to the range of the LED
// or int LEdbright = ...
analogWrite(LED,LEDbright); //writes LED brightness depending on potentiometer setting
}
// using analogue pins as digital pins means that they con wonly be written as high or low.
//They cannot be analoguelly written
// only PWM pins can be analoguelly written