Use Retation Sensor to control the brightness of LED lights

来源:互联网 发布:eml文件 mac 编辑:程序博客网 时间:2024/06/05 03:41

This is a very easy and small project.

The most important point is the map function.

int switchValue;int valueToOut;int ledPin = 4;int switchPin = A0;void setup(){  pinMode(ledPin,OUTPUT);  Serial.begin(9600);}void loop(){  switchValue = analogRead(switchPin);  //the range of switch is 1-1023  //use the function to map    valueToOut = map(switchValue,0,1023,1,254);  analogWrite(ledPin,valueToOut);}

We can use the function to show the status of some sensors.

原创粉丝点击