mirror of
https://github.com/KevinMidboe/Arduino.git
synced 2025-10-29 17:40:11 +00:00
Init commit with many years of arduino sketches and projects. I dont know if the esp8266 includes much, but there are also libraries. I hope they dont have crazy automatic versioning through the Arduino IDE.
This commit is contained in:
1
Projects/libraries/Installed_libs/JoystickController/.gitignore
vendored
Executable file
1
Projects/libraries/Installed_libs/JoystickController/.gitignore
vendored
Executable file
@@ -0,0 +1 @@
|
||||
.DS_Store
|
||||
@@ -0,0 +1,62 @@
|
||||
#include "JoystickController.h"
|
||||
|
||||
JoystickController controller;
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
controller.update();
|
||||
|
||||
if (controller.selectButtonPressed()){
|
||||
Serial.println("S");
|
||||
}
|
||||
|
||||
if (controller.upButtonPressed()){
|
||||
Serial.println("U");
|
||||
}
|
||||
|
||||
if (controller.downButtonPressed()){
|
||||
Serial.println("D");
|
||||
}
|
||||
|
||||
if (controller.leftButtonPressed()){
|
||||
Serial.println("L");
|
||||
}
|
||||
|
||||
if (controller.rightButtonPressed()){
|
||||
Serial.println("R");
|
||||
}
|
||||
|
||||
int direct = controller.getDirection();
|
||||
|
||||
switch (direct){
|
||||
case JoystickController::DIRECTION_UP:
|
||||
Serial.println("UP");
|
||||
break;
|
||||
case JoystickController::DIRECTION_UP_RIGHT:
|
||||
Serial.println("UP-RIGHT");
|
||||
break;
|
||||
case JoystickController::DIRECTION_RIGHT:
|
||||
Serial.println("RIGHT");
|
||||
break;
|
||||
case JoystickController::DIRECTION_DOWN_RIGHT:
|
||||
Serial.println("DOWN-RIGHT");
|
||||
break;
|
||||
case JoystickController::DIRECTION_DOWN:
|
||||
Serial.println("DOWN");
|
||||
break;
|
||||
case JoystickController::DIRECTION_DOWN_LEFT:
|
||||
Serial.println("DOWN-LEFT");
|
||||
break;
|
||||
case JoystickController::DIRECTION_LEFT:
|
||||
Serial.println("LEFT");
|
||||
break;
|
||||
case JoystickController::DIRECTION_UP_LEFT:
|
||||
Serial.println("UP-LEFT");
|
||||
break;
|
||||
}
|
||||
|
||||
delay(100);
|
||||
}
|
||||
184
Projects/libraries/Installed_libs/JoystickController/JoystickController.cpp
Executable file
184
Projects/libraries/Installed_libs/JoystickController/JoystickController.cpp
Executable file
@@ -0,0 +1,184 @@
|
||||
#include "Arduino.h"
|
||||
#include "JoystickController.h"
|
||||
|
||||
enum PINS{
|
||||
PIN_ANALOG_X = 0,
|
||||
PIN_ANALOG_Y = 1,
|
||||
PIN_BUTTON_SELECT = 2,
|
||||
PIN_BUTTON_UP = 4,
|
||||
PIN_BUTTON_DOWN = 5,
|
||||
PIN_BUTTON_LEFT = 6,
|
||||
PIN_BUTTON_RIGHT = 3
|
||||
};
|
||||
|
||||
JoystickController::JoystickController(int low, int high){
|
||||
_threshouldLow = low;
|
||||
_threshouldHigh = high;
|
||||
this->_setup();
|
||||
}
|
||||
|
||||
void JoystickController::update(){
|
||||
this->_reset();
|
||||
this->_updateDirection();
|
||||
this->_updateButtons();
|
||||
}
|
||||
|
||||
int JoystickController::getDirection(){
|
||||
return _direction;
|
||||
}
|
||||
|
||||
bool JoystickController::selectButtonPressed(){
|
||||
return _selectButtonPressed;
|
||||
}
|
||||
|
||||
bool JoystickController::upButtonPressed(){
|
||||
return _upButtonPressed;
|
||||
}
|
||||
|
||||
bool JoystickController::downButtonPressed(){
|
||||
return _downButtonPressed;
|
||||
}
|
||||
|
||||
bool JoystickController::leftButtonPressed(){
|
||||
return _leftButtonPressed;
|
||||
}
|
||||
|
||||
bool JoystickController::rightButtonPressed(){
|
||||
return _rightButtonPressed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected.
|
||||
*/
|
||||
void JoystickController::_reset(){
|
||||
_direction = DIRECTION_NONE;
|
||||
_selectButtonPressed = false;
|
||||
_upButtonPressed = false;
|
||||
_downButtonPressed = false;
|
||||
_leftButtonPressed = false;
|
||||
_rightButtonPressed = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected.
|
||||
*/
|
||||
void JoystickController::_setup(){
|
||||
pinMode(PIN_BUTTON_SELECT, INPUT);
|
||||
digitalWrite(PIN_BUTTON_SELECT, HIGH);
|
||||
|
||||
pinMode(PIN_BUTTON_UP, INPUT);
|
||||
digitalWrite(PIN_BUTTON_UP, HIGH);
|
||||
|
||||
pinMode(PIN_BUTTON_DOWN, INPUT);
|
||||
digitalWrite(PIN_BUTTON_DOWN, HIGH);
|
||||
|
||||
pinMode(PIN_BUTTON_LEFT, INPUT);
|
||||
digitalWrite(PIN_BUTTON_LEFT, HIGH);
|
||||
|
||||
pinMode(PIN_BUTTON_RIGHT, INPUT);
|
||||
digitalWrite(PIN_BUTTON_RIGHT, HIGH);
|
||||
|
||||
this->_reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected.
|
||||
*/
|
||||
void JoystickController::_updateDirection(){
|
||||
const int NONE = 0;
|
||||
const int POSITIVE = 1;
|
||||
const int NEGATIVE = -1;
|
||||
|
||||
int x = analogRead(PIN_ANALOG_X);
|
||||
int y = analogRead(PIN_ANALOG_Y);
|
||||
|
||||
int directX = NONE;
|
||||
int directY = NONE;
|
||||
|
||||
if (x < _threshouldLow){
|
||||
directX = NEGATIVE;
|
||||
}
|
||||
|
||||
if (x > _threshouldHigh){
|
||||
directX = POSITIVE;
|
||||
}
|
||||
|
||||
if (y < _threshouldLow){
|
||||
directY = NEGATIVE;
|
||||
}
|
||||
|
||||
if (y > _threshouldHigh){
|
||||
directY = POSITIVE;
|
||||
}
|
||||
|
||||
if (directX == NONE){
|
||||
if (directY == POSITIVE){
|
||||
_direction = DIRECTION_UP;
|
||||
}
|
||||
if (directY == NEGATIVE){
|
||||
_direction = DIRECTION_DOWN;
|
||||
}
|
||||
}
|
||||
|
||||
if (directX == POSITIVE){
|
||||
if (directY == NONE){
|
||||
_direction = DIRECTION_RIGHT;
|
||||
}
|
||||
if (directY == POSITIVE){
|
||||
_direction = DIRECTION_UP_RIGHT;
|
||||
}
|
||||
if (directY == NEGATIVE){
|
||||
_direction = DIRECTION_DOWN_RIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
if (directX == NEGATIVE){
|
||||
if (directY == NONE){
|
||||
_direction = DIRECTION_LEFT;
|
||||
}
|
||||
if (directY == POSITIVE){
|
||||
_direction = DIRECTION_UP_LEFT;
|
||||
}
|
||||
if (directY == NEGATIVE){
|
||||
_direction = DIRECTION_DOWN_LEFT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected.
|
||||
*/
|
||||
void JoystickController::_updateButtons(){
|
||||
int S = digitalRead(PIN_BUTTON_SELECT);
|
||||
int U = digitalRead(PIN_BUTTON_UP);
|
||||
int D = digitalRead(PIN_BUTTON_DOWN);
|
||||
int L = digitalRead(PIN_BUTTON_LEFT);
|
||||
int R = digitalRead(PIN_BUTTON_RIGHT);
|
||||
|
||||
if (this->_buttonPressed(S)){
|
||||
_selectButtonPressed = true;
|
||||
}
|
||||
|
||||
if (this->_buttonPressed(U)){
|
||||
_upButtonPressed = true;
|
||||
}
|
||||
|
||||
if (this->_buttonPressed(D)){
|
||||
_downButtonPressed = true;
|
||||
}
|
||||
|
||||
if (this->_buttonPressed(L)){
|
||||
_leftButtonPressed = true;
|
||||
}
|
||||
|
||||
if (this->_buttonPressed(R)){
|
||||
_rightButtonPressed = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected.
|
||||
*/
|
||||
bool JoystickController::_buttonPressed(int state){
|
||||
return (state == LOW);
|
||||
}
|
||||
71
Projects/libraries/Installed_libs/JoystickController/JoystickController.h
Executable file
71
Projects/libraries/Installed_libs/JoystickController/JoystickController.h
Executable file
@@ -0,0 +1,71 @@
|
||||
#ifndef __JOYSTICKCONTROLLER_H__
|
||||
#define __JOYSTICKCONTROLLER_H__
|
||||
|
||||
class JoystickController{
|
||||
protected:
|
||||
static const int DEFAULT_LOW = 490;
|
||||
static const int DEFAULT_HIGH = 530;
|
||||
|
||||
int _threshouldLow;
|
||||
int _threshouldHigh;
|
||||
|
||||
int _direction;
|
||||
bool _selectButtonPressed;
|
||||
bool _upButtonPressed;
|
||||
bool _downButtonPressed;
|
||||
bool _leftButtonPressed;
|
||||
bool _rightButtonPressed;
|
||||
|
||||
void _setup();
|
||||
void _reset();
|
||||
void _updateDirection();
|
||||
void _updateButtons();
|
||||
bool _buttonPressed(int state);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Directions in the integer format.
|
||||
*/
|
||||
static const int DIRECTION_NONE = 0;
|
||||
static const int DIRECTION_UP = 1;
|
||||
static const int DIRECTION_UP_RIGHT = 2;
|
||||
static const int DIRECTION_RIGHT = 3;
|
||||
static const int DIRECTION_DOWN_RIGHT = 4;
|
||||
static const int DIRECTION_DOWN = 5;
|
||||
static const int DIRECTION_DOWN_LEFT = 6;
|
||||
static const int DIRECTION_LEFT = 7;
|
||||
static const int DIRECTION_UP_LEFT = 8;
|
||||
|
||||
/**
|
||||
* Constructor. The first argument specifies the lower threshould value for the directional key pad,
|
||||
* below which the controller is assumed to set left/down in the horizontal/vertical direction.
|
||||
* The second argument specifies the upper threshould value,
|
||||
* above which the controller is assumed to set right/up in the horizontal/vertical direction.
|
||||
*/
|
||||
JoystickController(int low = DEFAULT_LOW, int high = DEFAULT_HIGH);
|
||||
|
||||
/**
|
||||
* Must get called in the main loop.
|
||||
*/
|
||||
void update();
|
||||
|
||||
/**
|
||||
* Returns the current direction in the integer format.
|
||||
*/
|
||||
int getDirection();
|
||||
|
||||
/**
|
||||
* Returns true if a button is being pressed, otherwise false.
|
||||
*/
|
||||
bool upButtonPressed();
|
||||
bool downButtonPressed();
|
||||
bool leftButtonPressed();
|
||||
bool rightButtonPressed();
|
||||
|
||||
/**
|
||||
* Returns true if the select button (directional keypad) is being pressed, otherwise false.
|
||||
*/
|
||||
bool selectButtonPressed();
|
||||
};
|
||||
|
||||
#endif
|
||||
7
Projects/libraries/Installed_libs/JoystickController/LICENSE
Executable file
7
Projects/libraries/Installed_libs/JoystickController/LICENSE
Executable file
@@ -0,0 +1,7 @@
|
||||
Copyright (c) 2012 boreal-kiss.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
120
Projects/libraries/Installed_libs/JoystickController/README.md
Executable file
120
Projects/libraries/Installed_libs/JoystickController/README.md
Executable file
@@ -0,0 +1,120 @@
|
||||
# JoystickController
|
||||
|
||||
Fully compatible with SparkFun's [Arduino joystick shield](https://www.sparkfun.com/products/9760?). The library lets you easily fetch the current status of the joystick (demo video is [here](https://vimeo.com/49010406)). Implementation is quite simple;
|
||||
|
||||
JoystickController(int low = DEFAULT_LOW, int high = DEFAULT_HIGH)
|
||||
|
||||
is a constructor. The first argument specifies the lower threshold value for the directional key pad, below which the controller is assumed to set left/down in the horizontal/vertical direction. The second argument specifies the upper threshold value, above which the controller is assumed to set right/up in the horizontal/vertical direction. If arguments are not specified, the following default values will be used:
|
||||
|
||||
static const int DEFAULT_LOW = 490;
|
||||
static const int DEFAULT_HIGH = 530;
|
||||
|
||||
For more information about the threshold see the following article; [How do I find the current direction of the joystick?](http://www.sparkfun.com/tutorials/171#direction)
|
||||
|
||||
void update()
|
||||
|
||||
must get called in the main loop in order for the library to communicate with the joystick.
|
||||
|
||||
int getDirection()
|
||||
|
||||
returns the current direction of the directional keypad as integer values that are defined as class static variables:
|
||||
|
||||
static const int DIRECTION_NONE = 0;
|
||||
static const int DIRECTION_UP = 1;
|
||||
static const int DIRECTION_UP_RIGHT = 2;
|
||||
static const int DIRECTION_RIGHT = 3;
|
||||
static const int DIRECTION_DOWN_RIGHT = 4;
|
||||
static const int DIRECTION_DOWN = 5;
|
||||
static const int DIRECTION_DOWN_LEFT = 6;
|
||||
static const int DIRECTION_LEFT = 7;
|
||||
static const int DIRECTION_UP_LEFT = 8;
|
||||
|
||||
Finally buttons' status can be fetched from the following functions:
|
||||
|
||||
bool upButtonPressed()
|
||||
bool downButtonPressed()
|
||||
bool leftButtonPressed()
|
||||
bool rightButtonPressed()
|
||||
bool selectButtonPressed()
|
||||
|
||||
They return true if a button is being pressed, otherwise false.
|
||||
|
||||
## Example
|
||||
|
||||
Here is a simple example for the library implementation.
|
||||
|
||||
#include "JoystickController.h"
|
||||
|
||||
JoystickController controller;
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
controller.update();
|
||||
|
||||
if (controller.selectButtonPressed()){
|
||||
Serial.println("S");
|
||||
}
|
||||
|
||||
if (controller.upButtonPressed()){
|
||||
Serial.println("U");
|
||||
}
|
||||
|
||||
if (controller.downButtonPressed()){
|
||||
Serial.println("D");
|
||||
}
|
||||
|
||||
if (controller.leftButtonPressed()){
|
||||
Serial.println("L");
|
||||
}
|
||||
|
||||
if (controller.rightButtonPressed()){
|
||||
Serial.println("R");
|
||||
}
|
||||
|
||||
int direct = controller.getDirection();
|
||||
|
||||
switch (direct){
|
||||
case JoystickController::DIRECTION_UP:
|
||||
Serial.println("UP");
|
||||
break;
|
||||
case JoystickController::DIRECTION_UP_RIGHT:
|
||||
Serial.println("UP-RIGHT");
|
||||
break;
|
||||
case JoystickController::DIRECTION_RIGHT:
|
||||
Serial.println("RIGHT");
|
||||
break;
|
||||
case JoystickController::DIRECTION_DOWN_RIGHT:
|
||||
Serial.println("DOWN-RIGHT");
|
||||
break;
|
||||
case JoystickController::DIRECTION_DOWN:
|
||||
Serial.println("DOWN");
|
||||
break;
|
||||
case JoystickController::DIRECTION_DOWN_LEFT:
|
||||
Serial.println("DOWN-LEFT");
|
||||
break;
|
||||
case JoystickController::DIRECTION_LEFT:
|
||||
Serial.println("LEFT");
|
||||
break;
|
||||
case JoystickController::DIRECTION_UP_LEFT:
|
||||
Serial.println("UP-LEFT");
|
||||
break;
|
||||
}
|
||||
|
||||
delay(100);
|
||||
}
|
||||
|
||||
## Related articles
|
||||
|
||||
* [Arduino joystick controller library](http://blog.boreal-kiss.net/2012/09/07/arduino-joystick-controller-library/)
|
||||
|
||||
## License
|
||||
|
||||
This project is provided under the terms of the [MIT License](http://www.opensource.org/licenses/mit-license.php).
|
||||
|
||||
## Contact
|
||||
|
||||
* [http://blog.boreal-kiss.net/](http://blog.boreal-kiss.net/)
|
||||
* [http://twitter.com/borealkiss](http://twitter.com/borealkiss)
|
||||
35
Projects/libraries/Installed_libs/JoystickController/keywords.txt
Executable file
35
Projects/libraries/Installed_libs/JoystickController/keywords.txt
Executable file
@@ -0,0 +1,35 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map for JoystickController
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
JoystickController KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
update KEYWORD2
|
||||
getDirection KEYWORD2
|
||||
selectButtonPressed KEYWORD2
|
||||
upButtonPressed KEYWORD2
|
||||
downButtonPressed KEYWORD2
|
||||
leftButtonPressed KEYWORD2
|
||||
rightButtonPressed KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
DIRECTION_NONE LITERAL1
|
||||
DIRECTION_UP LITERAL1
|
||||
DIRECTION_UP_RIGHT LITERAL1
|
||||
DIRECTION_RIGHT LITERAL1
|
||||
DIRECTION_DOWN_RIGHT LITERAL1
|
||||
DIRECTION_DOWN LITERAL1
|
||||
DIRECTION_DOWN_LEFT LITERAL1
|
||||
DIRECTION_LEFT LITERAL1
|
||||
DIRECTION_UP_LEFT LITERAL1
|
||||
Reference in New Issue
Block a user