1
2const int sensorPin = A0;
3const int ledPin = 3;
4const int potentiometerPin = A1;
5
6float potentiometerVal;
7float sensorVal;
8float light = 0;
9float mapping;
10
11void setup(){
12
13 Serial.begin(9600);
14
15 pinMode(ledPin,OUTPUT);
16}
17
18void loop(){
19 sensorVal = analogRead(sensorPin);
20 potentiometerVal = analogRead(potentiometerPin);
21
22
23 potentiometerVal = map(potentiometerVal, 0, 1023, 0, 255);
24 sensorVal = map(sensorVal,0,1023, 255, 0);
25 mapping = potentiometerVal;
26 light = map (sensorVal, 0, 255, sensorVal - potentiometerVal , 255);
27
28 if (light <= 0)
29 light=0;
30
31 Serial.print("Brightness: ");
32 Serial.println(sensorVal);
33 Serial.print("Mapping: ");
34 Serial.println(potentiometerVal);
35 analogWrite(ledPin,light);
36 Serial.print("Light: ");
37 Serial.println(light);
38 delay(15);
39}