/*####################################################################
FILE: robot_def.ino VERSION: 1.0
Descrizione: Programma di test robot comandato tramite 1Sheeld's gamepad shield
Ultima modifica il 19/6/2016
Applicazione realizzata da Adriano Gandolfo
Sito https://www.adrirobot.it
This example code is in the public domain.
####################################################################*/
#define CUSTOM_SETTINGS
#define INCLUDE_GAMEPAD_SHIELD
/* Include 1Sheeld library. */
#include <OneSheeld.h>
/* Configurazione dei pin del modulo L9110. */
int motorAPin1 = 5;
int motorAPin2 = 6;
int motorBPin1 = 10;
int motorBPin2 = 11;
void setup()
{
/* Start communication. */
OneSheeld.begin();
/* initialization modulo L9110 */
pinMode(motorAPin1, OUTPUT); // IN1 of motor A
pinMode(motorAPin2, OUTPUT); // IN2 of motor A
pinMode(motorBPin1, OUTPUT); // IN3 of motor B
pinMode(motorBPin2, OUTPUT); // IN4 of motor B
}
void loop()
{
/* If up is pressed, move the car forward. */
if (GamePad.isUpPressed())
{
digitalWrite(motorAPin1, HIGH);
digitalWrite(motorAPin2, LOW);
digitalWrite(motorBPin1, LOW);
digitalWrite(motorBPin2, HIGH);
}
/* If down is pressed, move the car backwards. */
else if (GamePad.isDownPressed())
{
digitalWrite(motorAPin1, LOW);
digitalWrite(motorAPin2, HIGH);
digitalWrite(motorBPin1, HIGH);
digitalWrite(motorBPin2, LOW);
}
/* Se si preme destra, il robot ruota a destra */
else if (GamePad.isRightPressed())
{
digitalWrite(motorAPin1, LOW);
digitalWrite(motorAPin2, HIGH);
digitalWrite(motorBPin1, LOW);
digitalWrite(motorBPin2, HIGH);
}
/* Se si preme sinistra, il robot ruota a sinistra */
else if (GamePad.isLeftPressed())
{
digitalWrite(motorAPin1, HIGH);
digitalWrite(motorAPin2, LOW);
digitalWrite(motorBPin1, HIGH);
digitalWrite(motorBPin2, LOW);
}
/* If nothing is pressed stop all motors. */
else
{
digitalWrite(motorAPin1, LOW);
digitalWrite(motorAPin2, LOW);
digitalWrite(motorBPin1, LOW);
digitalWrite(motorBPin2, LOW);
}
} |