joystick 002 — ESP32 simulation

An interactive ESP32 circuit simulation you can run free in your browser on Velxio, by josephkinuthia541.

Components

Sketch code

const int VERT = 35;
const int HOR  = 34;
const int SEL  = 27;

const int CENTER = 2048;
const int DEADZONE = 300;

void setup() {
  Serial.begin(115200);

  pinMode(SEL, INPUT_PULLUP);
}

void loop() {

  int vertical = analogRead(VERT);
  int horizontal = analogRead(HOR);
  int selectButton = digitalRead(SEL);

  // VERTICAL DIRECTION
  if (vertical > CENTER + DEADZONE) {
    Serial.println("VERTICAL: DOWN");
  }
  else if (vertical < CENTER - DEADZONE) {
    Serial.println("VERTICAL: UP");
  }
  else {
    Serial.println("VERTICAL: CENTER");
  }

  // HORIZONTAL DIRECTION
  if (horizontal > CENTER + DEADZONE) {
    Serial.println("HORIZONTAL: RIGHT");
  }
  else if (horizontal < CENTER - DEADZONE) {
    Serial.println("HORIZONTAL: LEFT");
  }
  else {
    Serial.println("HORIZONTAL: CENTER");
  }

  // PUSH BUTTON
  if (selectButton == LOW) {
    Serial.println("SELECT: PRESSED");
  }
  else {
    Serial.println("SELECT: NOT PRESSED");
  }

  Serial.println("--------------------");

  delay(200);
}

More projects by josephkinuthia541