下你所需,载你所想!
汇集开发技术源码资料

Arduino程序实例(.ino)

:630B :1 :2022-09-16 23:26:43

部分简介

Arduino程序实例(.ino)如果开发者对于本文件有需要的可以参考。
int motor[] = {A2,A4};
int shuibeng = A5;
int scan = A0;//人体检测
int val;//串口缓冲区
float times;//随机秒数
int i=0;
int index=0;
int rate=0;
void setup() {
Serial.begin(9600);
pinMode(A0, INPUT);
pinMode(A2, OUTPUT);
pinMode(A4, OUTPUT );
pinMode(A5, OUTPUT );
}

void loop() {
if (Serial.available() > 0)
{
val = Serial.read();
}
if (val == 0x01)
{
if(digitalRead(scan)==LOW)
{
digitalWrite(shuibeng, HIGH);
delay(1000);
Serial.print(02,HEX);
delay(500);
index=random(0,11);
if(index<5)
{
i=0;
digitalWrite(motor[i], HIGH);
delay(300);
digitalWrite(motor[i], LOW);
}
else if(index>4&&index<9)
{
i=1;
digitalWrite(motor[i], HIGH);
delay(300);
digitalWrite(motor[i], LOW);
}else
{
digitalWrite(motor[0], HIGH);
digitalWrite(motor[1], HIGH);
delay(300);
digitalWrite(motor[0], LOW);
digitalWrite(motor[1], LOW);
}
rate=random(0,3);
if(rate==0)
{
times = random(50, 150);//随机区间值2000-3999;
}
else if(rate==1)
{
times = random(100, 1500);//随机区间值2000-3999;
}
else
{
times = random(200, 1000);//随机区间值2000-3999;
}
delay(times);
}
}
else if (val == 0x00)
{
digitalWrite(shuibeng, LOW);
digitalWrite(motor[0], LOW);
digitalWrite(motor[1], LOW);
}
}

Arduino程序实例(.ino)

热门推荐

相关文章