Things used in this project

Hardware components:
1Sheeld Gamepad Shield
×1
Relay (generic)
×8
Robot Chassis
×1

Code

file_14431.txtC/C++
/*

AUTHOR  Eng. Osama Omar



Gamepad Shield Example



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



This example is to full control the MONSTER TRUCK using GAMEPAD shield

it controls the pins connected to RELAYS to control the motion of the car



NOTE: RELAYS is used instead of H-bridge motor drivers to give the car high power

, So number of RELAYS used is 8 , ( 2 RELAYs for each MOTOR )



RELAYS connected to pins 4,5,6,7,10,11,12,13



*/



/* Include 1Sheeld library. */

#include <OneSheeld.h>



void setup() 

{

  /* Start communication. */

  OneSheeld.begin();

  /* Set RELAY connected pins as output. */

  pinMode(13,OUTPUT);

  pinMode(12,OUTPUT);

  pinMode(11,OUTPUT);

  pinMode(10,OUTPUT);

  pinMode(4,OUTPUT);

  pinMode(5,OUTPUT);

  pinMode(6,OUTPUT);

  pinMode(7,OUTPUT);

  pinMode(2,OUTPUT);  // For FRONT car LIGHTS

  pinMode(3,OUTPUT);  // For BACK  car LIGHTS

  

}



void loop() 

{

  /* Always check the status of gamepad buttons. */

  if (GamePad.isUpPressed())

  {

    // Moving Forward

    /* Turn on the 4 RELAYS when up is pressed. */

    digitalWrite(13,HIGH);

    digitalWrite(12,HIGH);

    digitalWrite(11,HIGH);

    digitalWrite(10,HIGH);

    digitalWrite(4,LOW);

    digitalWrite(5,LOW);

    digitalWrite(6,LOW);

    digitalWrite(7,LOW);

  }

else if(GamePad.isDownPressed())

  {

    //Moving Backward

   /* Turn on other 4 RELAYS when up is pressed. */

    digitalWrite(12,LOW);

    digitalWrite(13,LOW);

    digitalWrite(11,LOW);

    digitalWrite(10,LOW);

    digitalWrite(4,HIGH);

    digitalWrite(5,HIGH);

    digitalWrite(6,HIGH);

    digitalWrite(7,HIGH);

  }

  else if(GamePad.isLeftPressed())

  {

    //Moving Left

   /* Turn on other 4 RELAYS when up is pressed. */

    digitalWrite(12,LOW);

    digitalWrite(13,LOW);

    digitalWrite(11,HIGH);

    digitalWrite(10,HIGH);

    digitalWrite(4,HIGH);

    digitalWrite(5,HIGH);

    digitalWrite(6,LOW);

    digitalWrite(7,LOW);

  }

  else if(GamePad.isRightPressed())

  {

    //Moving Right

   /* Turn on other 4 RELAYS when up is pressed. */

    digitalWrite(12,HIGH);

    digitalWrite(13,HIGH);

    digitalWrite(11,LOW);

    digitalWrite(10,LOW);

    digitalWrite(4,LOW);

    digitalWrite(5,LOW);

    digitalWrite(6,HIGH);

    digitalWrite(7,HIGH);

  }

 else if (GamePad.isOrangePressed())

  {

    // FRONT car lights ON

    /* Turn on the LED on pin 2 when orange is pressed. */

    digitalWrite(2,HIGH);

   

  }

 else if (GamePad.isGreenPressed())

  {

    // BACK car lights ON

    /* Turn on the LED on pin 3 when red is pressed. */

    digitalWrite(3,HIGH);

  }

  else

  {

    // NO thing is pressed all PINS are OFF

    digitalWrite(12,LOW);

    digitalWrite(13,LOW);

    digitalWrite(11,LOW);

    digitalWrite(10,LOW);

    digitalWrite(4,LOW);

    digitalWrite(5,LOW);

    digitalWrite(6,LOW);

    digitalWrite(7,LOW);

    digitalWrite(3,LOW);

    digitalWrite(2,LOW);

    

  }

}

Credits

10996581 1000088933335923 687107123103877150 n
Eng Osama Omar
2 projects • 10 followers
Head of embedded Systems at CECE lab Cairo university
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaBlog