Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Joystick.h>
- Joystick_ Joystick;
- int xAxis_ = 0;
- int yAxis_ = 0;
- int zAxis_ = 0;
- int RxAxis_ = 0;
- int RyAxis_ = 0;
- int RzAxis_ = 0;
- int Throttle_ = 0;
- const int armAndStage = 2;
- const int abortButton = 3;
- const int rcsSwitch = 5;
- const int sasSwitch = 6;
- const int lightsButton = 7;
- const int gearsButton = 8;
- const int solarButton = 9;
- const int escButton = 10;
- const int timeUp = 11;
- const int timeDown = 12;
- const bool initAutoSendState = true;
- void setup() {
- pinMode(armAndStage, INPUT);
- pinMode(abortButton, INPUT_PULLUP);
- pinMode(sasSwitch, INPUT_PULLUP);
- pinMode(rcsSwitch, INPUT_PULLUP);
- pinMode(lightsButton, INPUT_PULLUP);
- pinMode(gearsButton, INPUT_PULLUP);
- pinMode(solarButton, INPUT_PULLUP);
- pinMode(escButton, INPUT_PULLUP);
- pinMode(timeUp, INPUT_PULLUP);
- pinMode(timeDown, INPUT_PULLUP);
- Joystick.begin();
- }
- void loop() {
- controls();
- }
- void controls(void) {
- if (digitalRead(armAndStage) == HIGH) {
- Joystick.pressButton(armAndStage);
- }
- else {
- Joystick.releaseButton(armAndStage);
- }
- if (digitalRead(abortButton) == LOW) {
- Joystick.pressButton(abortButton);
- }
- else {
- Joystick.releaseButton(abortButton);
- }
- if (digitalRead(rcsSwitch == LOW)) {
- Joystick.pressButton(rcsSwitch);
- }
- else {
- Joystick.releaseButton(rcsSwitch);
- }
- if (digitalRead(sasSwitch) == LOW) {
- Joystick.pressButton(sasSwitch);
- }
- else {
- Joystick.releaseButton(sasSwitch);
- }
- if (digitalRead(lightsButton) == LOW) {
- Joystick.pressButton(lightsButton);
- }
- else {
- Joystick.releaseButton(lightsButton);
- }
- if (digitalRead(gearsButton) == LOW) {
- Joystick.pressButton(gearsButton);
- }
- else {
- Joystick.releaseButton(gearsButton);
- }
- if (digitalRead(solarButton) == LOW) {
- Joystick.pressButton(solarButton);
- }
- else {
- Joystick.releaseButton(solarButton);
- }
- if (digitalRead(escButton) == LOW) {
- Joystick.pressButton(escButton);
- }
- else {
- Joystick.releaseButton(escButton);
- }
- if (digitalRead(timeUp) == LOW) {
- Joystick.pressButton(timeUp);
- }
- else {
- Joystick.releaseButton(timeUp);
- }
- if (digitalRead(timeDown) == LOW) {
- Joystick.pressButton(timeDown);
- }
- else {
- Joystick.releaseButton(timeDown);
- }
- xAxis_ = analogRead(A0);
- xAxis_ = map(xAxis_,1023,0,255,0);
- Joystick.setXAxis(xAxis_);
- yAxis_ = analogRead(A1);
- yAxis_ = map(yAxis_,0,1023,0,255);
- Joystick.setYAxis(yAxis_);
- zAxis_ = analogRead(A2);
- zAxis_ = map(zAxis_,0,1023,0,255);
- Joystick.setZAxis(zAxis_);
- RxAxis_ = analogRead(A3);
- RxAxis_ = map(RxAxis_,0,1023,0,255);
- Joystick.setRxAxis(RxAxis_);
- RyAxis_ = analogRead(A4);
- RyAxis_ = map(RyAxis_,0,1023,0,255);
- Joystick.setRyAxis(RyAxis_);
- RzAxis_ = analogRead(A5);
- RzAxis_ = map(RzAxis_,0,1023,0,255);
- Joystick.setRzAxis(RzAxis_);
- Throttle_ = analogRead(A6);
- Throttle_ = map(Throttle_,0,1023,0,255);
- Joystick.setThrottle(Throttle_);
- delay (10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement