const int led = 3;
const int button = 13;
const int dim = A0;
void setup() {
// put your setup code here, to run once:
pinMode(dim, INPUT);
pinMode(button,INPUT);
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(led,digitalRead(button)); // turn on/ turn off
//----------PWM---------------------//
int dim_value= analogRead(dim);
int brightness = map(dim_value,0, 1023, 0,255); // map takes 5 things , 1- value 2- old range 3- new range because analogue is 1024 value but pwm is 255 as max
if (digitalRead(button)== HIGH)
{
digitalWrite(led, brightness);
Serial.println(brightness);
}
}