int Volt=5;
int analog_pin=A0;
int value;
float volt_value;
int led=2;
void setup()
{
pinMode(led,OUTPUT);
Serial.begin(9600);
}
void loop()
{
value=analogRead(analog_pin);
volt_value=(float)(Volt*value)/1024;
if(volt_value>2.5)
{
digitalWrite(led,HIGH);
Serial.print("led亮");
}
else
{
digitalWrite(led,LOW);
Serial.print("led不亮");
}
Serial.print("電壓為");
Serial.print(volt_value);
Serial.println("伏特");
delay(1000);
}
沒有留言:
張貼留言