#define burnInputPin 36
#define rotMotRel 40
#define kapSensPin4 29
#define conLed1Pin 15 // Buchse 15, viol (Control Led 1)
#define conLed2Pin 17 // Buchse 15, rosa (Control Led 2)
bool refScreenA;
bool kapSens4 = LOW;
bool kapSens4State = LOW;
unsigned int helixSetRotStart = 10; // 240/h how many calls are needed to start rot
unsigned int rotStartCount = 0; // Counter for min Calls at Start
byte rotTaktMax = 10; // max. Kettenintervalle ab wann ein Rührwerkintervall Startet
byte rotTakt = 5; // Rotations-Intervall von Brenner ab wann ein Rühr-Interval folgen soll
byte rotTimeCopy = 0;
byte rotTime = 5; // Rotorzeit
byte rotTimeMax = 30; // 30 sek > 5 U bei 10 U/min
bool rotInputStat = LOW; // StatusFlag für Impulszaehlung Brenner-Eingang
byte rotCount = 0; // Zähler Spiral-Intervalle
bool rotTaktStatus = LOW; // StatusFlag für Rotations timing
unsigned long nowRotTimeOld; // TimeStore Rot-Timing
bool rotState = LOW; // Toogle RotMot at BurnStart
byte burnStartRotCount = 0; // ProzessCounter RotStart
unsigned long nowRotStartOld;
unsigned long nowRotMillisOld;
unsigned long nowRotOnMillisOld;
unsigned long nowRotOffMillisOld;
byte waitRotInStart = 20;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(burnInputPin, INPUT_PULLUP);
pinMode(kapSensPin4, INPUT_PULLUP);
pinMode(rotMotRel, OUTPUT);
pinMode(conLed1Pin, OUTPUT);
pinMode(conLed2Pin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (rotInputStat == LOW && digitalRead(burnInputPin) == LOW){
rotInputStat = HIGH;
rotStartCount ++;
rotCount ++;
}
if (rotInputStat == HIGH && digitalRead(burnInputPin)== HIGH){
rotInputStat = LOW;
}
kapSens4 = !digitalRead(kapSensPin4); // High = Pellets contact, invers input, sensor detekt = input LOW = value HIGH
rotMotor();
serial();
}
void rotMotor(){
if (kapSens4 == HIGH){ // Reset HelixRotCount if DayBox are full
rotStartCount = 0;
}
if (rotStartCount >= helixSetRotStart ){
// auswerten der gezählten Takte
if (rotCount >= rotTakt && rotTaktStatus == LOW){
rotTaktStatus = HIGH;
rotCount = 0;
nowRotTimeOld = millis();
}
if (rotTaktStatus == HIGH){
//digitalWrite(rotMotRel, HIGH); // Rot-Rel ein
digitalWrite(rotMotRel, LOW); // Invers Rot-Rel ein
digitalWrite(conLed2Pin, HIGH); // ControlLED an
refScreenA = HIGH; // aktualisiere Display
if (millis() - nowRotTimeOld > (rotTime*1000)) { // 10U/min = 1U/6 Sek = 1 HalfTurn / 3sec, 1U Standard = 6 sek
rotTaktStatus = LOW;
//digitalWrite(rotMotRel, LOW); // Rot-Rel aus
digitalWrite(rotMotRel, HIGH); // Invers Rot-Rel aus
digitalWrite(conLed2Pin, LOW); // ControlLED aus
refScreenA = HIGH; // aktualisiere Display
}
}
}
}
void serial(){
Serial.print("rotStartCount: ");
Serial.println(rotStartCount);
Serial.print("rotCount: ");
Serial.println(rotCount);
}
//--- alt --------------------------------------------------------
/*
// Serial.println(helixCount);
if (rotInputStat == LOW && digitalRead(burnInputPin) == LOW){
rotInputStat = HIGH;
helixCount ++;
}
if (rotInputStat == HIGH && digitalRead(burnInputPin)== HIGH){
rotInputStat = LOW;
}
if (helixCount > helixSetCall){
// digitalWrite(rotMotRel, HIGH);
compSwL = 1;
compNow = millis();
helixCount = 0;
}
if (compSwL == 1){
// if (digitalRead(rotMotRel), HIGH){
digitalWrite(rotMotRel, HIGH);
if (millis() - compNow >= (compRunTme * 1000)) {
digitalWrite(rotMotRel, LOW);
compSwL = 0;
}
}
*/