Dreimal kurz einmal lang mit Millis

Gerne möchte ich ein Männchen auf dem LCD mit dem Fuss klopfen lassen und zwar in diesem Rythmus:

#include <LiquidCrystal_I2C.h>
#include <Wire.h>


byte Mann1[] = {
  B01010,
  B00000,
  B00000,
  B10001,
  B11111,
  B01010,
  B01010,
  B11011
};

byte Mann2[] = {
  B01010,
  B00000,
  B00000,
  B10001,
  B11111,
  B01010,
  B01010,
  B11010
};


LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);

  lcd.createChar(1, Mann1);
  lcd.createChar(2, Mann2);

}

void loop() {

  lcd.setCursor(17, 3);
  lcd.write(1);
  delay(300);
  lcd.setCursor(17, 3);
  lcd.write(2);
  delay(300);
  lcd.setCursor(17, 3);
  lcd.write(1);
  delay(300);
  lcd.setCursor(17, 3);
  lcd.write(2);
  delay(300);
  lcd.setCursor(17, 3);
  lcd.write(1);
  delay(300);
  lcd.setCursor(17, 3);
  lcd.write(2);
  delay(300);
  lcd.setCursor(17, 3);
  lcd.write(1);
  delay(300);
  lcd.setCursor(17, 3);
  lcd.write(2);
  delay(300);
  lcd.setCursor(17, 3);
  lcd.write(1);
 delay(3000);

}

Da ich jedoch noch IR Signale empfangen muss etc. taugt diese Lösung mit delay nicht.

Nun versuche ich mit folgenden Variablen etwas zu basteln

uint32_t Fuss_da;
uint32_t Fuss_weg;

int interval_Fuss = 300;
int interval_Fuss_Pause = 3000;
int Fuss_ja_nein = 0
int Zähler Fuss

Finde aber nicht wirklich einen Einstieg. Vielen Dank für eure Hilfe

Der Einstieg wäre das IDE Beispiel "Blink Without Delay".
Ist das schon in Fleisch und Blut übergegangen?

Dann schaust dir deine Sequence an.
A-B-A-B-A-B-Pause

Insgesamt 7 Status
Nach der Pause wieder A-B-...

brauchst also nur in einer finite State Machine weiterzählen.
Mit einem Switch Case abarbeiten.

Guckst du:


const uint16_t interval = 300;
const uint16_t intervalPause = 3000;

void runFSM(uint32_t currentMillis = millis())
{
  static uint8_t state = 0;             // stores the current state, must be static as the value should survive the function call
  static uint32_t previousMillis = 0;   // stores the last time stampe

  switch (state)
  {
    case 0 :
    case 2 :
    case 4 :              // do this in case of 0, 2, and 4
      if (currentMillis - previousMillis > interval)
      {
        previousMillis = currentMillis;
        Serial.println(F("Tipp"));
        state++;   // go to next state
      }
      break;
    case 1 :
    case 3 :
    case 5 :
      if (currentMillis - previousMillis > interval)
      {
        previousMillis = currentMillis;
        Serial.println(F("Tapp"));
        state++; // go to next state
      }
    case 6 :
      if (currentMillis - previousMillis > intervalPause)
      {
        previousMillis = currentMillis;
        Serial.println(F("restart"));
        state = 0; // go back to state 0
      }
  }
}

void setup() {
  Serial.begin(115200);
}

void loop() {
  runFSM();
}

Fleisch und Blut? da müsste ich lügen....
Wau ja genau so! vielen Dank
Im serial Monitor läuft das prima.
Nun habe ich versucht das rüberzuklauen:-)

#include <LiquidCrystal_I2C.h>
#include <Wire.h>


const uint16_t interval = 300;
const uint16_t intervalPause = 3000;

void runFSM(uint32_t currentMillis = millis())
{
  static uint8_t state = 0;             // stores the current state, must be static as the value should survive the function call
  static uint32_t previousMillis = 0;   // stores the last time stampe
  
  switch (state)
  {
    case 0 :
    case 2 :
    case 4 :              // do this in case of 0, 2, and 4
      if (currentMillis - previousMillis > interval)
      {
        previousMillis = currentMillis;
        lcd.setCursor(17, 3);
        lcd.write(1);
        state++;   // go to next state
      }
      break;
    case 1 :
    case 3 :
    case 5 :
      if (currentMillis - previousMillis > interval)
      {
        previousMillis = currentMillis;
        lcd.setCursor(17, 3);
        lcd.write(2);
        state++; // go to next state
      }
    case 6 :
      if (currentMillis - previousMillis > intervalPause)
      {
        previousMillis = currentMillis;
        Serial.println(F("restart"));
        state = 0; // go back to state 0
      }
  }
}


byte Mann1[] = {
  B01010,
  B00000,
  B00000,
  B10001,
  B11111,
  B01010,
  B01010,
  B11011
};

byte Mann2[] = {
  B01010,
  B00000,
  B00000,
  B10001,
  B11111,
  B01010,
  B01010,
  B11010
};


LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);

  lcd.createChar(1, Mann1);
  lcd.createChar(2, Mann2);

}

void loop() {


}

void loop() {
  
  runFSM();


}

aber das wird so nichts oder?

wenn du eine Fehlermeldung erhältst und nicht weiter weist. Dann kopiere die Fehlermeldung raus und frage.

Nein, mit zwei loop() wird es nicht funktionieren.

ah blöd. ohne den 2. loop kommt:

Arduino: 1.8.19 (Linux), Board: "Arduino Uno"











/home/user/Schreibtisch/lazy_bild_f_r_Forum_mit_millies/lazy_bild_f_r_Forum_mit_millies.ino: In function 'void runFSM(uint32_t)':
lazy_bild_f_r_Forum_mit_millies:21:9: error: 'lcd' was not declared in this scope
         lcd.setCursor(17, 3);
         ^~~
lazy_bild_f_r_Forum_mit_millies:32:9: error: 'lcd' was not declared in this scope
         lcd.setCursor(17, 3);
         ^~~
/home/user/Schreibtisch/lazy_bild_f_r_Forum_mit_millies/lazy_bild_f_r_Forum_mit_millies.ino: At global scope:
lazy_bild_f_r_Forum_mit_millies:84:1: error: expected declaration before '}' token
 }
 ^
exit status 1
'lcd' was not declared in this scope


This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Fehlermeldungen lesen!

mach das.

Du legst das lcd Objekt an, willst aber schon vorher darauf zugreifen. Klar dass das nicht geht.
Außerdem fehlt ein break.

und für die reingewürfelten Leerzeilen bekommst auch keinen Blumentopf zurück. Arbeite sauberer.

ungetestet

#include <LiquidCrystal_I2C.h>
#include <Wire.h>

LiquidCrystal_I2C lcd(0x27, 20, 4);

const uint16_t interval = 300;
const uint16_t intervalPause = 3000;

void runFSM(uint32_t currentMillis = millis())
{
  static uint8_t state = 0;             // stores the current state, must be static as the value should survive the function call
  static uint32_t previousMillis = 0;   // stores the last time stampe

  switch (state)
  {
    case 0 :
    case 2 :
    case 4 :              // do this in case of 0, 2, and 4
      if (currentMillis - previousMillis > interval)
      {
        previousMillis = currentMillis;
        lcd.setCursor(17, 3);
        lcd.write(1);
        state++;   // go to next state
      }
      break;
    case 1 :
    case 3 :
    case 5 :
      if (currentMillis - previousMillis > interval)
      {
        previousMillis = currentMillis;
        lcd.setCursor(17, 3);
        lcd.write(2);
        state++; // go to next state
      }
      break; // hast vergessen. 
    case 6 :
      if (currentMillis - previousMillis > intervalPause)
      {
        previousMillis = currentMillis;
        Serial.println(F("restart"));
        state = 0; // go back to state 0
      }
  }
}

byte Mann1[] = {
  B01010,
  B00000,
  B00000,
  B10001,
  B11111,
  B01010,
  B01010,
  B11011
};

byte Mann2[] = {
  B01010,
  B00000,
  B00000,
  B10001,
  B11111,
  B01010,
  B01010,
  B11010
};

void setup() {
  Serial.begin(115200);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);

  lcd.createChar(1, Mann1);
  lcd.createChar(2, Mann2);
}

void loop() {
  runFSM();
}

Vielen herzlichen Dank für die Lösung, den wertvollen Tip

und auch deinen berechtigten Tadel :slight_smile:

Ich habe noch Mann1 und Mann2 getauscht jetzt macht es was es soll: freu*****

#include <LiquidCrystal_I2C.h>
#include <Wire.h>

LiquidCrystal_I2C lcd(0x27, 20, 4);

const uint16_t interval = 300;
const uint16_t intervalPause = 3000;

void runFSM(uint32_t currentMillis = millis())
{
  static uint8_t state = 0;             // stores the current state, must be static as the value should survive the function call
  static uint32_t previousMillis = 0;   // stores the last time stampe

  switch (state)
  {
    case 0 :
    case 2 :
    case 4 :              // do this in case of 0, 2, and 4
      if (currentMillis - previousMillis > interval)
      {
        previousMillis = currentMillis;
        lcd.setCursor(17, 3);
        lcd.write(2);
        state++;   // go to next state
      }
      break;
    case 1 :
    case 3 :
    case 5 :
      if (currentMillis - previousMillis > interval)
      {
        previousMillis = currentMillis;
        lcd.setCursor(17, 3);
        lcd.write(1);
        state++; // go to next state
      }
      break; // hast vergessen. 
    case 6 :
      if (currentMillis - previousMillis > intervalPause)
      {
        previousMillis = currentMillis;
        Serial.println(F("restart"));
        state = 0; // go back to state 0
      }
  }
}

byte Mann1[] = {
  B01010,
  B00000,
  B00000,
  B10001,
  B11111,
  B01010,
  B01010,
  B11011
};

byte Mann2[] = {
  B01010,
  B00000,
  B00000,
  B10001,
  B11111,
  B01010,
  B01010,
  B11010
};

void setup() {
  Serial.begin(115200);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);

  lcd.createChar(1, Mann1);
  lcd.createChar(2, Mann2);
}

void loop() {
  runFSM();
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.