一:digitalRead 初始化数字端口读取0-13;
int Led = 13;
digitalRead (Led,OUTPUT);
二:analogRead 读取传感器的模拟值并赋给val,读取的针脚未A0-A5
int val;
val = analogRead(0)
红外感应代码
int Sensor = 0;
int temp = 1;
void setup() {
Serial.begin(9600);
pinMode(Sensor,INPUT);
}
void loop(){
page();
}
void page() {
int SensorInt = digitalRead(Sensor);
if( SensorInt != temp)
{
temp = SensorInt;
if(temp == 0) Serial.print("手伸进来了");
else Serial.print("手伸出去了");
Serial.println(SensorInt);
}
delay(50);
}
压力感应代码
int fsrPin = 0;
int fsrReading;
int fsrReadingTemp = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
fsrReading = analogRead(fsrPin);
if (fsrReadingTemp != fsrReading) {
fsrReadingTemp = fsrReading;
Serial.print("Analog reading = ");
Serial.println(fsrReading);
}
delay(100);
}
网友评论