Download presentation
Presentation is loading. Please wait.
Published byHilary Mills Modified over 8 years ago
1
可變電阻控制 LED 實驗
2
材料 杜邦線 可變電阻 LED * 10 Arduino uno
3
程式碼 byte ledPin[]={4,5,6,7,8,9,10,11,12,13};// 为 LED 建立数组 int ledDelay;// 每次变换之间的延时 int direction=1; int currentLED=0; unsigned long changeTime; int potPin=2;// 为变阻器选择输入口 void setup(){ for(int x=0;x<10;x++){ pinMode(ledPin[x],OUTPUT); } changeTime=millis(); } void loop(){ ledDelay=analogRead(potPin); if((millis()-changeTime)>ledDelay){ changeLED(); changeTime=millis(); }
4
程式碼 void changLED(){ for(int x=0;x<10;x++){ digitalWrite(ledPin[x],LOW); } digitalWrite(ledPin[currentLED],HIGH); currentLED+=direction; if(currentLED==9){direction=-1;} if(currentLED==0){direction=1;} }
5
實驗結果
6
資料來源 http://www.robotkoko.com/arduino-interactive-led-chasing-effect/ http://www.icshop.com.tw/images/product_images/original_images/2312_0.jpg http://www.custobots.com/sites/default/files/imagecache/product_full/products/Solar botics-redLED.gif
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.