amrmostaafaa
Published © CERN-OHL

Arduino Joystick Servo Control Using 1Sheeld

Controlling a servo motor wirelessly using a smartphone and 1Sheeld board.

EasyFull instructions provided1,529
Arduino Joystick Servo Control Using 1Sheeld

Things used in this project

Story

Read more

Schematics

Ciruit Diagram

Untitled cx3lke7mcm

Code

control_servo_with_gamebad_shield.ino

Arduino
/*
Arduino Joystick Servo Control Project

This example shows an application on 1Sheeld's gamepad shield.

By using this example, you can control a servo motor using Joystick from 1Sheeld.
You can move the servo up, right and left using the shield direction buttons.

OPTIONAL:
To reduce the library compiled size and limit its memory usage, you
can specify which shields you want to include in your sketch by
defining CUSTOM_SETTINGS and the shields respective INCLUDE_ define. 

*/

#define CUSTOM_SETTINGS
#define INCLUDE_GAMEPAD_SHIELD

/* include 1Sheeld library */
#include <OneSheeld.h>

/* include Servo library */
#include <Servo.h>

/* define servo pin */
int servo_pin = 7;

/* make a servo object */
Servo servo;

void setup() {
  
  /* start communication with 1shield */
  OneSheeld.begin();

  /* attach servo pin */
  servo.attach(servo_pin);

  /* initially move servo angel to position 0 degree */
  servo.write(0);
  delay(1000);
}

void loop() {

  /* move servo angel to the most up when up button is pressed */
  if(GamePad.isUpPressed())
  {
    servo.write(80);
  }
  

  /* move servo angel to the most right when right button is pressed */
  else if(GamePad.isRightPressed())
  {
   servo.write(0);
  }

  
  /* move servo angel to the most left when left button is pressed */
  else if(GamePad.isLeftPressed())
  {
   servo.write(180);
  }
  else
  {
    /* Do nothing */
  }
}

Credits

amrmostaafaa

amrmostaafaa

4 projects • 10 followers

Comments