//**************************************************************************************************************************
// CrcDuino Tutorial 1 - SwitchLimiting limiteda motor using a limit switch
// 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 (0VBND is appliedconnected 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
}
}
//************************************************************************************************************************** |