arduino 第一題
int led=9;
int y=0;
int q=1;
void setup(){
Serial.begin(9600);
pinMode(led,OUTPUT);
}
void loop(){
int readvalue = analogRead(A0);
float x = readvalue * (255.0/1023.0);
int z=x;
if(z==0){
digitalWrite(led,LOW);
}
else if(z>0 && z<255){
y = y + q;
if(y==0 || y==255){
q = -q;
}
analogWrite(led,y);
delay(5);
}
else{
digitalWrite(led,HIGH);
delay(500);
digitalWrite(led,LOW);
delay(500);
}
}