ärgern wollte ich bestimmt keinen, mein "geschreibsel" ist bestimmt kein Geheimniss

weil die Funktion aber richtig aufgerufen wird, dachte ich es reicht wenn ich danach frage wie ich das "Zeitglied" für die Einschaltdauer der Pumpe in dieser Funktion bilde. Natürlich dennoch hier der gesamte bisherige Code.
// this constant won't change:
const byte m_button = 4;
const byte s_button = 1;
const byte pinPot = 3;
const byte ledPin = 2; // the pin that the LED is attached to
const byte Pump = 0;
// Variables will change:
byte m_buttonPushCounter = 0; // (Menge) counter for the number of button presses
byte m_buttonState = 0; // (Menge) current state of the button
byte m_lastButtonState = 0; // (Menge) previous state of the button
byte s_buttonPushCounter = 0; // (Start/Stop Taster) counter for the number of button presses
byte s_buttonState = 0; // (Start/Stop Taster) current state of the button
byte s_lastButtonState = 0; // (Start/Stop Taster) previous state of the button
byte ledState = LOW; // ledState used to set the LED
unsigned long s_currentMillis = 0;
long s_previousMillis = 0;
unsigned long m_currentMillis = 0;
long m_previousMillis = 0;
long previousMillis = 0; // will store last time LED was updated
//long interval = 3000; // interval at which to blink (milliseconds)
int valPot = 0; // Zum zwischenspeichern des Potentiometerwert
byte pumpPoti;
byte pwmPump = 0; //Sollwert der Pumpe (6-12V) von Potentiometer
byte blinks = 0;
void setup()
{
pinMode (m_button, INPUT); // m_Button pin als Eingang deklariert
pinMode (s_button, INPUT); // s_Button pin als Eingang deklariert
pinMode (Pump, OUTPUT); // pin 5 // OC0A
pinMode(ledPin, OUTPUT);
//Timer 0, A side
TCCR0A = _BV (WGM00) | _BV (WGM01) | _BV (COM0A1); // fast PWM, clear OC0A on compare
TCCR0B = _BV (CS00); // fast PWM, top at 0xFF, no prescaler
pwmPump = 0; // PWM duty cycle
} // end of setup
void loop() {
// read the pushbutton input pin:
valPot = analogRead(pinPot); //Potentiometerwert einlesen
pumpPoti = map(valPot, 0, 1023, 85, 255); //Anpassung Potentiometerwert (0-1024) zu pumpPoti (6-12V=135-255)
m_buttonState = digitalRead(m_button);
if (m_buttonState != m_lastButtonState) { // compare the buttonState to its previous state
if (m_buttonState == HIGH) { // if the state has changed, increment the counter
m_buttonPushCounter++; // if the current state is HIGH then the button went from off to on:
}
}
m_lastButtonState = m_buttonState; // save the current state as the last state, for next time through the loop
if (m_buttonPushCounter == 1){
pwmPump = pumpPoti;
m_currentMillis = millis();
if(m_currentMillis - m_previousMillis > 25000) { // Blinktakt 1 * LED freigeben
m_previousMillis = m_currentMillis;
if (blinks == false)
blinks = true;
else
blinks = false;
}
Blinktakt(blinks);
}
if (m_buttonPushCounter == 2){
pwmPump = 135;
m_currentMillis = millis();
if(m_currentMillis - m_previousMillis > 50000) { // Blinktakt 2 * LED freigeben
m_previousMillis = m_currentMillis;
if (blinks == false)
blinks = true;
else
blinks = false;
}
Blinktakt(blinks);
}
if (m_buttonPushCounter == 3){
pwmPump = 180;
m_currentMillis = millis();
if(m_currentMillis - m_previousMillis > 75000) { // Blinktakt 3 * LED freigeben
m_previousMillis = m_currentMillis;
if (blinks == false)
blinks = true;
else
blinks = false;
}
Blinktakt(blinks);
}
if (m_buttonPushCounter == 4) {
//m_buttonPushCounter = 0;
pwmPump = 222;
m_currentMillis = millis();
if(m_currentMillis - m_previousMillis > 100000) { // Blinktakt 4 * LED freigeben
m_previousMillis = m_currentMillis;
if (blinks == false)
blinks = true;
else
blinks = false;
}
Blinktakt(blinks);
}
if (m_buttonPushCounter == 5) {
m_buttonPushCounter = 1;
}
int m_time = 10;
StartderPumpe(pwmPump, m_time); //Übergabe an "Void Start der Pumpe"
}
void StartderPumpe(byte startPump, int timePump){ //Neue Funktion; Übergabe START _ STOPP (PWM) und Einschaltdauer der Pumpe
s_buttonState = digitalRead(s_button);
if (s_buttonState != s_lastButtonState) { // compare the buttonState to its previous state
if (s_buttonState == HIGH) { // if the state has changed, increment the counter
s_buttonPushCounter++; // if the current state is HIGH then the button went from off to on:
}
}
s_lastButtonState = s_buttonState; // save the current state as the last state, for next time through the loop
if (s_buttonPushCounter % 2 == 0) { //Vergleich zwischen m_buttonPushCounter und Teiler, auf Rest 0
s_currentMillis = millis();
if(s_currentMillis - s_previousMillis > timePump) {
s_previousMillis = s_currentMillis;
s_buttonPushCounter++;
}
else {
analogWrite(Pump, startPump);
}
}
else {
analogWrite(Pump, 0);
}
}
void Blinktakt(int interval) { //Neue Funktion Blinktakt der LED
if(interval == true) {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > 12500) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}
if(interval == false){
digitalWrite(ledPin, LOW);
}
}
Zur Erklärung: mit dem m_buttoon kann ich 4 PWM Frequenzen für die Pumpe auswählen (Stufe 1 Potentiometerwert), mit s_button starte und stoppe ich die Pumpe. Die LED gibt den Status der Stufe wieder.
Also bitte nicht falschverstehen, der Code wird einigen die Tränen in die Augen treiben, aber mir geht es in diesem Projekt schließlich ums lernen :-)