求Joystick Shield激光清洗机的原理图图

【图片】【arduino】关于joystick shield开发游戏_arduino吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:56,448贴子:
【arduino】关于joystick shield开发游戏收藏
如题,用到Uno板,joystick shield,5110。想共同探讨一下游戏开发思路,硬件是接好并测试成功的了
先发一下测试程序和接线
首先是joystick shield。接线不用说了吧,直接插上就行,和我这种不一样的程序可能要稍微改动一下,这种大概是20元(还是很贵啊)。好了,上程序。
JoystickArduinoBasicExample.pde
A basic sketch to demonstrate reading values from the joystick shield
How to use:
* Connect joystick shield to your Arduino
* Upload this sketch to your Arduino
* Open the Arduino IDE Serial Monitor (set to 9600 baud)
* Waggle joystick, push buttons
* SparkFun Joystick Shield
Written for SparkFun Arduino Inventor's Kit CIRC-JOY
Based on original example by Ryan Owens */// Store the Arduino pin associated with each inputconst byte PIN_BUTTON_LEFT = 2; // Select button is triggered when joystick is pressedconst byte PIN_BUTTON_RIGHT = 3;const byte PIN_BUTTON_UP = 4;const byte PIN_BUTTON_DOWN = 5;const byte PIN_BUTTON_SELECT = 8;const byte PIN_ANALOG_X = 0;const byte PIN_ANALOG_Y = 1;void setup() {
Serial.begin(9600);
// Specify each pin connected to a pushbutton as an input.
// Also enable the Arduino's internal &pull-up& resistors
// for each pushbutton we want to read--this means the shield
// doesn't need to have resistors on it.
// Note that when a pull-up resistor is used on a pin the
// meaning of the values read are reversed compared to their
// usual meanings:
* HIGH = the button is not pressed
* LOW = the button is pressed
pinMode(PIN_BUTTON_RIGHT, INPUT);
digitalWrite(PIN_BUTTON_RIGHT, HIGH);
pinMode(PIN_BUTTON_LEFT, INPUT);
digitalWrite(PIN_BUTTON_LEFT, HIGH);
pinMode(PIN_BUTTON_UP, INPUT);
digitalWrite(PIN_BUTTON_UP, HIGH);
pinMode(PIN_BUTTON_DOWN, INPUT);
digitalWrite(PIN_BUTTON_DOWN, HIGH);
pinMode(PIN_BUTTON_SELECT, INPUT);
digitalWrite(PIN_BUTTON_SELECT, HIGH);
}void loop() {
// Print the current values of the inputs (joystick and
// buttons) to the console.
Serial.print(&A:&);
Serial.print(digitalRead(PIN_BUTTON_LEFT));
Serial.print(& &);
Serial.print(&B:&);
Serial.print(digitalRead(PIN_BUTTON_RIGHT));
Serial.print(& &);
Serial.print(&C:&);
Serial.print(digitalRead(PIN_BUTTON_UP));
Serial.print(& &);
Serial.print(&D:&);
Serial.print(digitalRead(PIN_BUTTON_DOWN));
Serial.print(& &);
Serial.print(&X:&);
Serial.print(analogRead(PIN_ANALOG_X));
Serial.print(& &);
Serial.print(&Y:&);
Serial.print(analogRead(PIN_ANALOG_Y));
Serial.print(& &);
Serial.print(&s:&);
Serial.print(digitalRead(PIN_BUTTON_SELECT));
Serial.print(& &);
Serial.println();
delay(00);}
这个程序最后的延时可以自己改一下,改在串口监视器上的刷新速度。不管怎样,就是测试一下按键接线在哪而已
我也是新手啊,虽然说测试程序自己该出来了,硬件连接好了,但是游戏开发一窍不通,大神帮我提供一下思路啊,谢谢
下面是5110测试和接线,接线可以直接接到专用接口上,但是我觉得那样偏了,请参考一下这位仁兄这个不是接在专用接口的,要弄弯几个引脚,但是这样视觉效果好。
有什么问题可以提问我,比如接线等,只要我知道的,一定会努力帮你,我的目的就是拉几个人入坑,共同开发而已
待会发个资料的整合包,方便下载!
怎么发压缩包呀?
有人教我怎么发个压缩包吗?
话说,这个硬件的组装非常漂亮
看看  一花凋零荒芜不了整个春天,一次挫折也荒废不了整个人生,一星陨落也暗淡不了整片星辰。
可以玩什么游戏吗
下边是引了什么线出来呢
据了解,贪吃蛇游戏开始的同时需要显示边界以及分数,第二要随机产生食物,第三需要判断是否操纵了摇杆,然后将蛇的方位与按键方位一致,判断是否吃到食物以及碰触到墙壁,最后是游戏结束
今晚先发个游戏测试的程序,应该不算是游戏吧,就是测试joystick和5110的结合而已
怎么办啊,写的测试程序编译总是不通过
楼主,我想用joystick弄个游戏手柄,想再加一点东西,可以把产生的信号发射出去,让智能小车接受,然后实现控制小车,能不能给点建议
是使用蓝牙,还是Wi-Fi去链接这两个设备呢?
最近在做小车,等小车调试完后我可能会把joystick拿来做遥控,用蓝牙接收,大家请期待
帮顶,我也准备做
小车基本成型,可以跑了,看起来高端了许多
433m无线收发模块,准备用来遥控小车
楼主这创意好赞啊,能用pro min做嘛?
有没有电路连接图,那个摇杆只有xy那些左右连到哪里
登录百度帐号Joystick Shield Quickstart Guide - SparkFun Electronics
tags, as close as possible to the opening tag.
Creation Date: 07/18/2016
Customer Service
Mon-Fri, 9am to 12pm and
1pm to 5pm U.S. Mountain Time:
(303) 284-0979
Joystick Shield Quickstart Guide
Skill Level:
May 18, 2010 |
Joystick Shield
Congratulations! Welcome to the wonderful world of joystick control. You'll be surprised by the multitude of uses you'll find for your new joystick. This page serves as a starting point for everything you need to get up and running with the Joystick Shield for the Arduino.
How do I assemble it?
For a step by step guide to assemble the joystick shield, see the .
What do I do with it?
The joystick shield provides simple analog inputs along with four separate buttons and one button under the joystick itself. The joystick can be used for controlling outputs such as a melody or pixels on a screen. The buttons can be used for navigation or game control. If you want to jump directly into the example sketches, go for it:
(printing joystick values and button presses to the console)
(controlling a melody and tempo with the joystick)
(basic Processing integration)
(painting on a window)
If you have no idea what to do with a joystick, checkout this video:
How do I make it work?
Once you've got the shield assembled, you can begin to change the example code to make the joystick do your bidding:
How do I find the current position of the joystick?
The position of the joystick is calculated from the two potentiometers in the joystick. The joystick can move in two dimensions which typically would represent X and Y coordinates but could represent any two dimensional quantity. To read the potentiometers we use the analogRead() function which returns a number from 0 to 1023. We need to supply an analog pin number to the function&for the joystick shield the X position is read from analog pin 0 and the Y position is read from analog pin 1:
Serial.println(analogRead(0)); // Prints current X position
Serial.println(analogRead(1)); // Prints current Y position
It is a good technique&because it clarifies your intent&to use ''constants'' for values that will not change when your sketch runs. With this in mind, the following sketch snippet sets up constants for the analog pins used and prints the current X and Y positions to the serial console:
const byte PIN_ANALOG_X = 0;
const byte PIN_ANALOG_Y = 1;
void setup() {
Serial.begin(9600);
void loop() {
Serial.print(&x:&);
Serial.print(analogRead(PIN_ANALOG_X));
Serial.print(& &);
Serial.print(&y:&);
Serial.print(analogRead(PIN_ANALOG_Y));
Serial.print(& &);
Serial.println();
How do I find the current direction of the joystick?
It can be useful to use the value of the X and Y position to determine if the joystick is centered or moved in one of 8 directions (i.e. up, right-up, right, right-down, down, left-down, left, left-up).
Since we know the value in each dimension will be between 0 and 1023 you might expect the centre value to be around 511 or 512 but because the joysticks are physical devices the actual value is unlikely to be that exact. If we choose the wrong value we'll find that our joystick will be detected as moving in a particular direction even though it is centered.
To work around this issue we specify two &threshold& values and consider that any value within that range should be considered &centered&:
|----------|----|----------|
The threshold values you choose may be different depending on your joystick. We specify the values as constants in the code:
const int X_THRESHOLD_LOW = 505;
const int X_THRESHOLD_HIGH = 515;
const int Y_THRESHOLD_LOW = 500;
const int Y_THRESHOLD_HIGH = 510;
Next, we want to map our value in each dimension from a position range of 0 to 1023 to a direction value in the range -1 to 1. For the X dimension -1 means moved to the left, 0 means not moved in the X dimension and 1 means moved to the right. For the Y dimension -1 means moved down, 0 means not moved in the Y dimension and 1 means moved up.
We start by setting the direction in each dimension to 0 (&centered&) and then we use if/else statements to check if the position value in either dimension is above or below our threshold values:
x_direction = 0;
y_direction = 0;
x_position = analogRead(PIN_ANALOG_X);
y_position = analogRead(PIN_ANALOG_Y);
if (x_position & X_THRESHOLD_HIGH) {
x_direction = 1;
} else if (x_position & X_THRESHOLD_LOW) {
x_direction = -1;
if (y_position & Y_THRESHOLD_HIGH) {
y_direction = 1;
} else if (y_position & Y_THRESHOLD_LOW) {
y_direction = -1;
The Arduino provides a map() function which in theory we could use instead of if/else but the method is complicated by the centering issues so we won't consider that approach here.
As you can see in the next complete example we then use if/else statements to print the direction&you can modify this example to perform whatever action you need:
const byte PIN_ANALOG_X = 0;
const byte PIN_ANALOG_Y = 1;
const int X_THRESHOLD_LOW = 505;
const int X_THRESHOLD_HIGH = 515;
const int Y_THRESHOLD_LOW = 500;
const int Y_THRESHOLD_HIGH = 510;
void setup() {
Serial.begin(9600);
void loop () {
x_direction = 0;
y_direction = 0;
x_position = analogRead(PIN_ANALOG_X);
y_position = analogRead(PIN_ANALOG_Y);
if (x_position & X_THRESHOLD_HIGH) {
x_direction = 1;
} else if (x_position & X_THRESHOLD_LOW) {
x_direction = -1;
if (y_position & Y_THRESHOLD_HIGH) {
y_direction = 1;
} else if (y_position & Y_THRESHOLD_LOW) {
y_direction = -1;
if (x_direction == -1) {
if (y_direction == -1) {
Serial.println(&left-down&);
} else if (y_direction == 0) {
Serial.println(&left&);
// y_direction == 1
Serial.println(&left-up&);
} else if (x_direction == 0) {
if (y_direction == -1) {
Serial.println(&down&);
} else if (y_direction == 0) {
Serial.println(&centered&);
// y_direction == 1
Serial.println(&up&);
// x_direction == 1
if (y_direction == -1) {
Serial.println(&right-down&);
} else if (y_direction == 0) {
Serial.println(&right&);
// y_direction == 1
Serial.println(&right-up&);
How do I set up the Arduino so I can know when a button has been pushed on the Joystick Shield?
Before you can know if a button on the shield has been pushed you need to set up your Arduino to recognize the buttons. Unsurprisingly you will perform this setup in the... setup() function!
First we define constants for the Arduino pin associated with each button:
// Select button is triggered when joystick is pressed
const byte PIN_BUTTON_SELECT = 2;
const byte PIN_BUTTON_RIGHT = 3;
const byte PIN_BUTTON_UP = 4;
const byte PIN_BUTTON_DOWN = 5;
const byte PIN_BUTTON_LEFT = 6;
If you've used a pushbutton switch before you may have noticed a resistor is normally required in order to detect a known voltage when the button is not pressed. To reduce the number of parts required this shield has been designed not to require resistors on the shield itself.& Are you thinking to yourself &if push buttons require resistors and the shield has no resistors how can we get the shield to work?&? If you're not thinking that then you can probably skip reading this bit. (And if you're thinking &I'm really hungry& it might be time to put down the electronics and get some food.)
It turns out your Arduino actually has internal resistors connected to the pins inside the microcontroller. In order to use the internal resistors we need to &enable the internal pull-up resistors&. If that sounds to you like &hoist the jib and unfurl the main stay& then I can explain some more:
When a &pull-up& resistor is connected to a push button it means that the voltage level when the button is not pressed will be HIGH because the resistors &pulls the voltage level up& to HIGH when the button is not pressed. On a typical Arduino a pin that is HIGH will be at 5 volts. When the push button is pressed the pin will read as LOW because there is less resistance between the pin and ground than there is between the pin and 5 volts.
To enable a pin's pull-up resistor you first set the pin as an input and then enable the pull-up:
pinMode(PIN_BUTTON_RIGHT, INPUT);
digitalWrite(PIN_BUTTON_RIGHT, HIGH);
The actual code to enable the pull-up doesn't really make any sense if you read it literally but that's the way it works.
Other than remembering that an unpressed button will read as HIGH with a pull-up resistor and a pressed button will read as LOW you don't need to remember or understand the other details.
In order to configure each pin to be an input and enable the pull up resistors we use the following code:
void setup() {
pinMode(PIN_BUTTON_RIGHT, INPUT);
digitalWrite(PIN_BUTTON_RIGHT, HIGH);
pinMode(PIN_BUTTON_LEFT, INPUT);
digitalWrite(PIN_BUTTON_LEFT, HIGH);
pinMode(PIN_BUTTON_UP, INPUT);
digitalWrite(PIN_BUTTON_UP, HIGH);
pinMode(PIN_BUTTON_DOWN, INPUT);
digitalWrite(PIN_BUTTON_DOWN, HIGH);
pinMode(PIN_BUTTON_SELECT, INPUT);
digitalWrite(PIN_BUTTON_SELECT, HIGH);
See the next section to learn how to read whether a button is pressed or not.
How do I know when a button on the Joystick Shield has been pressed?
Once you have set up your Arduino to recognize the buttons (see above) you can tell whether the button is pressed with the digitalRead() function. When the value read is LOW the button is pressed and when the value is HIGH the button is not pressed.
if (digitalRead(PIN_BUTTON_LEFT) == LOW) {
// Button is pressed
// Button is not pressed
The following complete example will print the state of each button and the value of the joystick to the Arduino serial console:
// Store the Arduino pin associated with each input
// Select button is triggered when joystick is pressed
const byte PIN_BUTTON_SELECT = 2;
const byte PIN_BUTTON_RIGHT = 3;
const byte PIN_BUTTON_UP = 4;
const byte PIN_BUTTON_DOWN = 5;
const byte PIN_BUTTON_LEFT = 6;
const byte PIN_ANALOG_X = 0;
const byte PIN_ANALOG_Y = 1;
void setup() {
Serial.begin(9600);
pinMode(PIN_BUTTON_RIGHT, INPUT);
digitalWrite(PIN_BUTTON_RIGHT, HIGH);
pinMode(PIN_BUTTON_LEFT, INPUT);
digitalWrite(PIN_BUTTON_LEFT, HIGH);
pinMode(PIN_BUTTON_UP, INPUT);
digitalWrite(PIN_BUTTON_UP, HIGH);
pinMode(PIN_BUTTON_DOWN, INPUT);
digitalWrite(PIN_BUTTON_DOWN, HIGH);
pinMode(PIN_BUTTON_SELECT, INPUT);
digitalWrite(PIN_BUTTON_SELECT, HIGH);
void loop() {
Serial.print(&l:&);
Serial.print(digitalRead(PIN_BUTTON_LEFT));
Serial.print(& &);
Serial.print(&r:&);
Serial.print(digitalRead(PIN_BUTTON_RIGHT));
Serial.print(& &);
Serial.print(&u:&);
Serial.print(digitalRead(PIN_BUTTON_UP));
Serial.print(& &);
Serial.print(&d:&);
Serial.print(digitalRead(PIN_BUTTON_DOWN));
Serial.print(& &);
Serial.print(&x:&);
Serial.print(analogRead(PIN_ANALOG_X));
Serial.print(& &);
Serial.print(&y:&);
Serial.print(analogRead(PIN_ANALOG_Y));
Serial.print(& &);
Serial.print(&s:&);
Serial.print(digitalRead(PIN_BUTTON_SELECT));
Serial.print(& &);
Serial.println();
How can I avoid repeating the setup code for each button?
An excellent question&see if you can work out the answer before we write one up. :)
How can I use the joystick with Processing (and Firmata)?
Also an excellent question&see if you can work out the answer before we write one up. :)
Schematic and PCB Layout
For technical information including the schematic and design files, please see the . You may also want to add/review the comments on this page or do a google search for example projects that use the joystick shield.
Startsomething.
What's on your mind?
For which department?
Customer Service
Tech Support
Please include your email address if you'd like us to respond to a specific question.
SparkFun Electronics
No account?
powered by价格从低到高
价格从高到低
相关推荐词
#Arduino课堂#Arduino 通信方式介绍
相关推荐词
浅尝DF micro:bit扩展板
这无厘头标题真不是我扯眼球取的,你看插上连接线的扩展板,像不像个大闸蟹?加之眼下也到了吃大闸蟹的季节,容易让人联想啊!当然,流哈喇子的时候,捏一下肚皮上的救生圈还是能止住的这块扩展板让几个群里
相关推荐词
扩展板是插接在控制器上方的、可以快速实现某一种特定功能的PCBA。扩展板能把各类传感器连接起来并进行统一控制,而不是零散地连接到控制器上。只要大家使用了接口相同的Arduino控制器,扩展板就能被共享使用。
【新品升级】爱上Arduino
爱上Arduino 互动入门套件 中文教材配套 快速入门
UNO R3 升级版通知:产品升级!为了进一步提升Arduino爱好者的入门体验,奥松机器人细心总结每一个
相关推荐词
用visualStudio开发arduino
不要吐槽arduinoIDE没有动态代码高亮、函数跳转等等等功能了,你可以选择更更更高级的IDE进行arduino开发。1.下载VisualStudio下载地址:https://www.visuals
相关推荐词
Arduino 遥控“捕蝇草”
我们将在这个简单又有趣的项目里创造一棵遥控捕蝇草,并将捕蝇草的叶片接上Arduino控制器,再发送微小的电子信号来触发生物反应。组装所需要的时间还不到90分钟,非常适合当做课堂范例。
[{"chanpin":"tmall","mobileUrl":"https://m.tmall.com/mblist/cp_tefM3WFyZA.html","pcUrl":"https://www.tmall.com/mlist/cp_tefM3WFyZA.html","word":"电梯ard"},{"chanpin":"tmall","mobileUrl":"https://m.tmall.com/mblist/cp_YXJkNzAwNGg.html","pcUrl":"https://www.tmall.com/mlist/cp_YXJkNzAwNGg.html","word":"ard7004h"},{"chanpin":"tmall","mobileUrl":"https://m.tmall.com/mblist/cp_YWQ4MDk5YXJk.html","pcUrl":"https://www.tmall.com/mlist/cp_YWQ4MDk5YXJk.html","word":"ad8099ard"},{"chanpin":"tmall","mobileUrl":"https://m.tmall.com/mblist/cp_YWQ4MDQ1YXJk.html","pcUrl":"https://www.tmall.com/mlist/cp_YWQ4MDQ1YXJk.html","word":"ad8045ard"},{"chanpin":"tmall","mobileUrl":"https://m.tmall.com/mblist/cp_MmFyZDY.html","pcUrl":"https://www.tmall.com/mlist/cp_MmFyZDY.html","word":"2ard6"}]1688.com,阿里巴巴打造的全球最大的采购批发平台
1688/淘宝会员(仅限会员名)请在此登录
cbulogin.center.eu13Server is OKJoyStick Shield 游戏摇杆扩展板模拟键盘鼠标功能

我要回帖

更多关于 lka转矩请求原理图 的文章

 

随机推荐