int led=3;
int sensor_val;
int delaytime=1;
void setup()
{
// put your setup code here, to run once:
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop()
{
// put your main code here, to run repeatedly:
sensor_val = analogRead(0);//0~1023
sensor_val = map(sensor_val, 0, 1023, 0, 255);
Serial.print("sensor_val=");
Serial.println(sensor_val);
analogWrite(led, sensor_val);//0~255
delay(delaytime);
}
沒有留言:
張貼留言