   Toy.decreasePower();
 }
 
-
+// Add a pattern to the toy
+void AddPattern(int (*patternFunc)(int)) {
+  Toy.addPattern(patternFunc);
+  currentPatternNumber++;
+}
+
+// Often used object-functions in own functions = smaller
+int SerialParseInt() {
+  return Serial.parseInt();
+}
+
+void SetOutput(int n, int v) {
+    Toy.setOutput(n, v);
+}
+
+void SetLED(int v) {
+    Toy.setLED(0, v);
+}
+
+// Serial.println-Calls in functions, this way object-reference only needed once
+void PrintLine(float number) {
+  Serial.println(number);
+}
+
+void PrintLine(int number) {
+  Serial.println(number);
+}
+
+void PrintLine(unsigned int number) {
+  Serial.println(number);
+}
+
+void PrintLine(String text) {
+  Serial.println(text);
+}
+
+// Print Pattern number or "User Pattern"
+void PrintPattern() {
+  int val = Toy.getPattern();
+  if (val == userPatternNumber) {
+    String strPrint = "";
+    strPrint += val;
+    strPrint += " (User Pattern)";
+    PrintLine(strPrint);
+  }
+  else
+    PrintLine(val);
+}
+
+// Play the User transmitted pattern, for example:
+// U 3,255 0 0 500, 0 0 255 500, 0 255 0 500
+// 3 Entries
+// First Motor 255, Second 0, Third 0, for 500ms
+// First Motor 0, Second 0, Third 255, for 500ms
+// First Motor 0, Second 255, Third 0, for 500ms
+int userPatternPlayer(int seq) {
+  // If no Userpattern created yet, skip to next pattern
+  if (userPatternSize == 0)
+    Toy.cyclePattern();
+  else {
+    seq %= userPatternSize;
+    SetMotorsAndTime(userPattern[seq*4], userPattern[seq*4+1], userPattern[seq*4+2], userPattern[seq*4+3]);
+  }
+  return 1;
+}
+

  // Set the patterns that the button will cycle through. Toy will do nothing on startup, and clicking the button once will run the 'first' pattern
  // Clicking again will run 'second', etc.

  Toy.addPattern(first);
  Toy.addPattern(second);
  Toy.addPattern(third);
  Toy.addPattern(pulse);
  Toy.addPattern(fadeCos);
  Toy.addPattern(weird3);
  Toy.addPattern(sharpRamp);
  Toy.addPattern(flicker);
  Toy.addPattern(weird2);
  Toy.addPattern(fadeOffset);
  Toy.addPattern(pulse2);

  // Set up the button click handlers
  Toy.attachClick(click);

// Add the pattern library.
#include "patterns.h"

/*
Available commands over Serial:
- <n>         = Set Value for all Motors : Returns nothing
0 <n>         = Set Value for Motor 1 : Return current Value
1 <n>         = Set Value for Motor 2 : Return current Value
2 <n>         = Set Value for Motor 3 : Return current Value
c             = Cycle Pattern : Returns running pattern
g             = Get number of currently running pattern : Returns running pattern
i             = Read input 0 or 1 : Returns value of input
l <n>         = Set LED power : Return current Value
p             = Decrease Power : Returns new Powerlevel
P             = Increase Power : Returns new Powerlevel
r <n>         = Run a specific pattern, r,0; r,1; etc. : Returns running pattern
s             = Stop all Motors, reset Patternnumber, Power & Timescale : Returns nothing
t             = Decrease pattern time, as in everything goes faster : Returns new Timescale
T             = Increase pattern time, as in everything goes slower : Returns new Timescale
{<n>,<n>,<n>} = Set Value for Motor1,2 and 3 in a single line : Returns nothing

New from v0.2.2:
G = get Powerlevel : Returns Powerlevel
v = get Version : Returns Version information

New from v0.2.4:
U ... = Play the User transmitted pattern, for example:
U 3,255 0 0 500, 0 0 255 500, 0 255 0 500
3 Entries
First Motor 255, Second 0, Third 0, for 500ms
First Motor 0, Second 0, Third 255, for 500ms
First Motor 0, Second 255, Third 0, for 500ms

allStop Pattern added

New from v0.2.5:
u = Returns current Userpattern
*/

const String txtVersion = "Mod-Sketch v0.2.5";
int* userPattern; // Will dynamicly be allocated/freed
int userPatternSize = 0;
int userPatternNumber = 0; // Number of the Userpattern
int currentPatternNumber = 0; // Currently added Pattern number

void setup() {
  Toy.setID(); // Set Toy ID using default Value, currently 1 = MOD
  
  // Button will increase/decrease power by 20%
  Toy.setPowerScaleStep(0.2);
  
