Eng Osama Omar
Created March 5, 2015 © Beerware

Full Control on Monster Truck

With voice and gamepad control

Work in progress2,579
Full Control on Monster Truck

Things used in this project

Hardware components

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

Story

Read more

Code

file_14431.txt

C/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

Eng Osama Omar

Eng Osama Omar

2 projects • 11 followers
Head of embedded Systems at CECE lab Cairo university

Comments