Last active
January 3, 2016 02:29
-
-
Save johnReeve/8395518 to your computer and use it in GitHub Desktop.
My 2-joystick serial controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
2-stick Serial Controller w/ xBee funcionality | |
*/ | |
#include <SoftwareSerial.h> | |
#define echoToSerialOut true | |
#define rxPin 2 | |
#define txPin 3 | |
#define ledPin 13 | |
#define left_stick_Y A1 | |
#define left_stick_X A0 | |
#define left_select 6 | |
#define right_stick_Y A3 | |
#define right_stick_X A2 | |
#define right_select 7 | |
SoftwareSerial xbee(rxPin, txPin); // RX, TX | |
#define delimiter "/" | |
#define terminator "//\n\r" | |
void setup() | |
{ | |
pinMode(ledPin, OUTPUT); | |
pinMode(rxPin, INPUT); | |
pinMode(txPin, OUTPUT); | |
pinMode(left_select, INPUT); | |
pinMode(right_select, INPUT); | |
xbee.begin(9600); | |
} | |
void loop() // run over and over | |
{ | |
//check_Left_Yposition(); | |
xbee.print("LEFT_Y:"); | |
xbee.print(map(analogRead(left_stick_Y), 0, 1023, -100, 100)); | |
xbee.print(delimiter); | |
//check_Left_Xposition(); | |
xbee.print("LEFT_X:"); | |
xbee.print(map(analogRead(left_stick_X), 0, 1023, -100, 100)); | |
xbee.print(delimiter); | |
//check_Left_select: | |
xbee.print("LEFT_SEL:"); | |
xbee.print(digitalRead(left_select) == LOW ? "1" : "0"); | |
xbee.print(delimiter); | |
// check_Right_Yposition(); | |
xbee.print("RIGHT_Y:"); | |
xbee.print(map(analogRead(right_stick_Y), 0, 1023, -100, 100)); | |
xbee.print(delimiter); | |
// check_Right_Xposition(); | |
xbee.print("RIGHT_X:"); | |
xbee.print(map(analogRead(right_stick_X), 0, 1023, -100, 100)); | |
xbee.print(delimiter); | |
//check_Right_select(); | |
xbee.print("RIGHT_SEL:"); | |
xbee.print(digitalRead(right_select) == LOW ? "1" : "0"); | |
xbee.print(delimiter); | |
xbee.print(terminator); | |
// wait 2 milliseconds before the next loop | |
// for the analog-to-digital converter to settle | |
// after the last reading: | |
delay(2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment