本帖最后由 凌风清羽 于 2016-6-30 22:10 编辑
使用图形化编程实现,适合青少年学习




- #include <Arduino.h>
- #include <Wire.h>
- #include <Servo.h>
- #include <SoftwareSerial.h>
-
- #include <MeMCore.h>
-
- double angle_rad = PI/180.0;
- double angle_deg = 180.0/PI;
- double jiaodu;
- MeIR ir;
- MBotDCMotor motor(0);
- Servo servo_1_2;
- MePort port_1(1);
-
-
-
- void setup(){
- ir.begin();
- servo_1_2.attach(port_1.pin2());
- jiaodu = 70;
-
- }
-
- void loop(){
-
- if(ir.keyPressed(64)){
- motor.move(1,255);
- }
- if(ir.keyPressed(21)){
- motor.move(1,0);
- }
- if(ir.keyPressed(25)){
- motor.move(1,-255);
- }
- if(ir.keyPressed(7)){
- motor.move(3,180);
- }
- if(ir.keyPressed(9)){
- motor.move(4,180);
- }
- if(ir.keyPressed(68)){
- jiaodu += 5;
- servo_1_2.write(jiaodu);
- if((180) < (jiaodu)){
- jiaodu = 180;
- }
- }
- if(ir.keyPressed(67)){
- jiaodu += -5;
- servo_1_2.write(jiaodu);
- if((jiaodu) < (0)){
- jiaodu = 0;
- }
- }
- ir.loop();
-
-
- }
复制代码
|