#include <Otto.h>
Otto Otto;

int Zufall = 0;
const char data[] = "VARIABLE#";
unsigned long int matrix;

#define LeftLeg 8 // left leg pin, servo[0]
#define RightLeg 10 // right leg pin, servo[1]
#define LeftFoot 11 // left foot pin, servo[2]
#define RightFoot 12 // right foot pin, servo[3]
#define Buzzer 13 //buzzer pin

#define CLK A2 // Clock pin
#define CS A1  // Chip Select pin
#define DIN A6 // Data In pin
#define Orientation 1// 8x8 LED Matrix orientation  Top  = 1, Bottom = 2, Left = 3, Right = 4
double random_int(int a,int b) {
  if (a > b) {
    int c = a;
    a = b;
    b = c;
  }
  return (double) random(a,b+1);
}
 void Otto_moveLegs(int T, int posLegL, int posLegR, int posFootL, int posFootR) {   int posLegs[]={ posLegL,posLegR,posFootL,posFootR };   Otto._moveServos(T,posLegs); }

void setup() {
  Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer);
Otto.home();

  Otto.initMATRIX( DIN, CS, CLK, Orientation);
  randomSeed(analogRead(0));
  Otto_moveLegs(200,90,90,90,90);
    Otto.putMouth(okMouth);
  delay(1*1000);
  Otto.writeText ( "3,2,1",80); // limited to CAPITAL LETTERS NUMBERS : ; < >  = @, MAX.9 characters
  Otto.writeText ( "Sart",80); // limited to CAPITAL LETTERS NUMBERS : ; < >  = @, MAX.9 characters
  delay(1*1000);
  Otto.writeText ( "Hallo! Ich bin Robi Tool.",80); // limited to CAPITAL LETTERS NUMBERS : ; < >  = @, MAX.9 characters
  delay(1*1000);
  Otto.clearMouth();
  delay(1*1000);

}

void loop() {
    Zufall = random_int(1, 15);
    delay(2*1000);
    if (Zufall == 1) {
      Otto.moonwalker(1, 1000, 25, 1);
      Otto.moonwalker(1, 1000, 25, -1);
    }
    if (Zufall == 2) {
      Otto.crusaito(1, 1000, 25, 1);
      Otto.crusaito(1, 1000, 25, -1);
    }
    if (Zufall == 3) {
      Otto.flapping(1, 1000, 25, 1);
      Otto.flapping(1, 1000, 25, -1);
    }
    if (Zufall == 4) {
      Otto.swing(1, 1000, 25);
    }
    if (Zufall == 5) {
      Otto.updown(1, 1000, 25);
    }
    if (Zufall == 6) {
      Otto.tiptoeSwing(1, 1000, 25);
    }
    if (Zufall == 7) {
      Otto.ascendingTurn(1, 1000, 25);
    }
    if (Zufall == 8) {
      Otto.bend(1,1000,1);
    }
    if (Zufall == 9) {
      Otto.bend(1,1000,-1);
    }
    if (Zufall == 10) {
      Otto.jitter(1, 1000, 25);
    }
    if (Zufall == 11) {
      Otto.jump(1,1000);
    }
    if (Zufall == 12) {
      Otto.shakeLeg(1,1000,-1);
    }
    if (Zufall == 13) {
      Otto.shakeLeg(1,1000,1);
    }
    if (Zufall == 14) {
      Otto.walk(1,1000,1); // FORWARD
    }
    if (Zufall == 15) {
      Otto.walk(1,1000,-1); // BACKWARD
    }
    Otto.putMouth(smile);
    Otto.walk(1,1000,1); // FORWARD
    Otto_moveLegs(200,90,90,90,90);for (int count=0 ; count<2 ; count++) {
      Otto.walk(1,1000,1); // FORWARD
      Otto.walk(1,1000,-1); // BACKWARD
    }
    for (int count=0 ; count<5 ; count++) {
      Otto.moonwalker(1, 1000, 25, 1);
    }
    for (int count=0 ; count<5 ; count++) {
      Otto.moonwalker(1, 1000, 25, -1);
    }
    for (int count=0 ; count<2 ; count++) {
      Otto.swing(1, 1000, 25);
      Otto.jitter(1, 1000, 25);
    }
    delay(3*1000);
    Otto.putMouth(culito);
    delay(3*1000);
    for (int count=0 ; count<5 ; count++) {
      Otto.flapping(1, 1000, 25, 1);
    }
    for (int count=0 ; count<5 ; count++) {
      Otto.flapping(1, 1000, 25, -1);
    }
    delay(3*1000);
    Otto.putMouth(happyOpen);
    delay(3*1000);
    for (int count=0 ; count<10 ; count++) {
      Otto.walk(1,1000,1); // FORWARD
    }
    Otto.writeText ( "FERTIG, BIS BALD.",80); // limited to CAPITAL LETTERS NUMBERS : ; < >  = @, MAX.9 characters
    Otto.shakeLeg(1,1000,-1);

}
