#define red 12
#define blue 10
#define green 11
#define LDR A0
int data;
float V;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(red, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(green, OUTPUT);
Serial.print("move the bar to get each colour");
}
void loop() {
// put your main code here, to run repeatedly:
data=analogRead(LDR);
V = (data/1023.0)*5;
Serial.print("[v]: ");
Serial.print(V);
data=map(data,0,1023,1,4);
if (data==1)
{
digitalWrite(red,HIGH);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
Serial.println(",colour is red");
}
else if(data==2)
{
digitalWrite(green,HIGH);
digitalWrite(red, LOW);
digitalWrite(blue, LOW);
Serial.println(" ,colour is green");
}
else
{
digitalWrite(blue,HIGH);
digitalWrite(green, LOW);
digitalWrite(red, LOW);
Serial.println(",colour is blue");
}
}