//------- - 15.04.2021 // DEMO OBJECTS //------- #include int tip1 = A0; int tip2 = A1; //--------------- VARIABLES USED IN MODULES - MUST BE char pit = ""; int spd = 8; //--------------- void setup() { pinMode(tip1, INPUT); pinMode(tip2, INPUT); //----------- START I2C COMMUNICATION - MUST BE Wire.setClock(100000); Wire.begin(); // join i2c bus //----------- begin_def(); } void loop() { trazi(); if (pit == 9) { end_prog(); } if (pit > 1 && pit < 5) { sound_light(); } if (digitalRead(tip1) == LOW) { ispis("BUT;-;X;1"); } if (digitalRead(tip2) == LOW) { ispis("BUT;+;X;1"); } delay(50); } //------------------------------------------------------------ SETTINGS void begin_def() // all settings you need in program { delay(2000); ispis("RST"); delay(200); ispis("CLS"); delay(500); ispis("BIT;1;255;153;189;231;231;189;153;255"); ispis("BIT;9;60;66;165;165;129;189;102;219"); // player ispis("BIT;8;60;66;165;129;189;66;231;24"); // player anima map ispis("OBJ;1;1;0;3;6"); ispis("OBJ;1;1;8;0;5;1"); begin_prog(); ispis("CLS"); ispis("FX;1"); // -- prikaz ’’ekrana’’ 1 ispis("POZ;5;2"); ispis("ANI;1"); ispis("KOL;1"); ispis("GRV;1"); } //------------------------------------------------------------ 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"); } }