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.
 
 

46 lines
1000 B

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