This repository has been archived on 2022-01-28. You can view files and clone it, but cannot push or open issues or pull requests.
Marlin-Artillery-M600/Marlin/src/HAL/HAL_LPC1768/LPC1768_Servo.h

63 lines
2.6 KiB
C
Raw Normal View History

/**
* Marlin 3D Printer Firmware
* Copyright (C) 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
2017-09-01 00:30:43 +02:00
* The class Servo uses the PWM class to implement its functions
*
* The PWM1 module is only used to generate interrups at specified times. It
* is NOT used to directly toggle pins. The ISR writes to the pin assigned to
* that interrupt
*
* All PWMs use the same repetition rate - 20mS because that's the normal servo rate
*
*/
2017-09-01 00:30:43 +02:00
#ifndef LPC1768_SERVO_H
#define LPC1768_SERVO_H
2017-09-06 13:28:32 +02:00
#include <stdint.h>
2017-09-01 00:30:43 +02:00
2017-09-06 13:28:32 +02:00
class Servo {
public:
Servo();
2017-09-27 10:33:29 +02:00
int8_t attach(const int pin); // attach the given pin to the next free channel, set pinMode, return channel number (-1 on fail)
int8_t attach(const int pin, const int min, const int max); // as above but also sets min and max values for writes.
2017-09-06 13:28:32 +02:00
void detach();
2017-09-29 15:17:30 +02:00
void write(int value); // if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds
void writeMicroseconds(int value); // write pulse width in microseconds
void move(const int value); // attach the servo, then move to value
2017-09-06 13:28:32 +02:00
// if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds
// if DEACTIVATE_SERVOS_AFTER_MOVE wait SERVO_DELAY, then detach
int read(); // returns current pulse width as an angle between 0 and 180 degrees
int readMicroseconds(); // returns current pulse width in microseconds for this servo (was read_us() in first release)
bool attached(); // return true if this servo is attached, otherwise false
2017-09-01 00:30:43 +02:00
2017-09-06 13:28:32 +02:00
private:
uint8_t servoIndex; // index into the channel data for this servo
int min;
int max;
};
2017-09-01 00:30:43 +02:00
2017-09-06 13:28:32 +02:00
#define HAL_SERVO_LIB Servo
2017-09-01 00:30:43 +02:00
#endif // LPC1768_SERVO_H