我们实训学习制作的资料,分享给大家看看
- void go()
- {
-
- digitalWrite(5,HIGH);
- digitalWrite(6,LOW);
- digitalWrite(9,HIGH);
- digitalWrite(10,LOW);
- }
- void left()
- {
- digitalWrite(5,LOW);
- digitalWrite(6,LOW);
- digitalWrite(9,HIGH);
- digitalWrite(10,LOW);
- }
- void right()
- {
- digitalWrite(5,HIGH);
- digitalWrite(6,LOW);
- digitalWrite(9,LOW);
- digitalWrite(10,LOW);
- }
- void back()
- {
- digitalWrite(5,LOW);
- digitalWrite(6,HIGH);
- digitalWrite(9,LOW);
- digitalWrite(10,HIGH);
- }
- void add()
- {
- int i;
- for(i=0;i<255;i+=5)
- {
- analogWrite(5,i);
- analogWrite(9,i);
- delay(100); }
- digitalWrite(6,LOW);
- digitalWrite(10,LOW);
- }
- void ting()
- {
- digitalWrite(5,LOW);
- digitalWrite(6,LOW);
- digitalWrite(9,LOW);
- digitalWrite(10,LOW);
- }
- void voice()
- {
- int i;
- for(i=0;i<100;i++)
- {
- if(i%2==0)
- {
- digitalWrite(7,HIGH);
- delay(500);
- }
- else
- {
- digitalWrite(7,LOW);
- delay(500);
- int x=Serial.read();
- if(x > 0)
- {
- digitalWrite(7,HIGH);
- break;
- }
- }
- }
- }
-
- void setup() {
- // put your setup code here, to run once:
- pinMode (5,OUTPUT);
- pinMode(6,OUTPUT);
- pinMode(9,OUTPUT);
- pinMode(10,OUTPUT);
- pinMode(7,OUTPUT);
- pinMode(13,OUTPUT);
- pinMode(12,OUTPUT);
- pinMode(11,OUTPUT);
- digitalWrite(7,HIGH);
- Serial.begin(9600);
- Serial.println("serial is ok");
- }
- void loop() {
- // put your main code here, to run repeatedly:
- char ch;
- ch=Serial.read();
- Serial.println(ch);
- if(ch=='w')
- {go();}
- else if(ch=='a')
- {left();
- digitalWrite(12,HIGH);}
- else if(ch=='d')
- {right();
- digitalWrite(11,HIGH);}
- else if(ch=='s')
- {back();
- voice();
- digitalWrite(13,HIGH);}
- else if(ch=='t')
- {ting();}
- else if(ch=='q')
- {add();}
- }
复制代码
全部资料51hei下载地址:
代码资料.zip
(256.42 KB, 下载次数: 33)
|