various fixes for grooves
This commit is contained in:
parent
71f791dcf5
commit
cc143c08e8
59
feeder.ino
59
feeder.ino
|
@ -4,7 +4,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define EE_RESET 26 // любое число 0-255. Измени, чтобы сбросить настройки и обновить время
|
#define EE_RESET 26 // любое число 0-255. Измени, чтобы сбросить настройки и обновить время
|
||||||
#define FEED_SPEED 500 // задержка между шагами мотора (мкс)
|
#define FEED_SPEED 250 // задержка между шагами мотора (мкс) def: 1500
|
||||||
#define DIRPIN 2 // d2 направление
|
#define DIRPIN 2 // d2 направление
|
||||||
#define STEPPIN 3 // d3 движение
|
#define STEPPIN 3 // d3 движение
|
||||||
#define BTN_PIN 4 // кнопка выдачи
|
#define BTN_PIN 4 // кнопка выдачи
|
||||||
|
@ -22,17 +22,17 @@
|
||||||
#define STEPPER_SPEED 250
|
#define STEPPER_SPEED 250
|
||||||
|
|
||||||
#define STEPPER_REV 800
|
#define STEPPER_REV 800
|
||||||
#define STEPPER_DELAY 500
|
#define STEPPER_DELAY 200
|
||||||
#define GROOVE_COUNT 3
|
#define GROOVE_COUNT 3
|
||||||
#define GEAR 4*3.857 // 3.857 - это соотношение зубцов внутреннее шестеренки и белого круга с орехами
|
#define GEAR 4*3.857 // 3.857 - это соотношение зубцов внутреннее шестеренки и белого круга с орехами
|
||||||
|
|
||||||
// =========================================================
|
// =========================================================
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
#include <Thread.h>
|
#include <Thread.h>
|
||||||
#include <ThreadController.h>
|
//#include <ThreadController.h>
|
||||||
Thread IRLedThread = Thread();
|
Thread IRLedThread = Thread();
|
||||||
Thread MotorThread = Thread();
|
Thread MotorThread = Thread();
|
||||||
ThreadController threadController = ThreadController();
|
//ThreadController threadController = ThreadController();
|
||||||
|
|
||||||
#include "microDS3231.h"
|
#include "microDS3231.h"
|
||||||
MicroDS3231 rtc;
|
MicroDS3231 rtc;
|
||||||
|
@ -79,6 +79,8 @@ unsigned long sleepTime; // переменная для задания врем
|
||||||
|
|
||||||
int monitor_speed = 9600;
|
int monitor_speed = 9600;
|
||||||
|
|
||||||
|
int failures = 0; // счетчик ошибок на IR
|
||||||
|
|
||||||
// GND -- [ R2 ] -- A0 -- [ R1 ] -- VIN
|
// GND -- [ R2 ] -- A0 -- [ R1 ] -- VIN
|
||||||
#define VREF 3.94 // точное напряжение на пине 5V (в данном случае зависит от стабилизатора на плате Arduino)
|
#define VREF 3.94 // точное напряжение на пине 5V (в данном случае зависит от стабилизатора на плате Arduino)
|
||||||
#define DIV_R1 10000 // точное значение 6.80 кОм резистора
|
#define DIV_R1 10000 // точное значение 6.80 кОм резистора
|
||||||
|
@ -129,6 +131,7 @@ void setup()
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
//empty_signal = analogRead(IRsens); // считать пустой (опорный) сигнал
|
||||||
static uint32_t tmr = 0;
|
static uint32_t tmr = 0;
|
||||||
float voltage = (float)analogRead(0) * VREF * ((DIV_R1 + DIV_R2) / DIV_R2) / 1024;
|
float voltage = (float)analogRead(0) * VREF * ((DIV_R1 + DIV_R2) / DIV_R2) / 1024;
|
||||||
if (millis() - tmr > 500)
|
if (millis() - tmr > 500)
|
||||||
|
@ -152,8 +155,15 @@ void loop()
|
||||||
digitalWrite(RELAY, LOW);
|
digitalWrite(RELAY, LOW);
|
||||||
delay(sleepTime);
|
delay(sleepTime);
|
||||||
}
|
}
|
||||||
if ((now.hour >= onTime && now.hour < offTime && voltage > VOLT && analogRead(IRsens) > 100 && analogRead(IRsens) < 1000 ))
|
if (analogRead(IRsens) > 400 && analogRead(IRsens) < 1000) {
|
||||||
{ //&& voltage > 10.5 && IR sensor is good
|
failures = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
failures++;
|
||||||
|
Serial.println("Ошибок IR: " + String(failures));
|
||||||
|
}
|
||||||
|
if (now.hour >= onTime && now.hour < offTime && voltage > VOLT && failures < 60)
|
||||||
|
{ //&& voltage > 10.2
|
||||||
digitalWrite(RELAY, HIGH); // работаем если время рабочее И напряжение выше минимума
|
digitalWrite(RELAY, HIGH); // работаем если время рабочее И напряжение выше минимума
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -238,30 +248,38 @@ void loop()
|
||||||
void feed()
|
void feed()
|
||||||
{
|
{
|
||||||
Serial.println("Feeding...");
|
Serial.println("Feeding...");
|
||||||
int counted = 0;
|
int counted = 0; int rev = 0;
|
||||||
static uint32_t tmr = 0;
|
static uint32_t tmr = 0;
|
||||||
EEPROM.put(3, counted); // Начинаем отсчет орехов на выдачу
|
EEPROM.put(3, counted); // Начинаем отсчет орехов на выдачу
|
||||||
|
|
||||||
|
//threadController.clear();
|
||||||
|
//threadController.add(&IRLedThread);
|
||||||
|
//threadController.add(&MotorThread);
|
||||||
|
|
||||||
feedAmount = EEPROM.read(1);
|
feedAmount = EEPROM.read(1);
|
||||||
//Serial.println("IR sens: " + String(analogRead(IRsens)));
|
Serial.println("IR sens: " + String(analogRead(IRsens)));
|
||||||
//Serial.println("Groove amount: " + String(feedAmount));
|
Serial.println("Groove amount: " + String(feedAmount));
|
||||||
|
|
||||||
for (int i = 0; i < feedAmount; i++){
|
for (int i = 0; i < feedAmount; i++){
|
||||||
tmr = millis();
|
tmr = millis();
|
||||||
while (1) {
|
while (1) {
|
||||||
if (millis() - tmr > 10000)
|
if (millis() - tmr > 6000)
|
||||||
{
|
{
|
||||||
motorRev();
|
motorRev(); rev++;
|
||||||
tmr = millis();
|
if (rev >= 5) {
|
||||||
|
rev = 0;
|
||||||
|
tmr = millis();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
digitalWrite(SLEEP, HIGH);
|
||||||
|
MotorThread.run();
|
||||||
}
|
}
|
||||||
digitalWrite(SLEEP, HIGH);
|
|
||||||
MotorThread.run();
|
|
||||||
IRLedThread.run();
|
IRLedThread.run();
|
||||||
grooveCounted = EEPROM.read(3);
|
grooveCounted = EEPROM.read(3);
|
||||||
if (grooveCounted > counted) {
|
if (grooveCounted > counted) {
|
||||||
counted = grooveCounted;
|
counted = grooveCounted;
|
||||||
//Serial.println("Now " + String(counted) + " grooves");
|
Serial.println("Now " + String(counted) + " grooves");
|
||||||
delayMicroseconds(STEPPER_DELAY);
|
//delayMicroseconds(STEPPER_DELAY);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,6 +288,7 @@ void feed()
|
||||||
}
|
}
|
||||||
|
|
||||||
disableMotor();
|
disableMotor();
|
||||||
|
//threadController.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeederMotor()
|
void FeederMotor()
|
||||||
|
@ -280,19 +299,21 @@ void FeederMotor()
|
||||||
|
|
||||||
void motorRev()
|
void motorRev()
|
||||||
{
|
{
|
||||||
myStepper.step(-((STEPPER_REV * GEAR) / GROOVE_COUNT));
|
//myStepper.step(-((STEPPER_REV * GEAR) / GROOVE_COUNT));
|
||||||
|
myStepper.step(-300);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRLedCount()
|
void IRLedCount()
|
||||||
{
|
{
|
||||||
grooveCounted = EEPROM.read(3);
|
grooveCounted = EEPROM.read(3);
|
||||||
|
|
||||||
for (int i=0; i<50; i++)
|
for (int i=0; i<300; i++)
|
||||||
{
|
{
|
||||||
//Serial.println(String(analogRead(IRsens)));
|
//Serial.println(String(analogRead(IRsens)));
|
||||||
if (analogRead(IRsens) > 980) {
|
if (analogRead(IRsens) > 980) {
|
||||||
//Serial.println(grooveCounted++);
|
Serial.println(grooveCounted++);
|
||||||
EEPROM.put(3, grooveCounted++);
|
EEPROM.put(3, grooveCounted++);
|
||||||
|
//myStepper.step(-((STEPPER_REV * GEAR) / GROOVE_COUNT));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue