纸片小鱼
标签:arduino
linmy 发布于 2017-05-12 15:26
材料是简单的舵机+纸盒
将面包板和接线隐藏在小鱼的后方,通过舵机让小鱼做出摇头摇尾以及游动的动作。
通过遥控控制小鱼的各种动作,除了普通的直接控制,还增加了一个随机操作小鱼的动作。
优酷视频地址:http://v.youku.com/v_show/id_XMjc2MDA1MTk2OA==.html?spm=a2h3j.8428770.3416059.1
Step 1: 所需材料
纸板*1
舵机*2dfrobot基础面包板*1
LED*1
红外遥控组件*1
电池若干(或者直接接线)
Step 2: 制作过程
外壳制作
将小鱼的外壳在纸板上描出剪下,连接小鱼身体的各个部分,将舵机和LED线接好再与身体连接在一起,最后将整个板固定在小鱼身上。
Step 3: 内部代码
#include <Servo.h>#include <IRremote.h>long ir_item;int ran;int i;int k;int t;Servo servo_3;Servo servo_5;IRrecv irrecv_4(4);decode_results results_4;
void 尾部() { digitalWrite(8,HIGH); for (int b = 1; b <= 5; b = b + (1)) { for (int i = 1; i <= 10; i = i + (1)) { k = k + 5; servo_5.write(k); delay(30); } for (int i = 1; i <= 10; i = i + (1)) { k = k - 5; servo_5.write(k); delay(30); } } digitalWrite(8,LOW);}
void 头部() { digitalWrite(8,HIGH); for (int b = 1; b <= 5; b = b + (1)) { for (int i = 1; i <= 10; i = i + (1)) { k = k + 5; servo_3.write(k); delay(30); } for (int i = 1; i <= 10; i = i + (1)) { k = k - 5; servo_3.write(k); delay(30); } } digitalWrite(8,LOW);}
void 全身() { digitalWrite(8,HIGH); for (int b = 1; b <= 5; b = b + (1)) { for (int i = 1; i <= 5; i = i + (1)) { t = t + 5; servo_3.write(t); delay(30); servo_5.write(t); delay(30); } for (int i = 1; i <= 5; i = i + (1)) { t = t - 5; servo_3.write(t); delay(30); servo_5.write(t); delay(30); } } digitalWrite(8,LOW);}
void setup(){ Serial.begin(9600); servo_3.attach(3); servo_5.attach(5); irrecv_4.enableIRIn(); pinMode(8, OUTPUT); ran = 0; i = 0; k = 0; t = 0;}
void loop(){
if (irrecv_4.decode(&results_4))
{ ir_item=results_4.value; String type="UNKNOWN"; String typelist[14]={"UNKNOWN", "NEC", "SONY", "RC5", "RC6", "DISH", "SHARP", "PANASONIC", "JVC", "SANYO", "MITSUBISHI", "SAMSUNG", "LG", "WHYNTER"};
if(results_4.decode_type>=1&&results_4.decode_type<=13){ type=typelist[results_4.decode_type]; } Serial.print("IR TYPE:"+type+" "); Serial.println(ir_item,HEX);
if (ir_item == 0xFD08F7) { 头部(); }
else if (ir_item == 0xFD48B7) { 尾部(); }
else if (ir_item == 0xFD8877) { 全身(); }
else if (ir_item == 0xFDA857) { ran = random(1, 100); if (ran <= 25) { 头部(); } else if (ran >= 75) { 尾部(); } else { 全身(); } } irrecv_4.resume(); } else { servo_3.write(25); delay(20); servo_5.write(25); delay(20); }}
Step 4: 最终组合
因为是第一次制作,而且没有焊接的设备,所以基本的连接都是通过透明胶和502连接的,最后选择用纸片将表面覆盖
登录以发表评论