#include <TVout.h>
#include <fontALL.h>
#include <EtherCard.h>
#define STATIC 0


TVout TV;

String L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14, L15, L16, L17, L18, L19, L20, 
L21, L22, L23, L24, L25, L26, L27, L28, L29, L30, L31, L32, L33, L34, L35, L36, L37, L38, L39, L40,
L41, L42, L43, L44,L45, L46, L47, L48, L49, L50, L51, L52, L53, L54, L55, L56, L57, L58, L59, L60;
//L61, L62, L63, L64, L65, L66, L67, L68, L69, L70, L71, L72, L73, L74, L75, L76, L77, L78, L79, L80,
//L81, L82, L83, L84, L85, L86, L87, L88, L89, L90, L91, L92,L93, L94, L95, L96, L97, L98, L99, L100;

static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

byte Ethernet::buffer[700];
static uint32_t timer;

// called when a ping comes in (replies to it are automatic)
static void gotPinged (byte* ptr) {
  ether.printIp(">>> ping from: ", ptr);
}

int admin = 0, pass = 0, kody = 0, automat = 0, ping = 0, hostwww=0, firstping=1;
int connection = 0; 
int incomingByte = 0;
int znak = 0;
int first = 0;
int cap = 0;
String RTT = "x";
String wykonaj = "x";
int ile = 0;
int program = 0, baza = 0;
int RTN=0;
int liczba2=0;
int a, b, F =0;
int dioda, jak = 2, Reset = 7;;
int interwal = 0, jaki = 20;
const char* c;
char ipStg[20];
byte getIP_address[IP_LEN];
String adres;
const char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
  "<head><title>"
    "Arduino"
  "</title></head>"
  "<body background='"
  "https://kriss.waw.pl/Grafiki/background-2462436_1920.jpg"
  "'>"
  "</body>"
  "<div style='"
  "margin-top:200px; height: 200px;width: 80%; background-color: rgb(56,56,56);margin-left: auto;margin-right: auto;border-radius: 10px;"
  "'>"
  "<center><a style='color: white;font-size: 50px;'><br>Strona hostowana na arduino Mega 2560 :)</a> </center>"
  "</div>"
"</html>"
;

//----mysql-------
String host, login, haslo;
//----------------

//int chipSelect = 4;

//------ZMIENNE LICZBOWE DO DYSPOZYCJI U»YTKOWNIKA------

String nazwa1 = "x", nazwa2 = "x", nazwa3 = "x", nazwa4 = "x", nazwa5 = "x";
   int zmien1, zmien2, zmien3, zmien4, zmien5;

//------------------------------------------------------


void setvar(String nazwa, int ilosc)
{

        if(nazwa == nazwa1){zmien1 = ilosc;}
   else if(nazwa == nazwa2){zmien2 = ilosc;}
   else if(nazwa == nazwa3){zmien3 = ilosc;}
   else if(nazwa == nazwa4){zmien4 = ilosc;}
   else if(nazwa == nazwa5){zmien5 = ilosc;}
   else 
   {
          if(nazwa1=="x") {nazwa1=nazwa; zmien1=ilosc;}
     else if(nazwa2=="x") {nazwa2=nazwa; zmien2=ilosc;}
     else if(nazwa3=="x") {nazwa3=nazwa; zmien3=ilosc;}
     else if(nazwa4=="x") {nazwa4=nazwa; zmien4=ilosc;}
     else if(nazwa5=="x") {nazwa5=nazwa; zmien5=ilosc;}
   }
}

int getvar(String nazwa)
{
        if(nazwa == nazwa1){return zmien1;}
   else if(nazwa == nazwa2){return zmien2;}
   else if(nazwa == nazwa3){return zmien3;}
   else if(nazwa == nazwa4){return zmien4;}
   else if(nazwa == nazwa5){return zmien5;}
   else {}
 }

void info()
{
  

//TV.print("-----------------------------");
TV.clear_screen();
TV.println("Arduino 8-bit PC");
TV.println();
TV.println("by Krzysztof Chojka");
TV.println();
TV.println("ATmega2560 @ 16 MHz");
TV.println();
TV.println("5703 B RAM free");
TV.println();
TV.println("4096 EEPROM B total");

//-----------------------------------------------------------------------
/*if (card.init(SPI_HALF_SPEED, chipSelect)) 
{
  TV.println();
  TV.print("Card type:");
  switch (card.type()) {
    case SD_CARD_TYPE_SD1:
        TV.println("SD1");
        break;
    case SD_CARD_TYPE_SD2:
      TV.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      TV.println("SDHC");
      break;
    default:
      TV.println("Unknown");
                        } 

if (!volume.init(card)) {
    TV.println("Volume: ERROR");
  }
else{
  TV.println();
TV.print("Volume:");
uint32_t volumesize;
TV.print("FAT");
TV.print(volume.fatType(), DEC);
TV.print("  ");
volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize /= 2;
  //TV.println(volumesize);
    TV.print((float)volumesize / 1024.0 / 1024); TV.println(" GB");
}
}*/
//--------------------------------------------------------------------------

//TV.print("-----------------------------");
//delay(70000);
TV.println();
}

void setup() {
    Serial.begin(9600);

  //---------------------------------------------------

  digitalWrite(Reset, HIGH);
  delay(200); 
  pinMode(Reset, OUTPUT);     

incomingByte = 0;
znak = 0;
first = 0;
RTT = "x";
wykonaj = "x";
ile = 0;
RTN=0;
liczba2=0;
jak = 2;
interwal = 0;
jaki = 20;

//----ethercard--------
  
//---------------------
  
  //Serial.begin(9600);
//TV.begin(NTSC,120,96);
  TV.begin(NTSC,180,160);

  TV.select_font(font6x8);
pinMode(38, OUTPUT);
pinMode(40, OUTPUT);
pinMode(41, OUTPUT);
pinMode(42, OUTPUT);
pinMode(43, OUTPUT);
pinMode(44, OUTPUT);
pinMode(45, OUTPUT);
pinMode(46, OUTPUT);
pinMode(47, OUTPUT);
pinMode(48, OUTPUT);
pinMode(49, OUTPUT);
pinMode(50, OUTPUT);
pinMode(51, OUTPUT);
pinMode(52, OUTPUT);
pinMode(53, OUTPUT);

for(int i=0; i < 29; i++)
{
  delay(1500);
  TV.print("-");
}

info();

TV.println("OK");
TV.println();
TV.print(">");

}

void line(int gdzie, String znaki)
{ 
     if(gdzie==1)    {L1 = znaki;}
else if(gdzie==2)    {L2 = znaki;}
else if(gdzie==3)    {L3 = znaki;}
else if(gdzie==4)    {L4 = znaki;}
else if(gdzie==5)    {L5 = znaki;}
else if(gdzie==6)    {L6 = znaki;}
else if(gdzie==7)    {L7 = znaki;}
else if(gdzie==8)    {L8 = znaki;}
else if(gdzie==9)    {L9 = znaki;}
else if(gdzie==10)   {L10 = znaki;}
else if(gdzie==11)   {L11 = znaki;}
else if(gdzie==12)   {L12 = znaki;}
else if(gdzie==13)   {L13 = znaki;}
else if(gdzie==14)   {L14 = znaki;}
else if(gdzie==15)   {L15 = znaki;}
else if(gdzie==16)   {L16 = znaki;}
else if(gdzie==17)   {L17 = znaki;}
else if(gdzie==18)   {L18 = znaki;}
else if(gdzie==19)   {L19 = znaki;}
else if(gdzie==20)   {L20 = znaki;}
else if(gdzie==21)   {L21 = znaki;}
else if(gdzie==22)   {L22 = znaki;}
else if(gdzie==23)   {L23 = znaki;}
else if(gdzie==24)   {L24 = znaki;}
else if(gdzie==25)   {L25 = znaki;}
else if(gdzie==26)   {L26 = znaki;}
else if(gdzie==27)   {L27 = znaki;}
else if(gdzie==28)   {L28 = znaki;}
else if(gdzie==29)   {L29 = znaki;}
else if(gdzie==30)   {L30 = znaki;}
else if(gdzie==31)   {L31 = znaki;}
else if(gdzie==32)   {L32 = znaki;}
else if(gdzie==33)   {L33 = znaki;}
else if(gdzie==34)   {L34 = znaki;}
else if(gdzie==35)   {L35 = znaki;}
else if(gdzie==36)   {L36 = znaki;}
else if(gdzie==37)   {L37 = znaki;}
else if(gdzie==38)   {L38 = znaki;}
else if(gdzie==39)   {L39 = znaki;}
else if(gdzie==40)   {L40 = znaki;}
else if(gdzie==41)   {L41 = znaki;}
else if(gdzie==42)   {L42 = znaki;}
else if(gdzie==43)   {L43 = znaki;}
else if(gdzie==44)   {L44 = znaki;}
else if(gdzie==45)   {L45 = znaki;}
else if(gdzie==46)   {L46 = znaki;}
else if(gdzie==47)   {L47 = znaki;}
else if(gdzie==48)   {L48 = znaki;}
else if(gdzie==49)   {L49 = znaki;}
else if(gdzie==50)   {L50 = znaki;}
else if(gdzie==51)   {L51 = znaki;}
else if(gdzie==52)   {L52 = znaki;}
else if(gdzie==53)   {L53 = znaki;}
else if(gdzie==54)   {L54 = znaki;}
else if(gdzie==55)   {L55 = znaki;}
else if(gdzie==56)   {L56 = znaki;}
else if(gdzie==57)   {L57 = znaki;}
else if(gdzie==58)   {L58 = znaki;}
else if(gdzie==59)   {L59 = znaki;}
else if(gdzie==60)   {L60 = znaki;}
/*else if(gdzie==61)   {L61 = znaki;}
else if(gdzie==62)   {L62 = znaki;}
else if(gdzie==63)   {L63 = znaki;}
else if(gdzie==64)   {L64 = znaki;}
else if(gdzie==65)   {L65 = znaki;}
else if(gdzie==66)   {L66 = znaki;}
else if(gdzie==67)   {L67 = znaki;}
else if(gdzie==68)   {L68 = znaki;}
else if(gdzie==69)   {L69 = znaki;}
else if(gdzie==70)   {L70 = znaki;}
else if(gdzie==71)   {L71 = znaki;}
else if(gdzie==72)   {L72 = znaki;}
else if(gdzie==73)   {L73 = znaki;}
else if(gdzie==74)   {L74 = znaki;}
else if(gdzie==75)   {L75 = znaki;}
else if(gdzie==76)   {L76 = znaki;}
else if(gdzie==77)   {L77 = znaki;}
else if(gdzie==78)   {L78 = znaki;}
else if(gdzie==79)   {L79 = znaki;}
else if(gdzie==80)   {L80 = znaki;}
else if(gdzie==81)   {L81 = znaki;}
else if(gdzie==82)   {L82 = znaki;}
else if(gdzie==83)   {L83 = znaki;}
else if(gdzie==84)   {L84 = znaki;}
else if(gdzie==85)   {L85 = znaki;}
else if(gdzie==86)   {L86 = znaki;}
else if(gdzie==87)   {L87 = znaki;}
else if(gdzie==88)   {L88 = znaki;}
else if(gdzie==89)   {L89 = znaki;}
else if(gdzie==90)   {L90 = znaki;}
else if(gdzie==91)   {L91 = znaki;}
else if(gdzie==92)   {L92 = znaki;}
else if(gdzie==93)   {L93 = znaki;}
else if(gdzie==94)   {L94 = znaki;}
else if(gdzie==95)   {L95 = znaki;}
else if(gdzie==96)   {L96 = znaki;}
else if(gdzie==97)   {L97 = znaki;}
else if(gdzie==98)   {L98 = znaki;}
else if(gdzie==99)   {L99 = znaki;}
else if(gdzie==100)  {L100 = znaki;}*/
}

void uruchom()
{
       if(program==1){  if( L1 != NULL){wykonaj ="x" + L1; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==2){  if( L2 != NULL){wykonaj ="x" + L2; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==3){  if( L3 != NULL){wykonaj ="x" + L3; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==4){  if( L4 != NULL){wykonaj ="x" + L4; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==5){  if( L5 != NULL){wykonaj ="x" + L5; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==6){  if( L6 != NULL){wykonaj ="x" + L6; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==7){  if( L7 != NULL){wykonaj ="x" + L7; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==8){  if( L8 != NULL){wykonaj ="x" + L8; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==9){  if( L9 != NULL){wykonaj ="x" + L9; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==10){  if( L10 != NULL){wykonaj ="x" + L10; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==11){  if( L11 != NULL){wykonaj ="x" + L11; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==12){  if( L12 != NULL){wykonaj ="x" + L12; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==13){  if( L13 != NULL){wykonaj ="x" + L13; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==14){  if( L14 != NULL){wykonaj ="x" + L14; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==15){  if( L15 != NULL){wykonaj ="x" + L15; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==16){  if( L16 != NULL){wykonaj ="x" + L16; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==17){  if( L17 != NULL){wykonaj ="x" + L17; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==18){  if( L18 != NULL){wykonaj ="x" + L18; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==19){  if( L19 != NULL){wykonaj ="x" + L19; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==20){  if( L20 != NULL){wykonaj ="x" + L20; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==21){  if( L21 != NULL){wykonaj ="x" + L21; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==22){  if( L22 != NULL){wykonaj ="x" + L22; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==23){  if( L23 != NULL){wykonaj ="x" + L23; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==24){  if( L24 != NULL){wykonaj ="x" + L24; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==25){  if( L25 != NULL){wykonaj ="x" + L25; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==26){  if( L26 != NULL){wykonaj ="x" + L26; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==27){  if( L27 != NULL){wykonaj ="x" + L27; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==28){  if( L28 != NULL){wykonaj ="x" + L28; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==29){  if( L29 != NULL){wykonaj ="x" + L29; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==30){  if( L30 != NULL){wykonaj ="x" + L30; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==31){  if( L31 != NULL){wykonaj ="x" + L31; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==32){  if( L32 != NULL){wykonaj ="x" + L32; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==33){  if( L33 != NULL){wykonaj ="x" + L33; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==34){  if( L34 != NULL){wykonaj ="x" + L34; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==35){  if( L35 != NULL){wykonaj ="x" + L35; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==36){  if( L36 != NULL){wykonaj ="x" + L36; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==37){  if( L37 != NULL){wykonaj ="x" + L37; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==38){  if( L38 != NULL){wykonaj ="x" + L38; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==39){  if( L39 != NULL){wykonaj ="x" + L39; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==40){  if( L40 != NULL){wykonaj ="x" + L40; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==41){  if( L41 != NULL){wykonaj ="x" + L41; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==42){  if( L42 != NULL){wykonaj ="x" + L42; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==43){  if( L43 != NULL){wykonaj ="x" + L43; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==44){  if( L44 != NULL){wykonaj ="x" + L44; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==45){  if( L45 != NULL){wykonaj ="x" + L45; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==46){  if( L46 != NULL){wykonaj ="x" + L46; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==47){  if( L47 != NULL){wykonaj ="x" + L47; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==48){  if( L48 != NULL){wykonaj ="x" + L48; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==49){  if( L49 != NULL){wykonaj ="x" + L49; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==50){  if( L50 != NULL){wykonaj ="x" + L50; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==51){  if( L51 != NULL){wykonaj ="x" + L51; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==52){  if( L52 != NULL){wykonaj ="x" + L52; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==53){  if( L53 != NULL){wykonaj ="x" + L53; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==54){  if( L54 != NULL){wykonaj ="x" + L54; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==55){  if( L55 != NULL){wykonaj ="x" + L55; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==56){  if( L56 != NULL){wykonaj ="x" + L56; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==57){  if( L57 != NULL){wykonaj ="x" + L57; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==58){  if( L58 != NULL){wykonaj ="x" + L58; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==59){  if( L59 != NULL){wykonaj ="x" + L59; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==60){  if( L60 != NULL){wykonaj ="x" + L60; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program >= 61){program = 0; automat = 0; TV.println(); TV.print(">");}
/*  else if(program==61){  if( L61 != NULL){wykonaj ="x" + L61; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==62){  if( L62 != NULL){wykonaj ="x" + L62; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==63){  if( L63 != NULL){wykonaj ="x" + L63; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==64){  if( L64 != NULL){wykonaj ="x" + L64; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==65){  if( L65 != NULL){wykonaj ="x" + L65; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==66){  if( L66 != NULL){wykonaj ="x" + L66; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==67){  if( L67 != NULL){wykonaj ="x" + L67; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==68){  if( L68 != NULL){wykonaj ="x" + L68; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==69){  if( L69 != NULL){wykonaj ="x" + L69; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==70){  if( L70 != NULL){wykonaj ="x" + L70; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==71){  if( L71 != NULL){wykonaj ="x" + L71; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==72){  if( L72 != NULL){wykonaj ="x" + L72; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==73){  if( L73 != NULL){wykonaj ="x" + L73; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==74){  if( L74 != NULL){wykonaj ="x" + L74; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==75){  if( L75 != NULL){wykonaj ="x" + L75; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==76){  if( L76 != NULL){wykonaj ="x" + L76; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==77){  if( L77 != NULL){wykonaj ="x" + L77; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==78){  if( L78 != NULL){wykonaj ="x" + L78; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==79){  if( L79 != NULL){wykonaj ="x" + L79; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==80){  if( L80 != NULL){wykonaj ="x" + L80; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==81){  if( L81 != NULL){wykonaj ="x" + L81; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==82){  if( L82 != NULL){wykonaj ="x" + L82; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==83){  if( L83 != NULL){wykonaj ="x" + L83; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==84){  if( L84 != NULL){wykonaj ="x" + L84; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==85){  if( L85 != NULL){wykonaj ="x" + L85; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==86){  if( L86 != NULL){wykonaj ="x" + L86; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==87){  if( L87 != NULL){wykonaj ="x" + L87; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==88){  if( L88 != NULL){wykonaj ="x" + L88; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==89){  if( L89 != NULL){wykonaj ="x" + L89; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==90){  if( L90 != NULL){wykonaj ="x" + L90; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==91){  if( L91 != NULL){wykonaj ="x" + L91; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==92){  if( L92 != NULL){wykonaj ="x" + L92; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==93){  if( L93 != NULL){wykonaj ="x" + L93; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==94){  if( L94 != NULL){wykonaj ="x" + L94; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==95){  if( L95 != NULL){wykonaj ="x" + L95; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==96){  if( L96 != NULL){wykonaj ="x" + L96; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==97){  if( L97 != NULL){wykonaj ="x" + L97; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==98){  if( L98 != NULL){wykonaj ="x" + L98; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==99){  if( L99 != NULL){wykonaj ="x" + L99; automat = 1;  program ++; }else{program++; uruchom();}}
  else if(program==100){ if( L100 != NULL){wykonaj ="x" + L100; automat = 1;  program ++; }else{program++; uruchom();}}*/
  else if(program >= 101){program = 0; automat = 0; TV.println(); TV.print(">");}
}

void list(int linia)
{

  if(linia == 1 && L1 != NULL){TV.print("1 ");     TV.println(L1.c_str());}
  if(linia == 2 && L2 != NULL){TV.print("2 ");     TV.println(L2.c_str());}
  if(linia == 3 && L3 != NULL){TV.print("3 ");     TV.println(L3.c_str());}
  if(linia == 4 && L4 != NULL){TV.print("4 ");     TV.println(L4.c_str());}
  if(linia == 5 && L5 != NULL){TV.print("5 ");     TV.println(L5.c_str());}
  if(linia == 6 && L6 != NULL){TV.print("6 ");     TV.println(L6.c_str());}
  if(linia == 7 && L7 != NULL){TV.print("7 ");     TV.println(L7.c_str());}
  if(linia == 8 && L8 != NULL){TV.print("8 ");     TV.println(L8.c_str());}
  if(linia == 9 && L9 != NULL){TV.print("9 ");     TV.println(L9.c_str());}
  if(linia == 10 && L10 != NULL){TV.print("10 ");    TV.println(L10.c_str());}
  if(linia == 11 && L11 != NULL){TV.print("11 ");    TV.println(L11.c_str());}
  if(linia == 12 && L12 != NULL){TV.print("12 ");    TV.println(L12.c_str());}
  if(linia == 13 && L13 != NULL){TV.print("13 ");    TV.println(L13.c_str());}
  if(linia == 14 && L14 != NULL){TV.print("14 ");    TV.println(L14.c_str());}
  if(linia == 15 && L15 != NULL){TV.print("15 ");    TV.println(L15.c_str());}
  if(linia == 16 && L16 != NULL){TV.print("16 ");    TV.println(L16.c_str());}
  if(linia == 17 && L17 != NULL){TV.print("17 ");    TV.println(L17.c_str());}
  if(linia == 18 && L18 != NULL){TV.print("18 ");    TV.println(L18.c_str());}
  if(linia == 19 && L19 != NULL){TV.print("19 ");    TV.println(L19.c_str());}
  if(linia == 20 && L20 != NULL){TV.print("20 ");    TV.println(L20.c_str());}
  if(linia == 21 && L21 != NULL){TV.print("21 ");    TV.println(L21.c_str());}
  if(linia == 22 && L22 != NULL){TV.print("22 ");    TV.println(L22.c_str());}
  if(linia == 23 && L23 != NULL){TV.print("23 ");    TV.println(L23.c_str());}
  if(linia == 24 && L24 != NULL){TV.print("24 ");    TV.println(L24.c_str());}
  if(linia == 25 && L25 != NULL){TV.print("25 ");    TV.println(L25.c_str());}
  if(linia == 26 && L26 != NULL){TV.print("26 ");    TV.println(L26.c_str());}
  if(linia == 27 && L27 != NULL){TV.print("27 ");    TV.println(L27.c_str());}
  if(linia == 28 && L28 != NULL){TV.print("28 ");    TV.println(L28.c_str());}
  if(linia == 29 && L29 != NULL){TV.print("29 ");    TV.println(L29.c_str());}
  if(linia == 30 && L30 != NULL){TV.print("30 ");    TV.println(L30.c_str());}
  if(linia == 31 && L31 != NULL){TV.print("31 ");    TV.println(L31.c_str());}
  if(linia == 32 && L32 != NULL){TV.print("32 ");    TV.println(L32.c_str());}
  if(linia == 33 && L33 != NULL){TV.print("33 ");    TV.println(L33.c_str());}
  if(linia == 34 && L34 != NULL){TV.print("34 ");    TV.println(L34.c_str());}
  if(linia == 35 && L35 != NULL){TV.print("35 ");    TV.println(L35.c_str());}
  if(linia == 36 && L36 != NULL){TV.print("36 ");    TV.println(L36.c_str());}
  if(linia == 37 && L37 != NULL){TV.print("37 ");    TV.println(L37.c_str());}
  if(linia == 38 && L38 != NULL){TV.print("38 ");    TV.println(L38.c_str());}
  if(linia == 39 && L39 != NULL){TV.print("39 ");    TV.println(L39.c_str());}
  if(linia == 40 && L40 != NULL){TV.print("40 ");    TV.println(L40.c_str());}
  if(linia == 41 && L41 != NULL){TV.print("41 ");    TV.println(L41.c_str());}
  if(linia == 42 && L42 != NULL){TV.print("42 ");    TV.println(L42.c_str());}
  if(linia == 43 && L43 != NULL){TV.print("43 ");    TV.println(L43.c_str());}
  if(linia == 44 && L44 != NULL){TV.print("44 ");    TV.println(L44.c_str());}
  if(linia == 45 && L45 != NULL){TV.print("45 ");    TV.println(L45.c_str());}
  if(linia == 46 && L46 != NULL){TV.print("46 ");    TV.println(L46.c_str());}
  if(linia == 47 && L47 != NULL){TV.print("47 ");    TV.println(L47.c_str());}
  if(linia == 48 && L48 != NULL){TV.print("48 ");    TV.println(L48.c_str());}
  if(linia == 49 && L49 != NULL){TV.print("49 ");    TV.println(L49.c_str());}
  if(linia == 50 && L50 != NULL){TV.print("50 ");    TV.println(L50.c_str());}
  if(linia == 51 && L51 != NULL){TV.print("51 ");    TV.println(L51.c_str());}
  if(linia == 52 && L52 != NULL){TV.print("52 ");    TV.println(L52.c_str());}
  if(linia == 53 && L53 != NULL){TV.print("53 ");    TV.println(L53.c_str());}
  if(linia == 54 && L54 != NULL){TV.print("54 ");    TV.println(L54.c_str());}
  if(linia == 55 && L55 != NULL){TV.print("55 ");    TV.println(L55.c_str());}
  if(linia == 56 && L56 != NULL){TV.print("56 ");    TV.println(L56.c_str());}
  if(linia == 57 && L57 != NULL){TV.print("57 ");    TV.println(L57.c_str());}
  if(linia == 58 && L58 != NULL){TV.print("58 ");    TV.println(L58.c_str());}
  if(linia == 59 && L59 != NULL){TV.print("59 ");    TV.println(L59.c_str());}
  if(linia == 60 && L60 != NULL){TV.print("60 ");    TV.println(L60.c_str());}
/*  if(linia == 60 && L60 != NULL){TV.print("60 ");    TV.println(L60.c_str());}
  if(linia == 61 && L61 != NULL){TV.print("61 ");    TV.println(L61.c_str());}
  if(linia == 62 && L62 != NULL){TV.print("62 ");    TV.println(L62.c_str());}
  if(linia == 63 && L63 != NULL){TV.print("63 ");    TV.println(L63.c_str());}
  if(linia == 64 && L64 != NULL){TV.print("64 ");    TV.println(L64.c_str());}
  if(linia == 65 && L65 != NULL){TV.print("65 ");    TV.println(L65.c_str());}
  if(linia == 66 && L66 != NULL){TV.print("66 ");    TV.println(L66.c_str());}
  if(linia == 67 && L67 != NULL){TV.print("67 ");    TV.println(L67.c_str());}
  if(linia == 68 && L68 != NULL){TV.print("68 ");    TV.println(L68.c_str());}
  if(linia == 69 && L69 != NULL){TV.print("69 ");    TV.println(L69.c_str());}
  if(linia == 70 && L70 != NULL){TV.print("70 ");    TV.println(L70.c_str());}
  if(linia == 71 && L71 != NULL){TV.print("71 ");    TV.println(L71.c_str());}
  if(linia == 72 && L72 != NULL){TV.print("72 ");    TV.println(L72.c_str());}
  if(linia == 73 && L73 != NULL){TV.print("73 ");    TV.println(L73.c_str());}
  if(linia == 74 && L74 != NULL){TV.print("74 ");    TV.println(L74.c_str());}
  if(linia == 75 && L75 != NULL){TV.print("75 ");    TV.println(L75.c_str());}
  if(linia == 76 && L76 != NULL){TV.print("76 ");    TV.println(L76.c_str());}
  if(linia == 77 && L77 != NULL){TV.print("77 ");    TV.println(L77.c_str());}
  if(linia == 78 && L78 != NULL){TV.print("78 ");    TV.println(L78.c_str());}
  if(linia == 79 && L79 != NULL){TV.print("79 ");    TV.println(L79.c_str());}
  if(linia == 80 && L80 != NULL){TV.print("80 ");    TV.println(L80.c_str());}
  if(linia == 81 && L81 != NULL){TV.print("81 ");    TV.println(L81.c_str());}
  if(linia == 82 && L82 != NULL){TV.print("82 ");    TV.println(L82.c_str());}
  if(linia == 83 && L83 != NULL){TV.print("83 ");    TV.println(L83.c_str());}
  if(linia == 84 && L84 != NULL){TV.print("84 ");    TV.println(L84.c_str());}
  if(linia == 85 && L85 != NULL){TV.print("85 ");    TV.println(L85.c_str());}
  if(linia == 86 && L86 != NULL){TV.print("86 ");    TV.println(L86.c_str());}
  if(linia == 87 && L87 != NULL){TV.print("87 ");    TV.println(L87.c_str());}
  if(linia == 88 && L88 != NULL){TV.print("88 ");    TV.println(L88.c_str());}
  if(linia == 89 && L98 != NULL){TV.print("89 ");    TV.println(L89.c_str());}
  if(linia == 90 && L90 != NULL){TV.print("90 ");    TV.println(L90.c_str());}
  if(linia == 91 && L91 != NULL){TV.print("91 ");    TV.println(L91.c_str());}
  if(linia == 92 && L92 != NULL){TV.print("92 ");    TV.println(L92.c_str());}
  if(linia == 93 && L93 != NULL){TV.print("93 ");    TV.println(L93.c_str());}
  if(linia == 94 && L94 != NULL){TV.print("94 ");    TV.println(L94.c_str());}
  if(linia == 95 && L95 != NULL){TV.print("95 ");    TV.println(L95.c_str());}
  if(linia == 96 && L96 != NULL){TV.print("96 ");    TV.println(L96.c_str());}
  if(linia == 97 && L97 != NULL){TV.print("97 ");    TV.println(L97.c_str());}
  if(linia == 98 && L98 != NULL){TV.print("98 ");    TV.println(L98.c_str());}
  if(linia == 99 && L99 != NULL){TV.print("99 ");    TV.println(L99.c_str());}
  if(linia == 100 && L100 != NULL){TV.print("100 ");    TV.println(L100.c_str());}*/
          
}

String zmienne()
{
    String nazwa="", znak="";
int x=1, a=0, TN=0;

for(;c[x] != '=';x++)
  {if(c[x]==NULL){return "ERROR";} nazwa = nazwa + c[x];}
  
int a1=NULL, a2=NULL;
String arg1="", arg2="";
int do_ktorego=1;
x++;
for(;c[x] > NULL; x++)
{
  if(c[x] == '0' || c[x] == '1' || c[x] == '2' || c[x] == '3' || c[x] == '4' || c[x] == '5' || c[x] == '6' || c[x] == '7' || c[x] == '8' || c[x] == '9') 
     {
        if(do_ktorego==1)
        {
          String wart;
         wart = c[x];
        TN = TN + atoi(wart.c_str());
  
          if(a1==NULL)
          {a1=TN;}
          else if(a1<10)
          {a1=a1*10; a1=a1+TN;}
          else if(a1<100)
          {a1=a1*10; a1=a1+TN;}
          else if(a1<1000)
          {a1=a1*10; a1=a1+TN;}
          else if(a1<10000)
          {a1=a1*10; a1=a1+TN;}

          TN = 0;
        }
        else
        {
          String wart;
         wart = c[x];
        TN = TN + atoi(wart.c_str());
  
          if(a2==NULL)
          {a2=TN;}
          else if(a2<10)
          {a2=a2*10; a2=a2+TN;}
          else if(a2<100)
          {a2=a2*10; a2=a2+TN;}
          else if(a2<1000)
          {a2=a2*10; a2=a2+TN;}
          else if(a2<10000)
          {a2=a2*10; a2=a2+TN;}

          TN = NULL;
        }
     }
    else if(c[x] == '+' || c[x] == '-' || c[x] == '*' || c[x] == '/')
    {
           if(c[x]=='+'){znak="+";}
      else if(c[x]=='-'){znak="-";}
      else if(c[x]=='*'){znak="*";}
      else if(c[x]=='/'){znak="/";}
      do_ktorego=2;
    }
    else
    {
           if(do_ktorego==1){arg1=arg1+c[x];}
      else if(do_ktorego==2){arg2=arg2+c[x];}
    }
}

if(arg1 == "" && a1 == NULL){return "ERROR";}
  
  if(a2 == NULL && arg2 == "")
  {
    if(a1>NULL)
    {
      
      setvar(nazwa, a1);
    }
    else
    {
      Serial.print(nazwa);
      Serial.print(" <- nazwa | wartosc -> ");
      Serial.print(arg1);
      int qwerty = getvar(arg1);
      setvar(nazwa, qwerty);
    }
  }
  else if(a2 > NULL || arg2 != "")
  {
    if(a2 > NULL) //ARGUMENT DRUGI TO LICZBA
    {
           if(a1 > NULL)  
           {
            //DWA ARGUMENTY LICZBOWE x=1+1

                   if(znak == "+"){setvar(nazwa, a1+a2);}
              else if(znak == "-"){setvar(nazwa, a1-a2);}
              else if(znak == "*"){setvar(nazwa, a1*a2);}
              else if(znak == "/"){setvar(nazwa, (float)a1/(float)a2);}
            }
            else if(arg1 != "")
            {
              //x=x+1
              int argvar = getvar(arg1);

                   if(znak == "+"){setvar(nazwa, argvar+a2);}
              else if(znak == "-"){setvar(nazwa, argvar-a2);}
              else if(znak == "*"){setvar(nazwa, argvar*a2);}
              else if(znak == "/"){setvar(nazwa, (float)argvar/(float)a2);}
            }
    }
    else  if(arg2 != "") //ARGUMENT DRUGI TO ZMIENNA
    {
          if(a1 > NULL)  
           {
            //x=1+x
            int argvar2 = getvar(arg2);
                   if(znak == "+"){setvar(nazwa, a1+argvar2);}
              else if(znak == "-"){setvar(nazwa, a1-argvar2);}
              else if(znak == "*"){setvar(nazwa, a1*argvar2);}
              else if(znak == "/"){setvar(nazwa, (float)a1/(float)argvar2);}
            }
            else if(arg1 != "")
            {
              //x=x+x
              int argvar = getvar(arg1);
              int argvar2 = getvar(arg2);

                   if(znak == "+"){setvar(nazwa, argvar+argvar2);}
              else if(znak == "-"){setvar(nazwa, argvar-argvar2);}
              else if(znak == "*"){setvar(nazwa, argvar*argvar2);}
              else if(znak == "/"){setvar(nazwa, (float)argvar/(float)argvar2);}
            }
    }
  }
  
 if(automat == 0) {TV.println(); TV.println(); TV.print(">");} else {} 
return "OK";
}

void klawiatura()
{
  incomingByte = Serial.read();
  if(incomingByte == -1)
  {}
  else if(kody == 1)
  {
    Serial.print(incomingByte);
  }
  else
  {}
  
  if(incomingByte == -1)
  {
    //Nic nie rA3b
    first = 0;
  }
  else if(first > 0)
  {
//----------49xx-----------------------------
    if(first == 49)
    {
      if(incomingByte == 49) //ESC i F6
      { TV.clear_screen(); wykonaj = "x"; RTT = "x"; first = 0; TV.print(">");}
      else if(incomingByte == 56) //cap
      { 
        if(cap == 0)
        {first = 0; cap = 1; digitalWrite(38, HIGH);}
        else if(cap == 1)
        {first = 0; cap = 0; digitalWrite(38, LOW);}
      }
      else if(incomingByte == 55) //L-ALT
      { 
        automat = 0;
        program = 0;
        if(ping>0){TV.println();TV.print(">"); adres="";}
        ping = 0;
      }
    }
//-------------------------------------------
//----------50xx-----------------------------
    if(first == 50)
    {
      if(incomingByte == 56)
      { if(pass == 0){TV.print("A");}else{TV.print("*");} RTT = RTT+"A"; first = 0;}
     else if(incomingByte == 55)
      { if(pass == 0){TV.print("S");}else{TV.print("*");} RTT = RTT+"S"; first = 0;}
      else if(incomingByte == 57)
      { if(pass == 0){TV.print("W");}else{TV.print("*");} RTT = RTT+"W"; first = 0;}
      else if(incomingByte == 54)
      { if(pass == 0){TV.print("Z");}else{TV.print("*");} RTT = RTT+"Z"; first = 0;}
      else if(incomingByte == 50 && cap == 1)
      { if(pass == 0){TV.print("!");}else{TV.print("*");} RTT = RTT+"!"; first = 0; cap = 0; digitalWrite(38,  LOW);}
      else if(incomingByte == 50)
      { if(pass == 0){TV.print("1");}else{TV.print("*");} RTN = 1; first = 0; 
      if(a==0)
          {a=RTN;}
          else if(a<10)
          {a=a*10; a=a+RTN;}
          else if(b<100)
          {a=a*10; a=a+RTN;}
          else if(a<1000)
          {a=a*10; a=a+RTN;}
          else if(a<10000)
          {a=a*10; a=a+RTN;}

          RTT = RTT + RTN;
      }
      else if(incomingByte == 49)
      { if(pass == 0){TV.print("Q");}else{TV.print("*");} RTT = RTT+"Q"; first = 0;}
    }
//-------------------------------------------
//----------53xx-----------------------------
    if(first == 53)
    {
      if(incomingByte == 48)
      { if(pass == 0){TV.print("B");}else{TV.print("*");} RTT = RTT+"B"; first = 0;}
     else if(incomingByte == 50)
     { if(pass == 0){TV.print("G");}else{TV.print("*");} RTT = RTT+"G"; first = 0;}
      else if(incomingByte == 49)
      { if(pass == 0){TV.print("H");}else{TV.print("*");} RTT = RTT+"H"; first = 0;}
      else if(incomingByte == 57)
     { if(pass == 0){TV.print("J");}else{TV.print("*");} RTT = RTT+"J"; first = 0;}
      else if(incomingByte == 56)
      { if(pass == 0){TV.print("M");}else{TV.print("*");} RTT = RTT+"M"; first = 0;}
      else if(incomingByte == 52 && cap == 1)
      { if(pass == 0){TV.print("^");}else{TV.print("*");} RTT = RTT+"^"; first = 0; cap = 0; digitalWrite(38,  LOW);}
      else if(incomingByte == 52)
      { if(pass == 0){TV.print("6");}else{TV.print("*");} RTN = 6; first = 0;
         
          if(a==0)
          {a=RTN;}
          else if(a<10)
          {a=a*10; a=a+RTN;}
          else if(b<100)
          {a=a*10; a=a+RTN;}
          else if(a<1000)
          {a=a*10; a=a+RTN;}
          else if(a<10000)
          {a=a*10; a=a+RTN;}
          
          RTT = RTT + RTN;
      }
      else if(incomingByte == 51)
      { if(pass == 0){TV.print("Y");}else{TV.print("*");} RTT = RTT+"Y"; first = 0;}
    }
//-------------------------------------------
//----------51xx-----------------------------
    if(first == 51)
    {
      if(incomingByte == 51)
      { if(pass == 0){TV.print("C");}else{TV.print("*");} RTT = RTT+"C"; first = 0;}
     else if(incomingByte == 53)
     { if(pass == 0){TV.print("D");}else{TV.print("*");} RTT = RTT+"D"; first = 0;}
      else if(incomingByte == 54)
      { if(pass == 0){TV.print("E");}else{TV.print("*");} RTT = RTT+"E"; first = 0;}
      else if(incomingByte == 52)
      { if(pass == 0){TV.print("X");}else{TV.print("*");} RTT = RTT+"X"; first = 0;}
      else if(incomingByte == 48 && cap == 1)
      { if(pass == 0){TV.print("@");}else{TV.print("*");} RTT = RTT+"@"; first = 0; cap = 0; digitalWrite(38,  LOW);}
      else if(incomingByte == 48)
      { if(pass == 0){TV.print("2");}else{TV.print("*");} RTN = 2; first = 0;
      if(a==0)
          {a=RTN;}
          else if(a<10)
          {a=a*10; a=a+RTN;}
          else if(b<100)
          {a=a*10; a=a+RTN;}
          else if(a<1000)
          {a=a*10; a=a+RTN;}
          else if(a<10000)
          {a=a*10; a=a+RTN;}

          RTT = RTT + RTN;
      }

      else if(incomingByte == 56 && cap == 1)
      { if(pass == 0){TV.print("#");}else{TV.print("*");} RTT = RTT+"#"; first = 0; cap = 0; digitalWrite(38,  LOW);}
      else if(incomingByte == 56)
      { if(pass == 0){TV.print("3");}else{TV.print("*");} RTN = 3; first = 0;
      if(a==0)
          {a=RTN;}
          else if(a<10)
          {a=a*10; a=a+RTN;}
          else if(b<100)
          {a=a*10; a=a+RTN;}
          else if(a<1000)
          {a=a*10; a=a+RTN;}
          else if(a<10000)
          {a=a*10; a=a+RTN;}

          RTT = RTT + RTN;
      }
      else if(incomingByte == 55 && cap == 1)
      { TV.print("$"); RTT = RTT+"$"; first = 0; cap = 0; digitalWrite(38,  LOW);}
      else if(incomingByte == 55)
      { if(pass == 0){TV.print("4");}else{TV.print("*");} RTN = 4; first = 0;
      if(a==0)
          {a=RTN;}
          else if(a<10)
          {a=a*10; a=a+RTN;}
          else if(b<100)
          {a=a*10; a=a+RTN;}
          else if(a<1000)
          {a=a*10; a=a+RTN;}
          else if(a<10000)
          {a=a*10; a=a+RTN;}

          RTT = RTT + RTN;
      }
    }
//-------------------------------------------
//----------52xx-----------------------------
    if(first == 52)
    {
      if(incomingByte == 51)
      { if(pass == 0){TV.print("F");}else{TV.print("*");} RTT = RTT+"F"; first = 0;}
     else if(incomingByte == 57)
      { if(pass == 0){TV.print("N");}else{TV.print("*");} RTT = RTT+"N"; first = 0;}
      else if(incomingByte == 53)
      { if(pass == 0){TV.print("R");}else{TV.print("*");} RTT = RTT+"R"; first = 0;}
      else if(incomingByte == 52)
      { if(pass == 0){TV.print("T");}else{TV.print("*");} RTT = RTT+"T"; first = 0;}
      else if(incomingByte == 49)
      { if(pass == 0){TV.print(" ");}else{TV.print("*");} RTT = RTT+" "; first = 0;}
      else if(incomingByte == 54 && cap == 1)
      { if(pass == 0){TV.print("%");}else{TV.print("*");} RTT = RTT+"%"; first = 0; cap = 0; digitalWrite(38,  LOW);}
      else if(incomingByte == 54)
      { if(pass == 0){TV.print("5");}else{TV.print("*");} RTN = 5; first = 0;
      if(a==0)
          {a=RTN;}
          else if(a<10)
          {a=a*10; a=a+RTN;}
          else if(b<100)
          {a=a*10; a=a+RTN;}
          else if(a<1000)
          {a=a*10; a=a+RTN;}
          else if(a<10000)
          {a=a*10; a=a+RTN;}

          RTT = RTT + RTN;
      }
      else if(incomingByte == 50)
      { if(pass == 0){TV.print("V");}else{TV.print("*");} RTT = RTT+"V"; first = 0;}
    }
//-------------------------------------------
//----------54xx-----------------------------
    if(first == 54)
    {
      if(incomingByte == 55)
      { if(pass == 0){TV.print("I");}else{TV.print("*");} RTT = RTT+"I"; first = 0;}
     else if(incomingByte == 54)
      { if(pass == 0){TV.print("K");}else{TV.print("*");} RTT = RTT+"K"; first = 0;}
      else if(incomingByte == 56)
      { if(pass == 0){TV.print("O");}else{TV.print("*");} RTT = RTT+"O"; first = 0;}
      else if(incomingByte == 48)
     { if(pass == 0){TV.print("U");}else{TV.print("*");} RTT = RTT+"U"; first = 0;}
      else if(incomingByte == 57 && cap == 1)
      { if(pass == 0){TV.print(")");}else{TV.print("*");} RTT = RTT+")"; first = 0; cap = 0; digitalWrite(38,  LOW);}
      else if(incomingByte == 57)
      { if(pass == 0){TV.print("0");}else{TV.print("*");} RTN = 0; first = 0;
      if(a==0)
          {a=RTN;}
          else if(a<10)
          {a=a*10; a=a+RTN;}
          else if(b<100)
          {a=a*10; a=a+RTN;}
          else if(a<1000)
          {a=a*10; a=a+RTN;}
          else if(a<10000)
          {a=a*10; a=a+RTN;}

          RTT = RTT + RTN;
      }
      else if(incomingByte == 49 && cap == 1)
      { if(pass == 0){TV.print("&");}else{TV.print("*");} RTT = RTT+"&"; first = 0; cap = 0; digitalWrite(38,  LOW);}
      else if(incomingByte == 49)
      { if(pass == 0){TV.print("7");}else{TV.print("*");} RTN = 7; first = 0;
      if(a==0)
          {a=RTN;}
          else if(a<10)
          {a=a*10; a=a+RTN;}
          else if(b<100)
          {a=a*10; a=a+RTN;}
          else if(a<1000)
          {a=a*10; a=a+RTN;}
          else if(a<10000)
          {a=a*10; a=a+RTN;}

          RTT = RTT + RTN;
      }
      else if(incomingByte == 50 && cap == 1)
      { if(pass == 0){TV.print("*");}else{TV.print("*");} RTT = RTT+"*"; first = 0; cap = 0; digitalWrite(38,  LOW);}
      else if(incomingByte == 50)
      { if(pass == 0){TV.print("8");}else{TV.print("*");} RTN = 8; first = 0;
      if(a==0)
          {a=RTN;}
          else if(a<10)
          {a=a*10; a=a+RTN;}
          else if(b<100)
          {a=a*10; a=a+RTN;}
          else if(a<1000)
          {a=a*10; a=a+RTN;}
          else if(a<10000)
          {a=a*10; a=a+RTN;}

          RTT = RTT + RTN;
      }
      else if(incomingByte == 53 && cap == 0)
      { if(pass == 0){TV.print(",");}else{TV.print("*");} RTT = RTT+","; first = 0;}
      else if(incomingByte == 53 && cap == 1)
      { if(pass == 0){TV.print("<");}else{TV.print("*");} RTT = RTT+"<"; first = 0; cap = 0; digitalWrite(38,  LOW);}
    }
//-------------------------------------------
//----------55xx-----------------------------
      if(first == 55)
    {
      if(incomingByte == 52 && cap == 1)
      { if(pass == 0){TV.print("?");}else{TV.print("*");} RTT = RTT+"?"; first = 0; cap = 0; digitalWrite(38,  LOW);}
      else if(incomingByte == 52)
     { if(pass == 0){TV.print("/");}else{TV.print("*");} RTT = RTT+"/"; first = 0;}
     else if(incomingByte == 56 && cap == 1)
      { if(pass == 0){TV.print("_");}else{TV.print("*");} RTT = RTT+"_"; first = 0; cap = 0; digitalWrite(38,  LOW);}
      else if(incomingByte == 56)
     { if(pass == 0){TV.print("-");}else{TV.print("*");} RTT = RTT+"-"; first = 0;}
     else if(incomingByte == 53)
      { if(pass == 0){TV.print("L");}else{TV.print("*");} RTT = RTT+"L"; first = 0;}
      else if(incomingByte == 54 && cap == 1)
      { if(pass == 0){TV.print(":");}else{TV.print("*");} RTT = RTT+":"; first = 0; cap = 0; digitalWrite(38,  LOW);}
      else if(incomingByte == 54)
      { if(pass == 0){TV.print(";");}else{TV.print("*");} RTT = RTT+";"; first = 0;}
      else if(incomingByte == 55)
     { if(pass == 0){TV.print("P");}else{TV.print("*");} RTT = RTT+"P"; first = 0;}
      else if(incomingByte == 51 && cap == 0)
      { if(pass == 0){TV.print(".");}else{TV.print("*");} RTT = RTT+"."; first = 0;}
      else if(incomingByte == 51 && cap == 1)
      { if(pass == 0){TV.print(">");}else{TV.print("*");} RTT = RTT+">"; first = 0; cap = 0; digitalWrite(38,  LOW);}
      else if(incomingByte == 48 && cap == 1)
      { if(pass == 0){TV.print("(");}else{TV.print("*");} RTT = RTT+"("; first = 0; cap = 0; digitalWrite(38,  LOW);}
      else if(incomingByte == 48)
      { if(pass == 0){TV.print("9");}else{TV.print("*");} RTN = 9; first = 0;
      if(a==0)
          {a=RTN;}
          else if(a<10)
          {a=a*10; a=a+RTN;}
          else if(b<100)
          {a=a*10; a=a+RTN;}
          else if(a<1000)
          {a=a*10; a=a+RTN;}
          else if(a<10000)
          {a=a*10; a=a+RTN;}

          RTT = RTT + RTN;
      }
    }
//-------------------------------------------
//----------56xx-----------------------------
      if(first == 56)
    {
      if(incomingByte == 52)
      { if(pass == 0){TV.print("[");}else{TV.print("*");} RTT = RTT+"["; first = 0;}
      else if(incomingByte == 56) //cap
      { 
        if(cap == 0)
        {first = 0; cap = 1; digitalWrite(38, HIGH);}
        else if(cap == 1)
        {first = 0; cap = 0; digitalWrite(38, LOW);}
      }
      else if(incomingByte == 50 && cap == 1)
      { if(pass == 0){TV.print('"');}else{TV.print("*");} RTT = RTT+'"'; first = 0; cap = 0; digitalWrite(38,  LOW);}
      else if(incomingByte == 50)
      { if(pass == 0){TV.print("'");}else{TV.print("*");} RTT = RTT+"'"; first = 0;}
      else if(incomingByte == 53 && cap == 1)
      { if(pass == 0){TV.print("+");}else{TV.print("*");} RTT = RTT+"+"; first = 0; cap = 0; digitalWrite(38,  LOW);}
      else if(incomingByte == 53)
      { if(pass == 0){TV.print("=");}else{TV.print("*");} RTT = RTT+"="; first = 0;}
    }
//-------------------------------------------
//----------57xx-----------------------------
      if(first == 57)
    {
      if(incomingByte == 49)
      { if(pass == 0){TV.print("]");}else{TV.print("*");} first = 0;}
      else if(incomingByte == 48) //enter
      {       
    liczba2 = RTN; RTN = 0;
   wykonaj = RTT; RTT = "x";  first = 0; //Serial.print(wykonaj);
   liczba2=a; a=0;
    //----------//
  //std::string str = "std::string to const char*";
  c = wykonaj.c_str();

  //std::cout << c;
    //----------//
   
     }
    }
//-------------------------------------------
  }
  else if(first == 0)
  {
    first = incomingByte;
  }
  else
  {
   TV.print(incomingByte);
    Serial.print(incomingByte);
  }
}

void konsolamysql()
{
  klawiatura();
   
  if(baza==1)//wybranie hosta
  {
    if(wykonaj=="x"||wykonaj=="")
      {}
      else
      {
        String pytanie;
        for(int x=1;c[x] > NULL;x++)
          {
            pytanie = pytanie + c[x];
          }
        
        host = pytanie;
        wykonaj = "x";
        if(automat == 0) {TV.println(); TV.println(); TV.print("Login:");} else {TV.println();TV.print(">");} 
        baza = 2;
      }
  }
  else if(baza==2)//login
  {
    if(wykonaj=="x"||wykonaj=="")
      {}
      else
      {
        String pytanie;
        for(int x=1;c[x] > NULL;x++)
          {
            pytanie = pytanie + c[x];
          }
        
        login = pytanie;
        wykonaj = "x";
        if(automat == 0) {TV.println(); TV.println(); TV.print("Haslo:");} else {TV.println();TV.print(">");} 
        baza = 3;
      }
  }
  else if(baza==3)//haslo
  {
    pass=1;
    if(wykonaj=="x"||wykonaj=="")
      {}
      else
      {
        String pytanie;
        for(int x=1;c[x] > NULL;x++)
          {
            pytanie = pytanie + c[x];
          }
        
        haslo = pytanie;
        wykonaj = "x";
        if(automat == 0) {TV.println(); TV.println(); TV.print("MySQL>");} else {TV.println();TV.print("MySQL>");} 
        baza = 4;
        pass=0;
      }
  }
  else if(baza==4)//konsola
  {
      if(wykonaj == "xEXIT" || wykonaj == "EXIT" || wykonaj == "xQUIT" || wykonaj == "QUIT")
      { 
        wykonaj = "x";  
        baza = 0;
        if(automat == 0) {TV.println(); TV.println("Bye"); TV.println(); TV.print(">");} else {TV.println("Bye");TV.print(">");} 
      }
      else if(wykonaj=="x"||wykonaj=="")
      {}
      else
      {
        wykonaj = "x";
        if(automat == 0) {TV.println(); TV.println(); TV.print("MySQL>");} else {TV.println();TV.print(">");} 
      }

  }
  
}

void loop() 
{
 delay(500);

 if(program > 0)
 {uruchom();}
 else if(baza > 0)
 {
  konsolamysql();
  return(0);
 }
 else if(ping == 1)
 {
       klawiatura();
    word len = ether.packetReceive(); // go receive new packets
  word pos = ether.packetLoop(len); // respond to incoming pings

  // report whenever a reply to our outgoing ping comes back
  if (len > 0 && ether.packetLoopIcmpCheckReply(ether.hisip)) {
    TV.print("  ");
    TV.print((micros() - timer) * 0.001, 3);
    TV.println(" ms"); //TV.println();
    TV.print("Pinging: "); TV.println(adres.c_str());
  }

  // ping a remote server once every few seconds
  if (micros() - timer >= 5000000) {
   // ether.printIp("Pinging: ", ether.hisip);
    
    
    timer = micros();
    ether.clientIcmpRequest(ether.hisip);
//    ileping++;
  }
 }
 else if(hostwww==1)
 {
    // wait for an incoming TCP packet, but ignore its contents
  if (ether.packetLoop(ether.packetReceive())) {
    memcpy_P(ether.tcpOffset(), page, sizeof page);
    ether.httpServerReply(sizeof page - 1);
  } 
 }

if(jak == 1 && interwal == jaki)
{
    digitalWrite(dioda, LOW);
    jak = 0;
    interwal = 0;
    
}
else if(jak == 0 && interwal == jaki)
{
  digitalWrite(dioda, HIGH);
  jak = 1;
  interwal = 0;
  
}
else
{
  interwal = interwal + 1;
}
  //Serial.print(interwal);
  
klawiatura();


if(wykonaj == "xTEST" || wykonaj == "TEST")
{ 
  wykonaj = "x";  
  if(automat == 0) {TV.println(); TV.println(); TV.println(" IT WORKS");  TV.println(); TV.print(">");} else {TV.println(); TV.println("IT WORKS");} 
}
else if(wykonaj == "xHOST START" && connection == 1 || wykonaj == "HOST START" && connection == 1)
{ 
  wykonaj = "x";  
  hostwww++;
  if(automat == 0) {TV.println(); TV.println(); TV.print("START ON "); TV.println(ipStg);  TV.println(); TV.print(">");} else {TV.println(); TV.print("START ON "); TV.println(ipStg);} 
}
else if(wykonaj == "xHOST STOP" && connection == 1 || wykonaj == "HOST STOP" && connection == 1)
{ 
  wykonaj = "x";  
  hostwww=0;
  if(automat == 0) {TV.println(); TV.println(); TV.println("STOP");  TV.println(); TV.print(">");} else {TV.println(); TV.println("STOP");} 
}
else if(wykonaj == "xCONNECT" && connection == 0 || wykonaj == "CONNECT" && connection == 0)
{ 
  wykonaj = "x";  
    // Change 'SS' to your Slave Select pin, if you arn't using the default pin
  if (ether.begin(sizeof Ethernet::buffer, mymac, SS) == 0)
    {Serial.println( "Failed to access Ethernet controller");
    TV.println();
    TV.println("Connection failed");
    TV.println();
    TV.print(">");
    return 0;}
#if STATIC
  ether.staticSetup(myip, gwip);
#else
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");
#endif

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);
  ether.printIp("DNS: ", ether.dnsip);

sprintf(ipStg, "%d.%d.%d.%d", ether.myip[0], ether.myip[1], ether.myip[2], ether.myip[3]);
connection = 1;
Serial.print(ipStg);
  if(automat == 0) {TV.println(); TV.println(); TV.println("CONNECTED");  TV.println(); TV.print(">");} else {TV.println(); TV.println("");} 
}
else if(wykonaj == "xMYSQL" || wykonaj == "MYSQL")
{ 
  wykonaj = "x";  
  baza = 1;
  if(automat == 0) {TV.println(); TV.println(); TV.print("Host:");} else {TV.println();TV.print("Host:");} 
}
else if(c[1] == 'I' && c[2] == 'N' && c[3] == 'P' && c[4] == 'U' && c[5] == 'T' && c[6] == ' ' && c[7] == '"') //INPUT
{
  String pytanie, zmienna;
  int x=8;
  for(;c[x] != '"';x++)
  {
    pytanie = pytanie + c[x];
  }
  for(;c[x] > NULL;x++)
  {
    if(c[x] != '"' && c[x] != ';' && c[x] != ' '){zmienna = zmienna + c[x];}
  }

if(automat == 0) {TV.println(); TV.println(); TV.print(pytanie.c_str());} else {TV.println(); TV.print(pytanie.c_str());} 
wykonaj ="x";
  while(1)
  {
    klawiatura();
    if(wykonaj != "x")
    {

      //----------------------------------------------------------
int TN = NULL, a = 0;
String wart;

for(int x=1;c[x] > NULL;x++)
  {
    
    wart = c[x];
    if(wart == "0" || wart == "1" || wart == "2" || wart == "3" || wart == "4" || wart == "5" || wart == "6" || wart == "7" || wart == "8" || wart == "9")
{
      TN = TN + atoi(wart.c_str());
  
          if(a==0)
          {a=TN;}
          else if(a<10)
          {a=a*10; a=a+TN;}
          else if(b<100)
          {a=a*10; a=a+TN;}
          else if(a<1000)
          {a=a*10; a=a+TN;}
          else if(a<10000)
          {a=a*10; a=a+TN;}

          TN = NULL;
}
  }
//---------------------------------------------------------
      setvar(zmienna, a);
      
      break;
    }
    
  }

  
  
}
else if(c[1]=='I' && c[2]=='F' && c[3]==' ' && c[4]=='(') //IF
{
  String zmienna1, warunek, zmienna2, polecenie;
  int z1, z2;
  int x=5;
    for(;c[x]!='=' && c[x]!='<' && c[x]!='>';x++)
  {
    zmienna1 = zmienna1 + c[x];
    z1=getvar(zmienna1);
  }
  for(;c[x]=='='||c[x]=='<'||c[x]=='>';x++)
  {
    warunek = warunek + c[x];
  }
  int TN = NULL, a = NULL;
String wart; 
  for(;c[x]!=')'; x++)
  {
    //----------------------------------------------------------
   
    wart = c[x];
    if(wart == "0" || wart == "1" || wart == "2" || wart == "3" || wart == "4" || wart == "5" || wart == "6" || wart == "7" || wart == "8" || wart == "9")
{
      TN = TN + atoi(wart.c_str());
  
          if(a==0)
          {a=TN;}
          else if(a<10)
          {a=a*10; a=a+TN;}
          else if(b<100)
          {a=a*10; a=a+TN;}
          else if(a<1000)
          {a=a*10; a=a+TN;}
          else if(a<10000)
          {a=a*10; a=a+TN;}

          TN = NULL;
}
else {zmienna2 = zmienna2 + c[x];}  
//---------------------------------------------------------
    
  }if(a != NULL){z2=a;}else{z2=getvar(zmienna2);}
  x=x+7;
  for(;c[x]>NULL;x++)
  {
    polecenie = polecenie + c[x];
  }

  if(warunek=="=")
  {
    if(z1==z2){wykonaj="x"+polecenie;}else{wykonaj="x"; if(automat == 0) {TV.println(); TV.println(); TV.print(">");} else {} }
  }
  else if(warunek=="<")
  {
    if(z1<z2){wykonaj="x"+polecenie;}else{wykonaj="x"; if(automat == 0) {TV.println(); TV.println(); TV.print(">");} else {} }
  }
  else if(warunek==">")
  {
    if(z1>z2){wykonaj="x"+polecenie;}else{wykonaj="x"; if(automat == 0) {TV.println(); TV.println(); TV.print(">");} else {} }
  }
  else if(warunek=="=>")
  {
    if(z1>=z2){wykonaj="x"+polecenie;}else{wykonaj="x"; if(automat == 0) {TV.println(); TV.println(); TV.print(">");} else {} }
  }
  else if(warunek=="<=")
  {
    if(z1<=z2){wykonaj="x"+polecenie;}else{wykonaj="x"; if(automat == 0) {TV.println(); TV.println(); TV.print(">");} else {} }
  }
  else if(warunek=="<>")
  {
    if(z1!=z2){wykonaj="x"+polecenie;}else{wykonaj="x"; if(automat == 0) {TV.println(); TV.println(); TV.print(">");} else {} }
  }
  
}
else if(c[1] == '0' || c[1] == '1' || c[1] == '2' || c[1] == '3' || c[1] == '4' || c[1] == '5' || c[1] == '6' || c[1] == '7' || c[1] == '8' || c[1] == '9') //DODAJ LINIJK╩ PROGRAMU
{
  int poczatek = 0, TN, a=0;
  String wartosc, wart;
   for(int x=1;c[x] > NULL;x++)
  {  wart = c[x];
        
       if(poczatek == 0 && c[x] == ' ')
       {
           poczatek = 1;
       }
       else if(poczatek == 1)
       {
           wartosc = wartosc + c[x];
       }
       else if(wart == "0" || wart == "1" || wart == "2" || wart == "3" || wart == "4" || wart == "5" || wart == "6" || wart == "7" || wart == "8" || wart == "9")
      {  
        TN = TN + atoi(wart.c_str());
          
        if(a==0)
          {a=TN;}
          else if(a<10)
          {a=a*10; a=a+TN;}
          else if(b<100)
          {a=a*10; a=a+TN;}
          else if(a<1000)
          {a=a*10; a=a+TN;}
          else if(a<10000)
          {a=a*10; a=a+TN;}
          TN = NULL;
                       
       }
       else
       {
        
       }

   }
line(a, wartosc);

wykonaj = "x";
if(automat == 0) {TV.println(); TV.println(); TV.print(">");} else {TV.println();} 
}
else if(c[1] == 'G' && c[2] == 'O' && c[3] == 'T' && c[4] == 'O') //GOTO
{
  //----------------------------------------------------------
int TN = NULL, a = 0;
String wart;

for(int x=5;c[x] > NULL;x++)
  {
    
    wart = c[x];
    if(wart == "0" || wart == "1" || wart == "2" || wart == "3" || wart == "4" || wart == "5" || wart == "6" || wart == "7" || wart == "8" || wart == "9")
{
      TN = TN + atoi(wart.c_str());
  
          if(a==0)
          {a=TN;}
          else if(a<10)
          {a=a*10; a=a+TN;}
          else if(b<100)
          {a=a*10; a=a+TN;}
          else if(a<1000)
          {a=a*10; a=a+TN;}
          else if(a<10000)
          {a=a*10; a=a+TN;}

          TN = NULL;
}
  }
//---------------------------------------------------------
program = a;
wykonaj = "x";
}
else if(c[1] == 'L' && c[2] == 'I' && c[3] == 'S' && c[4] == 'T')
{
  TV.println();
  TV.println();

//----------------------------------------------------------
int TN = NULL, a = 0;
String wart;

for(int x=5;c[x] > NULL;x++)
  {
    
    wart = c[x];
    if(wart == "0" || wart == "1" || wart == "2" || wart == "3" || wart == "4" || wart == "5" || wart == "6" || wart == "7" || wart == "8" || wart == "9")
{
      TN = TN + atoi(wart.c_str());
  
          if(a==0)
          {a=TN;}
          else if(a<10)
          {a=a*10; a=a+TN;}
          else if(b<100)
          {a=a*10; a=a+TN;}
          else if(a<1000)
          {a=a*10; a=a+TN;}
          else if(a<10000)
          {a=a*10; a=a+TN;}

          TN = NULL;
}
  }
//---------------------------------------------------------
if(a != 0)
{list(a);}
else
{
  for(int i =0; i<101; i++)
  {
    list(i);
  }
}


  
  wykonaj = "x";
  TV.println();
  TV.print(">");
  
}
else if(wykonaj == "xNEW")
{
  for(int i=0;i<101;i++)
//  line(i, "");
wykonaj = "x";
TV.println();
  //TV.println("READY");
  TV.println();
  TV.print(">");
  
}
else if(c[1] == 'L' && c[2] == 'O' && c[3] == 'A' && c[4] == 'D') //LOAD
{
  TV.println();
  TV.println();
  
/*    if (!SD.begin(4)) {
    TV.println("SD CARD REQUIRED!");
  }
  else
  {
   TV.println("FOUND:");
 
  }*/
  TV.println("SD CARD REQUIRED!");
    
  TV.println();
  TV.print(">");
  wykonaj = "x";
}
else if(c[1] == 'S' && c[2] == 'A' && c[3] == 'V' && c[4] == 'E') //SAVE
{
  TV.println();
  TV.println();

/*if (!SD.begin(4)) {
    TV.println("SD CARD REQUIRED!");
  }
  else
  {
  TV.println("OK");
  }*/
  TV.println("SD CARD REQUIRED!");

  TV.println();
  TV.print(">");
  wykonaj = "x";
}
else if(c[1] == 'P' && c[2] == 'A' && c[3] == 'U' && c[4] == 'S' && c[5] == 'E' && c[6] == ' ') //PAUSE
{

//----------------------------------------------------------
int TN = NULL, a = 0;
String wart;
String zmienna="";
for(int x=7;c[x] > NULL;x++)
  {
    
    wart = c[x];
    if(wart == "0" || wart == "1" || wart == "2" || wart == "3" || wart == "4" || wart== "5" || wart == "6" || wart == "7" || wart == "8" || wart == "9")
{
      TN = TN + atoi(wart.c_str());
  
          if(a==0)
          {a=TN;}
          else if(a<10)
          {a=a*10; a=a+TN;}
          else if(b<100)
          {a=a*10; a=a+TN;}
          else if(a<1000)
          {a=a*10; a=a+TN;}
          else if(a<10000)
          {a=a*10; a=a+TN;}

          TN = NULL;
}
else
{zmienna = zmienna + c[x];}
  }
//---------------------------------------------------------
 a=a/2;
 unsigned long czekaj;
  unsigned long aktualnyCzas = 0; aktualnyCzas = millis();
  if(zmienna==""){czekaj = aktualnyCzas + a;}
  else 
  {
    int qwerty = getvar(zmienna);
    czekaj = aktualnyCzas + qwerty;
  }

  
//  for(;aktualnyCzas<czekaj;aktualnyCzas = millis())
  //{}

  while(1)
  {
    Serial.print(aktualnyCzas);
    aktualnyCzas = millis();
    if(aktualnyCzas >= czekaj)
    {break;}
    else
    {}
  }
  
  //delay(a);
//Serial.print(a);
  wykonaj = "x";
   if(automat == 0) {TV.println();  TV.println(); TV.print(">");} else {} 
}
else if(wykonaj == "xRUN") //RUN
{
  wykonaj = "x";
  program = 1;
  TV.println();
 // TV.print(">");
 // program = 1;
}
 else if(c[1] == 'R' && c[2] == 'E' && c[3] == 'S' && c[4] == 'T' && c[5] == 'A' && c[6] == 'R' && c[7] == 'T') //RESET RESTART
 {
  digitalWrite(Reset, LOW);
TV.println();
TV.println("ERROR");
TV.println();
TV.print(">");
RTN = 0;
   wykonaj = "x";

 }
else if(c[1] == 'R' && c[2] == 'E' && c[3] == 'M') //REM
{
   wykonaj = "x";
  if(automat == 0) {TV.println(); TV.println(); TV.print(">");} else {} 
}
 else if(c[1] == 'P' && c[2] == 'R' && c[3] == 'I' && c[4] == 'N' && c[5] == 'T' && c[6] == ' ' && c[7] == '"') //PRINT ""
{
  TV.print("                        ");
  TV.println("");
  //for(int x=8;c[x]!='"';x++)
  int x=7;
  String z;
  for(;;)
  {
    x++;
         if(c[x+1]==NULL && c[x]=='"'){break;}
    else if(c[x]==';')
    {
      //x++;
      for(;;)
      {
        if(c[x+1]==NULL && c[x]=='"'){wykonaj = "x" + z; break;}
        x++;
        z = z + c[x];
        Serial.print(z);
      }

      wykonaj = "x" + z;
      break;
    }
    else
    {
    TV.print(c[x]); 
    }
   
  }


  
  TV.println();
  wykonaj = "x";
  if(automat == 0) {TV.println(); TV.print(">");} else {} 
  }
else if(c[1] == 'P' && c[2] == 'I' && c[3] == 'N' && c[4] == 'G' && c[5] == ' ' && connection == 1) //PING
{
//String adres="";
  for(int x=6;c[x]!=NULL;x++)
  {
    adres = adres + c[x];
  }
  
 // TV.println();
 // TV.print(adres.c_str());
 // TV.println();
  wykonaj = "x";

if(firstping==1)
{
  firstping++; TV.println(); TV.print("Pinging: "); TV.println(adres.c_str());
}
else
{
  TV.println(); TV.print("Pinging: "); TV.println(adres.c_str());
}

  
 

/*#if 1
  // use DNS to locate the IP address we want to ping
  if (!ether.dnsLookup(PSTR("www.google.com")))
    Serial.println("DNS failed");
#else*/
  ether.parseIp(ether.hisip, adres.c_str()); Serial.println(adres.c_str());
//#endif
  ether.printIp("SRV: ", ether.hisip);

  // call this to report others pinging us
  ether.registerPingCallback(gotPinged);

  timer = -9999999; // start timing out right away
  TV.println();
ping = 1;
/*for(int ileping = 0; ileping <= 3;)
{
  
}*/
  // if(automat == 0) {TV.println(); TV.print(">");} else {} 
}
else if(wykonaj == "xINFO")
{
  RTN = 0;
  wykonaj = "x";
  /*
   TV.println();
   TV.println();
   TV.print(" Autor: Krzysztof Chojka      ");
   TV.print("                             ");
   TV.print("Plytki: - Arduino UNO        ");
   TV.print("        - Arduino MEGA 2560  ");
   TV.print("                             ");
   TV.print("Biblioteki: - TVout.h        ");
   TV.print("            - fontALL.h      ");
   TV.print("                            ");
   TV.print(">");
*/
info();
}
else if(c[1] == 'H' && c[2] == 'E' && c[3] == 'L' && c[4] == 'P')
{

if(c[5] == '1' || c[6] == '1')
 { 
  TV.println("");
  //-------------------
     // TV.println("");
     // TV.println("- HELP");
      TV.println("");
      TV.println("PAGE 1/5 --------------------");
      TV.println("");
      TV.println("- HELP |1-5|");
      TV.println("");
      TV.println("- TEST");
      TV.println("");
      TV.println("- INFO");
      TV.println("");
     // TV.println("- GAMES");
    //  TV.println("");
      TV.println("- CLS");
      TV.println("");
      TV.println("- RESTART");
      TV.println("");
      TV.println("- ADMIN");
  //-------------------
 }
 else if(c[5] == '2' || c[6] == '2')
 { 
  TV.println("");
  //-------------------
     // TV.println("");
     // TV.println("- HELP");
      TV.println("");
      TV.println("PAGE 2/5 --------------------");
      TV.println("");
      TV.println("- NUM |1-10000|");
      TV.println("");
      TV.println("- PRINT |TXT|v|x+y|");
      TV.println("");
      TV.println("- HIGH |40-53|");
      TV.println("");
      TV.println("- LOW |40-53|");
      TV.println("");
      TV.println("- START STROBE |40-53|");
      TV.println("");
      TV.println("- STOP STROBE");
     // TV.println("");
     // TV.println("- ");
     // TV.println("");
     // TV.println("- ");
  //-------------------
 }
 else if(c[5] == '3' || c[6] == '3')
 { 
  TV.println("");
  //-------------------
      TV.println("");
      TV.println("PAGE 3/5 - ------------------");
      TV.println("");
      TV.println("- |1-100| |command|");
      TV.println("");
      TV.println("- GOTO |1-100|");
      TV.println("");
      TV.println("- PAUSE |x|");
      TV.println("");
      TV.println("- LIST");
      TV.println("");
      TV.println("- LOAD");
      TV.println("");
      TV.println("- SAVE");
      TV.println("");
      TV.println("- RUN");
      TV.println("");
      TV.println("- NEW");
  //-------------------
 }
 else if(c[5] == '4' || c[6] == '4')
 { 
  TV.println("");
  //-------------------
     // TV.println("");
     // TV.println("- HELP");
      TV.println("");
      TV.println("PAGE 4/5 - ------------------");
      TV.println("");
      TV.println("- REM | |");
      TV.println("");
      TV.println("- LET | |");
      TV.println("");
      TV.println("- CLEAR");
      TV.println("");
      TV.println("- INPUT |TXT|;| |");
      TV.println("");
      TV.println("- IF () THEN | |");
    //  TV.println("");
    //  TV.println("- ");
    //  TV.println("");
    //  TV.println("- ");
    //  TV.println("");
    //  TV.println("- ");
  //-------------------
 }
 else if(c[5] == '5' || c[6] == '5')
 { 
  TV.println("");
  //-------------------
     // TV.println("");
     // TV.println("- HELP");
      TV.println("");
      TV.println("PAGE 5/5 - Admin's commands--");
      TV.println("");
      TV.println("- TV.BEGIN();");
      TV.println("");
      TV.println("- TV.SELECT_FONT();");
      TV.println("");
      TV.println("- PINMODE |x| OUTPUT/INPUT");
      TV.println("");
      TV.println("- DIGITALWRITE |x| HIGH/LOW");
      TV.println("");
      TV.println("- SERIAL.PRINT |TXT|");
      TV.println("");
      TV.println("- HIDE / SHOW");
      TV.println("");
      TV.println("- CODES = TRUE/FALSE");
      TV.println("");
      TV.println("- EXIT");
  //-------------------
 }
 else
 { 
  TV.println("");
  //-------------------
     // TV.println("");
     // TV.println("- HELP");
      TV.println("");
      TV.println("PAGE 1/5 --------------------");
      TV.println("");
      TV.println("- HELP |1-5|");
      TV.println("");
      TV.println("- TEST");
      TV.println("");
      TV.println("- INFO");
      TV.println("");
   //   TV.println("- GAMES");
    //  TV.println("");
      TV.println("- CLEAR");
      TV.println("");
      TV.println("- RESTART");
      TV.println("");
      TV.println("- ADMIN");
  //-------------------
 }
 TV.println();
  TV.print("-----------------------------");
  RTN = 0;
  wykonaj = "x";
  if(automat == 0) {TV.print(">");} else {} 
}
else if(wykonaj == "x")
{}
else if(c[1] == 'N' && c[2] == 'U' && c[3] == 'M')
{

int TN=NULL, a=0;
    String wartosc;

 for(int x=4;c[x] > NULL;x++)
  {
    //int got = 0;
    wartosc = c[x];
    if(wartosc == "0" || wartosc == "1" || wartosc == "2" || wartosc == "3" || wartosc == "4" || wartosc == "5" || wartosc == "6" || wartosc == "7" || wartosc == "8" || wartosc == "9")
{
      TN = TN + atoi(wartosc.c_str());
  
          if(a==0)
          {a=TN;}
          else if(a<10)
          {a=a*10; a=a+TN;}
          else if(b<100)
          {a=a*10; a=a+TN;}
          else if(a<1000)
          {a=a*10; a=a+TN;}
          else if(a<10000)
          {a=a*10; a=a+TN;}

          TN = NULL;
}
  }


TV.println("");
if(automat == 0) {TV.println();} else {} 
  //-------------------
      if(a>10000)
      {  
        //TV.println("");
        TV.println("NUMBER IS TOO BIG!");
  //TV.println("");
  liczba2 = 0;
  RTN = 0;
  wykonaj = "x";
 // TV.println("");
 // TV.print(">");
  if(automat == 0) {TV.println(); TV.print(">");} else {} 
  }
  else
  {
      
     for(int i=0; i<a; i++)
      {
        TV.print(i+1);
        TV.print(" ");
       }
  //-------------------
 // TV.println("");
  liczba2 = 0;
  RTN = 0;
  wykonaj = "x";
  //TV.println("");
 // TV.print(">");
  if(automat == 0) {TV.println(); TV.println(); TV.print(">");} else {TV.println("");} 
  }
}
else if(wykonaj == "xCLS") //CLS
{
  TV.clear_screen();
  RTN = 0;
  wykonaj = "x";
  TV.print(">");
}
else if(wykonaj == "xCLEAR") //CLEAR
{
  incomingByte = 0;
znak = 0;
first = 0;
RTT = "x";
wykonaj = "x";
ile = 0;
RTN=0;
liczba2=0;
jak = 2;
interwal = 0;
jaki = 20;
zmien1 = 0;
zmien2 = 0;
zmien3 = 0;
zmien4 = 0;
zmien5 = 0;
nazwa1 = "x";
nazwa2 = "x";
nazwa3 = "x";
nazwa4 = "x";
nazwa5 = "x";

  RTN = 0;
  wykonaj = "x";
  TV.println();
  TV.println();
  TV.print(">");
}
else if(c[1] == 'H' && c[2] == 'I' && c[3] == 'G' && c[4] == 'H')
{
//----------------------------------------------------------
int TN = NULL, a = 0;
String wart;

for(int x=5;c[x] > NULL;x++)
  {
    
    wart = c[x];
    if(wart == "0" || wart == "1" || wart == "2" || wart == "3" || wart == "4" || wart== "5" || wart == "6" || wart == "7" || wart == "8" || wart == "9")
{
      TN = TN + atoi(wart.c_str());
  
          if(a==0)
          {a=TN;}
          else if(a<10)
          {a=a*10; a=a+TN;}
          else if(b<100)
          {a=a*10; a=a+TN;}
          else if(a<1000)
          {a=a*10; a=a+TN;}
          else if(a<10000)
          {a=a*10; a=a+TN;}

          TN = NULL;
}
  }
//---------------------------------------------------------
  
  digitalWrite(a, HIGH);
 // TV.println("");
  liczba2 = 0;
  RTN = 0;
  wykonaj = "x";
 // TV.println("");
//  TV.print(">");
  if(automat == 0) {TV.println(); TV.println(); TV.print(">");} else {} 
}
else if(c[1] == 'L' && c[2] == 'O' && c[3] == 'W')
{

  //----------------------------------------------------------
int TN = NULL, a = 0;
String wart;

for(int x=4;c[x] > NULL;x++)
  {
    
    wart = c[x];
    if(wart == "0" || wart == "1" || wart == "2" || wart == "3" || wart == "4" || wart== "5" || wart == "6" || wart == "7" || wart == "8" || wart == "9")
{
      TN = TN + atoi(wart.c_str());
  
          if(a==0)
          {a=TN;}
          else if(a<10)
          {a=a*10; a=a+TN;}
          else if(b<100)
          {a=a*10; a=a+TN;}
          else if(a<1000)
          {a=a*10; a=a+TN;}
          else if(a<10000)
          {a=a*10; a=a+TN;}

          TN = NULL;
}
  }
//---------------------------------------------------------
  
  digitalWrite(a, LOW);
   // TV.println("");
    liczba2 = 0;
  RTN = 0;
  wykonaj = "x";
 // TV.println("");
 // TV.print(">");
  if(automat == 0) {TV.println(); TV.println(); TV.print(">");} else {} 
}
else if(c[1] == 'S' && c[2] == 'T' && c[3] == 'A' && c[4] == 'R' && c[5] == 'T' && c[6] == ' ' && c[7] == 'S' && c[8] == 'T' && c[9] == 'R' && c[10] == 'O' && c[11] == 'B' && c[12] == 'E')
{

//----------------------------------------------------------
int TN = NULL, a = 0;
String wart;

for(int x=13;c[x] > NULL;x++)
  {
    
    wart = c[x];
    if(wart == "0" || wart == "1" || wart == "2" || wart == "3" || wart == "4" || wart== "5" || wart == "6" || wart == "7" || wart == "8" || wart == "9")
{
      TN = TN + atoi(wart.c_str());
  
          if(a==0)
          {a=TN;}
          else if(a<10)
          {a=a*10; a=a+TN;}
          else if(b<100)
          {a=a*10; a=a+TN;}
          else if(a<1000)
          {a=a*10; a=a+TN;}
          else if(a<10000)
          {a=a*10; a=a+TN;}

          TN = NULL;
}
  }
//---------------------------------------------------------

  dioda = a;
  jak = 1;
      TV.println("");
    liczba2 = 0;
  RTN = 0;
  interwal = 0;
  wykonaj = "x";
  TV.println("");
  TV.print(">");
}
else if(wykonaj == "xSTOP STROBE")
{
  jak = 2;
      TV.println("");
      digitalWrite(dioda, LOW);
    liczba2 = 0;
  RTN = 0;
  wykonaj = "x";
  TV.println("");
  TV.print(">");
}
else if(wykonaj == "xADMIN" && admin == 0)
{
  RTN = 0;
  RTT = "xpassword";
  wykonaj = "x";
  pass = 1;
  TV.println("");
  TV.print("Password:");
}
else if(wykonaj == "xADMIN" && admin == 1)
{
  RTN = 0;
  wykonaj = "x";
  TV.println("");
  TV.println("You are admin");
  TV.println("");
  TV.print(">");
}
else if(wykonaj == "[email protected]")
{
  RTN = 0;
  wykonaj = "x";
  pass = 0;
  admin = 1;
  TV.println("");
  TV.println("");
  TV.print(">");
}
else if(c[1]=='p' && c[2]=='a' && c[3]=='s' && c[4]== 's' && c[5]=='w' && c[6]=='o' && c[7]=='r' && c[8]=='d')
{
  RTN = 0;
  wykonaj = "x";
  pass = 0;
  admin = 0;
  TV.println("");
  TV.println("");
  TV.println("WRONG PASSWORD!");
  TV.println("");
  TV.print(">");
}
else if(wykonaj == "xEXIT" && admin ==1)
{
  RTN = 0;
  wykonaj = "x";
  admin = 0;
  TV.println("");
  TV.println("");
  TV.print(">");
}
else if(wykonaj == "xHIDE" && admin == 1)
{
  pass = 1;
  RTN = 0;
  wykonaj = "x";
  TV.println("");
  TV.println("");
  TV.print(">");
}
else if(wykonaj == "xSHOW" && admin == 1)
{
  pass = 0;
  RTN = 0;
  wykonaj = "x";
  TV.println("");
  TV.println("");
  TV.print(">");
}
else if(wykonaj == "xCODES = TRUE" && admin == 1)
{
  kody = 1;
  RTN = 0;
  wykonaj = "x";
  TV.println("");
  TV.println("");
  TV.print(">");
}
else if(wykonaj == "xCODES = FALSE" && admin == 1)
{
  kody = 0;
  RTN = 0;
  wykonaj = "x";
  TV.println("");
  TV.println("");
  TV.print(">");
}
else if(c[1]=='S' && c[2]=='E' && c[3]=='R' && c[4]== 'I' && c[5]=='A' && c[6]=='L' && c[7]=='.' && c[8]=='P' && c[9]=='R' && c[10]=='I' && c[11]=='N' && c[12]=='T' && c[13]==' ' && admin == 1)
{
  String wartosc;
  int e = 0, n = 0, d = 0;
   for(int x=14;c[x] > NULL;x++)
  {wartosc = wartosc + c[x];}
  Serial.print(wartosc);
  wartosc = "";
  RTN = 0;
  wykonaj = "x";
  TV.println("");
  TV.println("");
  TV.print(">");
  
}
else if(c[1]=='D' && c[2]=='I' && c[3]=='G' && c[4]== 'I' && c[5]=='T' && c[6]=='A' && c[7]=='L' && c[8]=='W' && c[9]=='R' && c[10]=='I' && c[11]=='T' && c[12]=='E' && admin == 1)
{
  String wartosc;
   for(int x=13;c[x] > NULL;x++)
  {
    if(c[x] == '0' || c[x] == '1' || c[x] == '2' || c[x] == '3' || c[x] == '4' || c[x] == '5' || c[x] == '6' || c[x] == '7' || c[x] == '8' || c[x] == '9' || c[x] == ' ') {}
     else {wartosc = wartosc + c[x];}
    }
TV.println("");
if(wartosc == "HIGH")
{
  digitalWrite(liczba2, HIGH);
}
else if(wartosc == "LOW")
{
   digitalWrite(liczba2, LOW); 
}
else
{
   const char* a;
    a = wartosc.c_str();
    TV.print("BAD ARGUMENT:");
    TV.println(a);
}

  
  wartosc = "";
  RTN = 0;
  wykonaj = "x";
  
 TV.println("");
  TV.print(">");
  
}
else if(c[1]=='P' && c[2]=='I' && c[3]=='N' && c[4]== 'M' && c[5]=='O' && c[6]=='D' && c[7]=='E' && admin == 1)
{
  String wartosc;
   for(int x=9;c[x] > NULL;x++)
  {
     if(c[x] == '0' || c[x] == '1' || c[x] == '2' || c[x] == '3' || c[x] == '4' || c[x] == '5' || c[x] == '6' || c[x] == '7' || c[x] == '8' || c[x] == '9' || c[x] == ' ') {}
     else {wartosc = wartosc + c[x];}
  }
TV.println("");
if(wartosc == "OUTPUT")
{
  pinMode(liczba2, OUTPUT);
}
else if(wartosc == "INPUT")
{
   pinMode(liczba2, INPUT); 
}
else
{
    const char* a;
    a = wartosc.c_str();
    TV.print("BAD ARGUMENT:");
    TV.println(a);
}

  
  wartosc = "";
  RTN = 0;
  wykonaj = "x";
  
 TV.println("");
  TV.print(">");
  
}
else
{
//------------------------------------------------------------------------------

if(c[1]=='P' && c[2]=='R' && c[3]=='I' && c[4]== 'N' && c[5]=='T' && c[6]==' ') //PRINT NUM
{
  int w = 0, pierwszy, drugi;
  int TN=NULL, a=NULL;
    String wartosc, znak;
String nazwa_zmiennej="";
pierwszy = 0;
drugi = 0;
w = 0;
znak = "x";
    
   for(int x=7;c[x] > NULL;x++)
  {
    //int got = 0;
    wartosc = c[x];
    if(wartosc == "0" || wartosc == "1" || wartosc == "2" || wartosc == "3" || wartosc == "4" || wartosc == "5" || wartosc == "6" || wartosc == "7" || wartosc == "8" || wartosc == "9")
{
      TN = TN + atoi(wartosc.c_str());
  
          if(a==NULL)
          {a=TN;}
          else if(a<10)
          {a=a*10; a=a+TN;}
          else if(b<100)
          {a=a*10; a=a+TN;}
          else if(a<1000)
          {a=a*10; a=a+TN;}
          else if(a<10000)
          {a=a*10; a=a+TN;}

          TN = NULL;
}
else if(wartosc == "+" || wartosc == "-" || wartosc == "*" || wartosc == "/" || wartosc == "%")
{

     /* if(w==0)
      {pierwszy = a; w++;}
      else if(w==1)
      {drugi = a;}*/
       pierwszy = a;
       a = 0;
      znak = wartosc;
     // got = 1;
    
}
else if(wartosc == " ")
{
 
}
else
{
   //TUTAJ
   nazwa_zmiennej = nazwa_zmiennej + wartosc;
}
   
   }
if(nazwa_zmiennej != "")
{
    int varnum = getvar(nazwa_zmiennej);
   if(automat == 0) {TV.println(); TV.println(varnum);  TV.println(""); TV.print(">");} else {  TV.println(""); TV.println(varnum);} 
   RTN = 0;
   wykonaj = "x";
}
else
{
   
drugi = a;

   if(znak == "+")
   {
    //const char* x;
   // x = znak.x_str();
    //TV.println("");
    int wynik = 0;
    wynik = pierwszy + drugi;
    //TV.println("");
     //TV.println(wynik);
      // TV.println("");
         RTN = 0;
  wykonaj = "x";
 // TV.print(">");

  if(automat == 0) {TV.println(); TV.println(wynik);  TV.println(""); TV.print(">");} else {  TV.println(""); TV.println(wynik);} 
   }
   else if(znak == "-")
   {
    //const char* x;
   // x = znak.x_str();
 //   TV.println("");
    int wynik = 0;
    wynik = pierwszy - drugi;
//    TV.println("");
//      TV.println(wynik);
    //   TV.println("");
         RTN = 0;
  wykonaj = "x";
 //TV.print(">");

  if(automat == 0) {TV.println(); TV.println(wynik);  TV.println(""); TV.print(">");} else {  TV.println(""); TV.println(wynik);} 
   }
   else if(znak == "*")
   {
    //const char* x;
   // x = znak.x_str();
 //   TV.println("");
    int wynik = 0;
    wynik = pierwszy * drugi;
//    TV.println("");
 //     TV.println(wynik);
 //      TV.println("");
         RTN = 0;
  wykonaj = "x";
//  TV.print(">");

if(automat == 0) {TV.println(); TV.println(wynik);  TV.println(""); TV.print(">");} else {  TV.println(""); TV.println(wynik);} 
   }
   else if(znak == "%")
   {
    int wynik = 0;
    wynik = pierwszy % drugi;
         RTN = 0;
  wykonaj = "x";
if(automat == 0) {TV.println(); TV.println(wynik);  TV.println(""); TV.print(">");} else {  TV.println(""); TV.println(wynik);} 
   }
       else if(znak == "/")
   {
    //const char* x;
   // x = znak.x_str();
  //  TV.println("");
    int wynik = 0;
    //wynik = pierwszy * drugi;
  //  TV.println("");
    int czy = pierwszy%drugi;
    if(czy > 0)
    {
      if(automat == 0) {TV.println(); TV.println((float)pierwszy/drugi);  TV.println(""); TV.print(">");} else {  TV.println(""); TV.println((float)pierwszy/drugi);} 
    }
    else
    {
      if(automat == 0) {TV.println(); TV.println(pierwszy/drugi);  TV.println(""); TV.print(">");} else {  TV.println(""); TV.println(pierwszy/drugi);} 
    }
      
      // TV.println("");
         RTN = 0;
  wykonaj = "x";
 // TV.print(">");
   }
   else
   {}
}
}
else if(c[1]=='L' && c[2]=='E' && c[3]=='T' && c[4]==' ') //LET
{
  String tym="x";
  for(int x=5;c[x] > NULL;x++)
  {
    tym = tym + c[x];
  }
 c = tym.c_str();
 String odp = zmienne();
if(odp == "ERROR")
{
  //------------------------------------------------------------------------------  
 if(automat == 0){
  TV.println("");
  TV.println("");
  TV.println("?SYNTAX ERROR USE >HELP");
  TV.println("");
  TV.print(">");
 }
 else
 {
  TV.println("");
  TV.print("?SYNTAX ERROR IN ");
  TV.println(program - 1);
 }
 RTN = 0;
  wykonaj = "x";
//------------------------------------------------------------------------------
}
else if(odp = "OK")
  {
  RTN = 0;
  wykonaj = "x";
  }
}
else{
  
String odp = zmienne();
if(odp == "ERROR")
{
  //------------------------------------------------------------------------------  
 if(automat == 0){
  TV.println("");
  TV.println("");
  TV.println("?SYNTAX ERROR USE >HELP");
  TV.println("");
  TV.print(">");
 }
 else
 {
  TV.println("");
  TV.print("?SYNTAX ERROR IN ");
  TV.println(program - 1);
 }
 RTN = 0;
  wykonaj = "x";
//------------------------------------------------------------------------------
}
else if(odp = "OK")
  {
  RTN = 0;
  wykonaj = "x";
  }
}


}
}