2018-1-3 15:37:50 [显示全部楼层]
7828浏览
查看: 7828|回复: 5

用Boson&Arduino实现跳一跳外挂装置

[复制链接]

最近微信推出的小游戏“跳一跳”
刷爆了朋友圈

用Boson&Arduino实现跳一跳外挂装置图4

如何才能刷到2999分?
光靠手指是不行的,还是要外援!
接下来我们来教大家用Boson模块+Arduino主控板制作简单的外挂装置~

!用玩游戏的方式学编程!

先上效果图

用Boson&Arduino实现跳一跳外挂装置图1




材料清单:

用Boson&Arduino实现跳一跳外挂装置图5

尺子,按钮模块,角度传感器模块,舵机,导电胶布,棉签,Arduino主控板+扩展板,导电线

硬件制作:

1. 将角度传感器连到A0,黄色按钮模块连到数字2号口,舵机连接到数字9号口(PMW)
2. 将棉签裹上一层导电布,然后将导电布一段接上5V导电线,(可直接连接至扩展板),即可模拟手指触摸屏幕~
用Boson&Arduino实现跳一跳外挂装置图7


用Boson&Arduino实现跳一跳外挂装置图6


代码上传:

打开ArduinoIDE ,上传代码

[mw_shl_code=c,true]#include <Servo.h>
Servo myservo;
int pos = 0;
float val = 0.00;
const int buttonPin = 2;
const int ledPin = 13;
//Variables will change:
int buttonPushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;
void play(){
  int t = val*300;
  myservo.write(0);
  delay(500);
  myservo.write(60);
  delay(t);
  myservo.write(0);
  delay(500);
}
void setup() {
  // put your setup code here, to run once:
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
  myservo.attach(9);
  myservo.write(0);
  delay(500);
}

void loop() {
  // put your main code here, to run repeatedly:
  val = analogRead(A0);
  val = (val+1)*0.02;
  Serial.println(val);
  buttonState = digitalRead(buttonPin);
  //compare the buttonState to its previous state
  if (buttonState != lastButtonState){
    //if the state has changed, increment the counter
    if (buttonState == HIGH){
      buttonPushCounter++;
      play();
      Serial.println("on");
      Serial.print("number of button pushes: ");
      Serial.println(buttonPushCounter);
    }else{
      //if the current state is LOW then the button
      //wend from on to off:
      Serial.println("off");
    }
    //dalay a little bit to avoid bouncing
    delay(50);
  }
  lastButtonState = buttonState;
}[/mw_shl_code]

打开Arduino IDE 的工具,点击串口监视器,
用Boson&Arduino实现跳一跳外挂装置图2

开始游戏:
1.先用尺子测量距离屏幕上盒子之间的距离;
2.通过角度模拟器的输入实际测量的盒子之间的距离

用Boson&Arduino实现跳一跳外挂装置图3

3.按下黄色按钮,舵机就会按对应的时间按压屏幕,然后就尽情地跳跳跳吧~



Boson 3.gif

JustDoIt  学徒

发表于 2018-1-3 19:20:33

666
回复

使用道具 举报

xiaohe9527  高级技师

发表于 2018-1-4 12:04:09

那么不同的距离怎么办呢?每次都要测量吗?
回复

使用道具 举报

1002victor  初级技师

发表于 2018-1-4 13:28:07

太麻烦,不如手快;P
回复

使用道具 举报

zbl  中级技匠
 楼主|

发表于 2018-1-4 13:41:05

xiaohe9527 发表于 2018-1-4 12:04
那么不同的距离怎么办呢?每次都要测量吗?

这个初级版本是需要手动测量的~可以做个图像识别的高级版本!
回复

使用道具 举报

面包板  初级技匠

发表于 2018-1-5 15:10:22

没太明白程序里距离和需要按屏幕的时间的线性关系?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail