#define RED 10
#define GREEN 11
#define BLUE 12
#define meter A0
int data;
float v;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(RED, OUTPUT);
pinMode(GREEN,OUTPUT);
pinMode(BLUE,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
data = analogRead(meter);
v = (data/1023.0) * 5;
Serial.print("vin =");
Serial.print(v);
Serial.print("[v]");
Serial.print(", data =");
Serial.print(data);
Serial.print(", =");
Serial.println(data,BIN);
data=map(data,0,1023,1,4);
if(data==1)
{
digitalWrite(GREEN, HIGH);
digitalWrite(BLUE, LOW);
digitalWrite(RED, LOW);
}
else if(data==2)
{
digitalWrite(BLUE, HIGH);
digitalWrite(GREEN, LOW);
digitalWrite(RED, LOW);
}
else
{
digitalWrite(RED, HIGH);
digitalWrite(BLUE, LOW);
digitalWrite(GREEN, LOW);
}
}