//------- - 15.04.2021 // DEMO METEORS GAME SAME LIKE PYTHON PROG42.PY //------- #include int tip1 = A0; // jump switch 1 int tip2 = A1; // jump switch 2 //--------------- VARIABLES USED IN MODULES - MUST BE char pit = ""; int spd = 8; //--------------- // the setup routine runs once when you press reset: void setup() { pinMode(tip1, INPUT); pinMode(tip2, INPUT); //----------- START I2C COMMUNICATION - MUST BE Wire.setClock(100000); Wire.begin(); // join i2c bus //----------- begin_def(); } // the loop routine runs over and over again forever: void loop() { trazi(); if (pit == 9) { end_prog(); } if (pit > 1 && pit < 5) { sound_light(); } if (digitalRead(tip1) == LOW) { ispis("BUT;+;Y;2"); } if (digitalRead(tip2) == LOW) { ispis("BUT;-;Y;2"); } delay(50); // you can change this delay } //------------------------------------------------------------ SETTINGS void begin_def() // all settings you need in program { delay(2000); ispis("RST"); delay(200); ispis("CLS"); delay(500); ispis("BIT;2;102;255;219;195;195;102;60;24"); ispis("BIT;3;24;124;118;207;243;239;126;24"); ispis("BIT;8;224;112;50;95;95;50;112;224"); // anim ispis("BIT;9;112;56;26;191;191;26;56;112"); // play. ispis("OBJ;1;3;2;1;1"); //-- ekran 1 ispis("OBJ;1;3;5;4;1"); ispis("OBJ;1;2;4;1;1"); ispis("OBJ;1;2;8;4;1"); ispis("OBJ;2;3;2;2;1"); //-- ekran 2 ispis("OBJ;2;3;8;5;1"); ispis("OBJ;2;2;4;2;1"); ispis("OBJ;3;3;2;2;1"); //-- ekran 3 ispis("OBJ;3;3;8;3;1"); ispis("OBJ;3;2;1;5;1"); ispis("OBJ;3;2;5;2;1"); begin_prog(); ispis("CLS"); ispis("FX;1"); ispis("POZ;4;2"); ispis("ANI;3"); // -- animacija igrača ispis("KOL;1"); // --------> ispis("GRV;1") - ne koristimo ispis("ASD;1"); ispis("SPD;10;1"); // -- brzina pomaka // --------> ispis("PAD;1") - ne koristimo ispis("BOD;0"); ispis("LIV;5"); ispis("TIM;30"); // -- vrijeme igre 30 sekundi ispis("RND"); // -- slučajni redoslijed spd = 4; } //------------------------------------------------------------ ALL MODULES void ispis(String poruka) { Serial.println(poruka); poruka = poruka + ";"; int duz = poruka.length(); if (duz > 30) { String por1 = poruka.substring(0,30)+"+"; char dio1[31]; por1.toCharArray(dio1,duz); Wire.beginTransmission(0x11); Wire.write(dio1); Wire.endTransmission(); String por2 = poruka.substring(30); duz = por2.length(); char dio2[duz]; por2.toCharArray(dio2,duz); Wire.beginTransmission(0x11); Wire.write(dio2); Wire.endTransmission(); delay(duz*spd); } else { char copy[duz]; poruka.toCharArray(copy,duz); Wire.beginTransmission(0x11); Wire.write(copy); Wire.endTransmission(); delay(duz*spd); } } void trazi(){ Wire.requestFrom(0x11,1); while (Wire.available()) { pit = Wire.read(); } } void begin_prog() { ispis("CLS"); ispis("START;2;1;2"); ispis("G A M E;3;3"); delay(2000); } void end_prog(){ delay(300); trazi(); delay(300); ispis("CLS"); ispis("E N D;2;1;2"); ispis("G A M E;3;3"); ispis("Score:"+String(int(pit))+";3;4"); while (true){ delay(5000); } } void rest(){ ispis("RST"); while(true) { trazi(); if (pit == 5){ break; } delay(20); } } void sound_light(){ if (pit == 2){ // POINTS ispis("BIP;200;50"); ispis("LED;G;50"); } if (pit == 3) { // LIFES ispis("BIP;800;50"); ispis("LED;R;50"); } if (pit == 4){ // FALL ispis("BIP;1200;50"); ispis("LED;R;50"); } }