You are on page 1of 2

/*

AnalogReadSerial

Reads an analog input on pin 0, prints the result to the Serial Monitor.
Graphical representation is available using Serial Plotter (Tools > Serial
Plotter menu).
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V
and ground.

This example code is in the public domain.

https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogReadSerial
*/
int lampe1 = 3;
int lampe2 = 4;

// the setup routine runs once when you press reset:


void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(lampe1,OUTPUT);
pinMode(lampe2,OUTPUT);
}

// the loop routine runs over and over again forever:


void loop() {
// read the input on analog pin 0:
int V1 = analogRead(A0);
int V2 = analogRead(A1);
int P1 = 0.0039*V1+1;

int P2 = 0.0039*V2+1;
// int X = P+1;

// print out the value you read:


// Serial.println(V);

Serial.print("Potentiometre 1: ");
Serial.print(P1);
Serial.print(",");
Serial.print("Potentiometre 2: ");
Serial.println(P2);

delay(1);

if (P1 == 1 && P2 != 1) {
digitalWrite(lampe1, HIGH);
digitalWrite(lampe2, LOW);
}
else if (P2 == 1 && P1 != 1) {
digitalWrite(lampe1, LOW);
digitalWrite(lampe2, HIGH);
}
else if (P1 == 1 && P2 == 1) {
digitalWrite(lampe1, LOW);
digitalWrite(lampe2, LOW);
}
else {
digitalWrite(lampe1, LOW);
digitalWrite(lampe2, LOW);
}

You might also like