Skip to content

Instantly share code, notes, and snippets.

@labajo
Created December 20, 2017 09:01
Show Gist options
  • Save labajo/5c5b85ae3d45c4b88f4f5c99845d1813 to your computer and use it in GitHub Desktop.
Save labajo/5c5b85ae3d45c4b88f4f5c99845d1813 to your computer and use it in GitHub Desktop.
Arduino Joystick
#include <Adafruit_ADS1015.h>
#include "RestClient.h"
RestClient client = RestClient("192.168.2.1", 3000);
Adafruit_ADS1115 ads;
int buttonState = 0;
void setup(void)
{
Serial.begin(115200);
Serial.println("Controller Started!");
ads.begin();
pinMode(D3, INPUT);
client.begin("MissileLauncher", "12345678");
}
void loop(void)
{
buttonState = digitalRead(D3);
String response = "";
if (buttonState == HIGH) {
Serial.println("Button not pressed");
int statusCode = client.get("/pepe", &response);
Serial.print("Status code from server: ");
Serial.println(statusCode);
Serial.print("Response body from server: ");
Serial.println(response);
} else {
Serial.println("Button pressed");
int statusCode = client.get("/con?on=true", &response);
Serial.print("Status code from server: ");
Serial.println(statusCode);
Serial.print("Response body from server: ");
Serial.println(response);
}
int16_t adc0, adc1;
adc0 = ads.readADC_SingleEnded(0);
adc1 = ads.readADC_SingleEnded(1);
Serial.print("AIN0: "); Serial.println(adc0);
Serial.print("AIN1: "); Serial.println(adc1);
Serial.println(" ");
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment