// ------ - 15.04.2021 // DIGITAL READING INPUTS - A1,A2,A3 // ------ #include // variables for this sample int I1 = 0; int I2 = 0; int I3 = 0; int I1p = 0; int I2p = 0; int I3p = 0; //--------------- VARIABLES USED IN MODULES - MUST BE char pit = ""; int spd = 8; //--------------- void setup() { //----------- START I2C COMMUNICATION - MUST BE Wire.setClock(100000); Wire.begin(); // join i2c bus //----------- begin_def(); // start screen } void loop() { ispis("GET;1"); trazi(); I1 = String(int(pit)).toInt(); if (I1 != I1p) { ispis(" ;5;2"); ispis(String(I1)+";5;2"); sound(); I1p = I1;} ispis("GET;2"); trazi(); I2 = String(int(pit)).toInt(); if (I2 != I2p) { ispis(" ;5;3"); ispis(String(I2)+";5;3"); sound(); I2p = I2;} ispis("GET;3"); trazi(); I3 = String(int(pit)).toInt(); if (I3 != I3p) { ispis(" ;5;4"); ispis(String(I3)+";5;4"); sound(); I3p = I3;} } //-------------- for this sample void sound(){ ispis("BIP;800;50"); // salji("LED;G;50"); // LIGHT } //------------------------------------------------------------ SETTINGS void begin_def() // all settings you need in program { ispis("DEL"); delay(200); ispis("RST"); delay(200); ispis("CLS"); delay(500); ispis("INPUTS:;0;0"); ispis("I1 =;0;2"); ispis("I2 =;0;3"); ispis("I3 =;0;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;"); } }