硬件平台:PC机一台,ibox卡片电脑一只,arduino扩展板一个,LED灯一个,电位器一个 软件平台:WIN7操作系统,android4.0或android4.4系统 实验目标:通过电位器控制LED灯的亮与灭 打开arduino的IDE开发工具,依次点击文件->示例-> 05.Control->IfStatementConditional,IfStatementConditional的示例程序将会被打开,其源码如下: - // These constants won't change:
- const int analogPin = A0; // pin that the sensor is attached to
- const int ledPin = IO0; // pin that the LED is attached to
- const int threshold = 1000; // an arbitrary threshold level that's in the range of the analog input
-
- void setup() {
- // initialize the LED pin as an output:
- pinMode(ledPin, OUTPUT);
- // initialize serial communications:
- Serial.begin(9600);
- }
-
- void loop() {
- // read the value of the potentiometer:
- int analogValue = analogRead(analogPin);
-
- // if the analog value is high enough, turn on the LED:
- if (analogValue > threshold) {
- digitalWrite(ledPin, HIGH);
- }
- else {
- digitalWrite(ledPin, LOW);
- }
-
- // print the analog value:
- Serial.println(analogValue);
- delay(10); // delay in between reads for stability
- }
复制代码 从程序可以看出,程序期望通过从A0口读取ADC的值,当读取的值大于1000时,点亮LED,小于1000时熄灭LED,LED灯由IO0控制。将LED灯的正级接IO0,负级接GND,将电位器的两端接3.3V和GND,中间接A0,运行程序,钮动电位器,观察LED灯是否受电位器控制。
|