/************************************************************************
*
* Test of Pmod HB3
*
*************************************************************************
* Description: Pmod_HB3
* Switch SW1 controls the stop or rotation of the motor.
* Switch SW2 controls the direction of rotation of the motor.
* The status of the motor is displayed on the serial monitor.
*
* Material
* 1. Arduino Uno
* 2. Pmod HB3
* 3. Pmod SWT
*
************************************************************************/
// Affectation of pins
#define DIRECTION 2
#define VALIDATION 3
#define SWT_1 4
#define SWT_2 5
boolean inter_1;
boolean inter_2;
void setup()
{
Serial.begin(9600); // Initialization of the serial monitor
pinMode(DIRECTION,OUTPUT); // Pin configuration
pinMode VALIDATION,OUTPUT);
pinMode(SWT_1,INPUT);
pinMode(SWT_2,INPUT);
}
void loop()
{
inter_1=digitalRead(SWT_1); // Reading switch SW1
inter_2=digitalRead(SWT_2); // Reading switch SW2
if (inter_1==HIGH) // stop motor
{
digitalWrite(DIRECTION,LOW);
digitalWrite(VALIDATION,LOW);
Serial.println("Le moteur est arrete"); // display in serial monitor
}
else // The motor is running
{
if (inter_2==HIGH)
{
digitalWrite(DIRECTION,HIGH);
digitalWrite(VALIDATION,HIGH);
Serial.println("Le moteur tourne dans le sens horaire");
}
else
{
digitalWrite(DIRECTION,LOW);
digitalWrite(VALIDATION,HIGH);
Serial.println("Le moteur tourne dans le sens anti-horaire");
}
}
}
Comments
Please log in or sign up to comment.