unsigned long time1;
int led_pin[]={2,3,4,5,6,7,8,9,10,11};
int analog_pin=0;
int num_value;
int j;
void setup()
{
for(int i=0;i<10;i++)
{
Serial.begin(9600);
pinMode(led_pin[i],OUTPUT);
}
}
void loop()
{
num_value=analogRead(analog_pin);
num_value=map(num_value,0,1023,0,10);
if(millis()-time1>2000)
{
time1=millis();
Serial.println(num_value);
}
for(j=0;j<=num_value;j++)
{
digitalWrite(led_pin[j],HIGH);
}
for(j=num_value+1;j<10;j++)
{
digitalWrite(led_pin[j],LOW);
}
}
沒有留言:
張貼留言