You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

44 lines
1009 B

#include <Arduino.h>
#include "esp32-hal-ledc.h"
#include "semaphore.h"
#include "driver/ledc.h"
#include "hardware.h"
#include "pusher.h"
using namespace std;
Pusher::Pusher(void) {
xSemaphore = xSemaphoreCreateMutex();
}
void Pusher::setup(void) {
ledcSetup(channel, 50, TIMER_WIDTH);
for(int pin : SERVO_PINS) {
if (xSemaphoreTake(xSemaphore, TIMEOUT) == pdTRUE) {
ledcAttachPin(pin, channel);
ledcWrite(channel, MAX_PULSE_WIDTH);
delay(500);
ledcDetachPin(pin);
xSemaphoreGive(xSemaphore);
Serial.print("configured pin ");
Serial.println(pin);
}
}
}
void Pusher::push(int num) {
if (xSemaphoreTake(xSemaphore, TIMEOUT) == pdTRUE) {
int pin = SERVO_PINS[num];
// ledcSetup(channel, 50, TIMER_WIDTH);
ledcAttachPin(pin, channel);
ledcWrite(channel, MIN_PULSE_WIDTH);
delay(1000);
ledcWrite(channel, MAX_PULSE_WIDTH);
delay(1000);
ledcDetachPin(pin);
xSemaphoreGive(xSemaphore);
} else {
return;
}
}