Giter Site home page Giter Site logo

loop-inglouie's Introduction

Loop()ingLouie

This project is in German. Please drop us a line if you'd like to see it translated.

Loop()ingLouie macht Looping Louie wieder krass! Schneller fahren, rückwärts fahren, oder einfach mal anhalten ... whaaat? Aber macht euch selbst ein Bild. Mit versteckter Kamera haben wir einen frühen Prototypen filmen können: [Link zum Video folgt]

Hardware

Unser Controller besteht aus einem Arduino Nano, 3 LEDs, einem Powerswitch, und einem Knopf. Details folgen noch.

Logik

Das Herzstück des Codes ist ein Array von Funktionen, die die Spielmodi darstellen. Sie liefern einen float zwischen -1 und 1 (≙ "Vollgas rückwärts" und "Vollgas vorwärts"). Zwei Beispielmodi:

typedef float (*Spielmodus) ();
Spielmodus spielmodi[] = {
  []() -> float {
    // Vollgas
    return 1.0f;
  },
  
  []() -> float {
    // Zwischen zwei Geschwindigkeiten sinus-förmig oszillieren
    const float pi = static_cast<float>(atan(1)*4);
    const float low = 0.24f;
    const float high = 1.0f;
    return clip(static_cast<float>((high-low)/2+low + sin(laufzeit_spielmodus_get()/(2*pi*130))*((high-low)/2)), low, high);
  },
  
  []() -> float {
    // ...
  }
};

Es sind natürlich auch kompliziertere Funktionen möglich:

[]() -> float {
  bremse bis zum Stehenbleiben
  warte eine zufällige Zeit lang
  fahre vorwärts mit Vollgas
}

Im loop() wird mit der aktuell ausgewählten Funktion die Geschwindigkeit bestimmt und am Motor eingestellt:

void loop() {
  static Button button(12); // Button an Pin 12
  static const Motor motor(6, 5); // Motor an Pins 6 und 5

  // Bei Knopfdruck nächsten Spielmodus auswählen
  button.status_abfragen();
  if (button.wurde_losgelassen()) {
    spielmodus = (spielmodus + 1) % anzahl_spielmodi; // Den nächsten Spielmodus auswählen
  }

  // Geschwindigkeit je nach Spielmodus einstellen
  motor.geschwindigkeit_set(spielmodi[spielmodus]());
}

Fragen?

Dann schreibt uns einfach! (:

loop-inglouie's People

Contributors

twiddler avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.