Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

Version 1 Next »

Objective

The objective of this tutorial is to reproduce the behavior of a mechanism for which we want to limit
the movement using a limit switch. Limit switches are often use to indicate that a mechanism has
reached a certain position, or to automatically stop the motor that moves a mechanism that has
reached the limit of its reach. In simpler terms: we want the motor to stop before is breaks
everything!

Wiring schematics and complete presentation

Code

Download the Arduino IDE .ino file:

//**************************************************************************************************************************
// CrcDuino Tutorial 1 - Switch limited motor
// NOTE: Continuous Servos often have a calibration screw on their side.
//       When sending a "0" speed command, adjust it so that the motor doesn't run
//**************************************************************************************************************************
#include <CrcLib.h> //CrcLib program requirement
//Rename IOs with meaningful name (good practice)
#define SERVO_CONT_1 CRC_PWM_5
#define BTN_RUN CRC_DIG_1
#define LS1_SERVO_CONT_1 CRC_DIG_2
using namespace Crc; //CrcLib program requirement
//**************************************************************************************************************************
void setup() {
// put your setup code here, to run once at the beginning:
CrcLib::Initialize(); //Sets up the CrcDuino
CrcLib::InitializePwmOutput(SERVO_CONT_1); //Sets up the motor output
CrcLib::SetDigitalPinMode(BTN_RUN, INPUT); //Sets up the digital port as an Input
CrcLib::SetDigitalPinMode(LS1_SERVO_CONT_1, INPUT);
}
//**************************************************************************************************************************
void loop() {
// put your main code here, to run repeatedly:
CrcLib::Update(); //Refreshes the CrcDuino
if( !(CrcLib::GetDigitalInput(BTN_RUN)) ) //When the button is pressed (0V applied to the input)
{
if( CrcLib::GetDigitalInput(LS1_SERVO_CONT_1) ) //But only if the limit switch is not pressed (5V applied to the input)
{
CrcLib::SetPwmOutput(SERVO_CONT_1, 127); //127=Full speed
}
else //when the limit switch is pressed...
{
CrcLib::SetPwmOutput(SERVO_CONT_1, 0); //0=stop
}
}
else //when the button is not pressed...
{
CrcLib::SetPwmOutput(SERVO_CONT_1, 0); //0=stop
}
}
//**************************************************************************************************************************
  • No labels

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.