Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <PubSubClient.h>
- //Vores eget
- //Display
- #include <Arduino.h>
- #include <U8g2lib.h>
- #ifdef U8X8_HAVE_HW_SPI
- #include <SPI.h>
- #endif
- #ifdef U8X8_HAVE_HW_I2C
- #include <Wire.h>
- #endif
- U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display
- //Button
- const int buttonPin = D7; // the number of the pushbutton pin
- int buttonState = 0; // variable for reading the pushbutton status
- //Potentiometer
- int potPin = A0; // select the input pin for the potentiometer
- int potVal = 0; // variable to store the value coming from the sensor
- //Buzzer
- const int buzzer = D6;
- //Egne variables etc
- int state = 1; //test
- int timeP = 0;
- int checkRun = 0;
- int runTime = 0;
- int antiSpamReset = 0;
- int resetSwitchCounter = 0;
- int buttonStatePrevious = 0;
- int buttonStateAlt = 0;
- int button_1_ready = 1; //Test values
- int button_2_ready = 1;
- int button_3_ready = 1;
- int sentry_1_ready = 1;
- int sentry_2_ready = 1;
- int sentry_3_ready = 1;
- int menuState = 1;
- int gamemode = 0;
- int buttonNo = 0;
- int diff = 0;
- int numberOfThings = 0;
- int MPV = 0;
- int hugeNumber = 0;
- int timeStarted = 0;
- int buzzerLimiter = 0;
- //GAME VARIABLES
- int ingameTime = 0;
- int timesCaught = 0;
- //TURRET CONTROL VARIABLES
- int nowControlling = 0;
- int sentryCommand = 0;
- int controlLimiter = 0;
- int oldDirection = 10;
- int newDirection = 11;
- //Gamemode 1
- int but1Pressed = 0;
- int but2Pressed = 0;
- int but3Pressed = 0;
- int buttonsPressed = 0;
- //Gamemode 2
- int takeOuts = 0;
- //Gamemode 2/3
- int but1CheckRun = 0;
- int but2CheckRun = 0;
- int but3CheckRun = 0;
- int but1StartTime = 0;
- int but2StartTime = 0;
- int but3StartTime = 0;
- int endgameCheck = 0;
- // Update these with values suitable for your network.
- const char* ssid = "DSB Free Wifi";
- const char* password = "skridspader";
- // for the in-class exercise, we'll use the public broker, but for the actual course project:
- // set-up a private mqtt broker at cloudmqtt.com (see Canvas for a howto video)
- //and uncomment / edit the following: [ you also need to change the 'client.connect' part of the code below in the code ]
- //const char *mqtt_server = "mXX.cloudmqtt.com";
- //const int mqtt_port = 17323;
- const char *mqtt_server = "m21.cloudmqtt.com";
- const int mqtt_port = 14939;
- const char *mqtt_user = "testuser";
- const char *mqtt_pass = "hejhejhej";
- //see the actual function below - this is just a placeholder..
- void callback(char* byteArraytopic, byte* byteArrayPayload, unsigned int length);
- //Let's define some objects:
- WiFiClient espClient;
- //and the mqtt client:
- PubSubClient client(mqtt_server,mqtt_port,callback,espClient);
- //THIS IS THE CORE OF THE 'SUBSCRIBE'
- //everytime something happens on the topics we've subscribed [down below in the code]; this function will be fired.
- void callback(char* byteArraytopic, byte* byteArrayPayload, unsigned int length) {
- // it has the 'topic' and the message 'payload'
- //let's convert the topic name [the first array] to a string:
- String topic;
- topic=String(byteArraytopic);
- Serial.print("Message arrived [");
- Serial.print(topic);
- Serial.print("] ");
- // let's convert the incoming message [which arrives as an array of characters] to a string:
- String payload;
- for (int i = 0; i < length; i++) {
- //Serial.print((char)payload[i]);
- payload+=(char)byteArrayPayload[i];
- }
- //HER ER DER KODE SOM AKTIVERES VED NYT PÅ TOPICS YOOO
- if (String(topic) == "groupsix/readyCheckBut1"){
- button_1_ready = 1;
- }
- if (String(topic) == "groupsix/readyCheckBut2"){
- button_2_ready = 1;
- }
- if (String(topic) == "groupsix/readyCheckBut3"){
- button_3_ready = 1;
- }
- if (String(topic) == "groupsix/readyCheckSen1"){
- sentry_1_ready = 1;
- }
- if (String(topic) == "groupsix/readyCheckSen2"){
- sentry_2_ready = 1;
- }
- if (String(topic) == "groupsix/readyCheckSen3"){
- sentry_3_ready = 1;
- }
- if (String(topic) == "groupsix/caught"){
- timesCaught=timesCaught+1;
- }
- if (String(topic) == "groupsix/b1p"){
- but1Pressed = 1;
- }
- if (String(topic) == "groupsix/b2p"){
- but2Pressed = 1;
- }
- if (String(topic) == "groupsix/b3p"){
- but3Pressed = 1;
- }
- }
- // Setup the wifi connection...
- void setup_wifi() {
- delay(10);
- // We start by connecting to a WiFi network
- Serial.println();
- Serial.print("Connecting to ");
- Serial.println(ssid);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.println("WiFi connected");
- Serial.println("IP address: ");
- Serial.println(WiFi.localIP());
- }
- // A function to connect to the mqtt server, and reconnect if the connection breaks, wifi breaks, server problem etc..
- void reconnect() {
- // Loop until we're reconnected
- while (!client.connected()) {
- Serial.print("Attempting MQTT connection...");
- // Attempt to connect:
- // if you are using cloudmqtt, uncomment the following line, and comment the one below...
- if (client.connect("groupsix","testuser","hejhejhej")){ // make sure 'myclientID' is something unique, e.g. 'groupXX'
- //if (client.connect("myclientID")) { // make sure 'myclientID' is something unique, e.g. 'groupXX'
- Serial.println("connected");
- // Once connected, publish an announcement...
- client.publish("groupsix/welcomeMessage", "hello world");
- // ... and resubscribe to all messages coming to the 'OLED' topic...
- client.subscribe("groupsix/#");
- client.subscribe("groupsix/controller_online");
- client.subscribe("groupsix/turretBegin");
- client.subscribe("groupsix/reset"); //til slukke gamemode
- client.subscribe("groupsix/diff");
- client.subscribe("groupsix/nowControlling");
- client.subscribe("groupsix/turretDirections");
- } else {
- Serial.print("failed, rc=");
- Serial.print(client.state());
- Serial.println(" try again in 5 seconds");
- // Wait 5 seconds before retrying
- delay(5000);
- }
- }
- }
- void setup() {
- //NOTE: if the following line does not work - try changing the BUILTIN_LED to LED_BUILTIN
- //if still does not work - attach a real LED to e.g. pin D5..
- pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output
- Serial.begin(115200);
- setup_wifi(); // self-explanatory.. check the function to see what it does..
- client.setServer(mqtt_server, mqtt_port); // connect to the mqtt server at the specified port [defined at the top]
- // set the 'callback' function, which is defined above.
- // We tell our client to fire the 'callback' function everytime there is a new message on the subscribed topics
- client.setCallback(callback);
- //Button
- pinMode(buttonPin, INPUT);
- //Buzzer
- pinMode(buzzer, OUTPUT);
- //Display
- u8g2.begin();
- }
- void loop() {
- //if we're not connected to the mqtt broker:
- if (!client.connected()) {
- reconnect();
- }
- client.loop();
- //Time
- timeP = millis();
- //Button
- buttonState = digitalRead(buttonPin);
- buttonStateAlt= digitalRead(buttonPin);
- //Potentiometer
- potVal = analogRead(potPin);
- //Makes sure everything isnt spammed when the button is kept down (going through menus when trying to reset and spamming the broker). Only sends output if the buttonstate is currently LOW, and previously HIGH.
- if (buttonStateAlt==HIGH){
- buttonState=LOW;
- }
- if (buttonStateAlt==LOW){
- if (buttonStatePrevious==HIGH){
- buttonState=HIGH;
- }
- else{
- buttonState=LOW;
- }
- }
- buttonStatePrevious=buttonStateAlt;
- //Actual reset
- if (buttonStateAlt==LOW){
- resetSwitchCounter=timeP;
- }
- if (timeP-resetSwitchCounter>3000 and state!=1 and state != 2){ //jeg vil gerne have man ikke kan køre initialiseringen over
- buttonStatePrevious=LOW; //Makes sure we dont have a click of "HIGH" when the system has been reset.
- u8g2.clearBuffer();
- u8g2.setFont(u8g2_font_ncenB14_tr);
- u8g2.drawStr(30,30,"System");
- u8g2.drawStr(35,55,"Reset");
- u8g2.sendBuffer();
- state=6;
- }
- //Splash state
- if (state==1){
- u8g2.clearBuffer();
- u8g2.setFont(u8g2_font_ncenB14_tr);
- u8g2.drawStr(0,35,"Agent Escape");
- u8g2.setFont(u8g2_font_chroma48medium8_8r);
- u8g2.drawStr(22,47,"Artuino Int");
- u8g2.sendBuffer();
- if (checkRun==0){
- runTime = millis();
- checkRun = 1;
- client.publish("groupsix/controller_online", "ready"); //Laver en splash screen og tjekker om alt er connected. Hvis ikke går den til en connection screen (som ikke ses hvis alt er tilgængeligt)
- }//Systemet fungerer så de gør opmærksomme på sig selv når de tænder, og når de får en "ready" fra controlleren. Derfor ved vi altid om de er på, med meget få resourcer.
- if (timeP-runTime>1000){
- checkRun = 0;
- state = 2;
- u8g2.clearBuffer();
- u8g2.setFont(u8g2_font_ncenB14_tr);
- }
- }
- //Connecting to others state
- if (state == 2){
- if(button_1_ready == 1 and button_2_ready == 1 and button_3_ready == 1 and sentry_1_ready == 1 and sentry_2_ready == 1 and sentry_3_ready == 1){
- state=3;
- }
- else{
- if(button_1_ready == 1){ //Viser dem på skærmen alt som de kommer online.
- u8g2.drawStr(0,20,"But1");
- }
- if(button_2_ready == 1){
- u8g2.drawStr(0,40,"But2");
- }
- if(button_3_ready == 1){
- u8g2.drawStr(0,60,"But3");
- }
- if(sentry_1_ready == 1){
- u8g2.drawStr(70,20,"Sen1");
- }
- if(sentry_2_ready == 1){
- u8g2.drawStr(70,40,"Sen2");
- }
- if(sentry_3_ready == 1){
- u8g2.drawStr(70,60,"Sen3");
- }
- delay(10);
- u8g2.sendBuffer();
- }
- }
- //Menu state
- if (state == 3){
- antiSpamReset = 0;
- //Menu substate 1 (gamemode)
- if (menuState == 1){
- u8g2.clearBuffer();
- u8g2.setFont(u8g2_font_chroma48medium8_8r);
- u8g2.drawStr(5,7,"Select Gamemode");
- u8g2.drawStr(20,22,"Jail escape");
- u8g2.drawStr(20,52,"Agent COOP");
- u8g2.drawStr(20,37,"Take out");
- if (potVal>840){
- u8g2.drawStr(7,22,"o");
- if (buttonState==HIGH){
- gamemode=1;
- menuState=2;
- MPV=900;
- buttonState=LOW;
- }
- }
- if (potVal<840 and potVal>700){
- u8g2.drawStr(7,37,"o");
- if (buttonState==HIGH){
- gamemode=2;
- menuState=2;
- MPV=840;
- buttonState=LOW;
- }
- }
- if (potVal<700){
- u8g2.drawStr(7,52,"o");
- if (buttonState==HIGH){
- gamemode=3;
- hugeNumber=1000;
- menuState=2;
- MPV=700;
- buttonState=LOW;
- }
- }
- u8g2.sendBuffer();
- }
- //Menu substate 2 (number of things)
- if (menuState == 2){
- u8g2.clearBuffer();
- u8g2.setFont(u8g2_font_chroma48medium8_8r);
- if (gamemode == 1){
- u8g2.drawStr(5,7,"No of buttons");
- u8g2.drawStr(20,22,"1 button");
- u8g2.drawStr(20,37,"2 buttons");
- u8g2.drawStr(20,52,"3 buttons");
- }
- if (gamemode == 2){
- u8g2.drawStr(5,7,"No of sentries");
- u8g2.drawStr(20,22,"1 sentry");
- u8g2.drawStr(20,37,"2 sentries");
- u8g2.drawStr(20,52,"3 sentries");
- }
- if (gamemode == 3){
- u8g2.drawStr(5,7,"No of players");
- u8g2.drawStr(20,22,"2 players");
- u8g2.drawStr(20,37,"3 players");
- }
- if (potVal<1000 and potVal>MPV-140){
- u8g2.drawStr(7,22,"o");
- if (buttonState==HIGH){
- client.publish("groupsix/numberOfThings", "1");
- numberOfThings=1;
- MPV=MPV-140;
- menuState=3;
- buttonState=LOW;
- }
- }
- if (potVal<MPV-140 and potVal>MPV-280-hugeNumber){
- u8g2.drawStr(7,37,"o");
- if (buttonState==HIGH){
- client.publish("groupsix/numberOfThings", "2");
- numberOfThings=2;
- MPV=MPV-280;
- menuState=3;
- buttonState=LOW;
- }
- }
- if (potVal+hugeNumber<MPV-280-hugeNumber){
- u8g2.drawStr(7,52,"o");
- if (buttonState==HIGH){
- client.publish("groupsix/numberOfThings", "3");
- numberOfThings=3;
- MPV=MPV-420;
- menuState=3;
- buttonState=LOW;
- }
- }
- u8g2.sendBuffer();
- }
- //Menu substate 3 (difficulty)
- if (menuState == 3){
- u8g2.clearBuffer();
- u8g2.setFont(u8g2_font_chroma48medium8_8r);
- u8g2.drawStr(5,7,"Difficulty");
- u8g2.drawStr(20,22,"Normal");
- u8g2.drawStr(20,37,"Hard");
- u8g2.drawStr(20,52,"INSANE");
- if (potVal<1000 and potVal>MPV-140){
- u8g2.drawStr(7,22,"o");
- if (buttonState==HIGH){
- client.publish("groupsix/diff", "1");
- diff=1;
- buttonState=LOW;
- menuState=4;
- }
- }
- if (potVal<MPV-140 and potVal>MPV-280){
- u8g2.drawStr(7,37,"o");
- if (buttonState==HIGH){
- client.publish("groupsix/diff", "2");
- diff=2;
- buttonState=LOW;
- menuState=4;
- }
- }
- if (potVal<MPV-280){
- u8g2.drawStr(7,52,"o");
- if (buttonState==HIGH){
- client.publish("groupsix/diff", "3");
- diff=3;
- buttonState=LOW;
- menuState=4;
- }
- }
- u8g2.sendBuffer();
- }
- //READY? State
- if (menuState == 4){
- u8g2.clearBuffer();
- u8g2.setFont(u8g2_font_ncenB14_tr);
- u8g2.drawStr(32,20,"PRESS");
- u8g2.drawStr(35,40,"WHEN");
- u8g2.drawStr(30,60,"READY");
- u8g2.sendBuffer();
- if (buttonState == HIGH){
- state = 4;
- timeStarted=timeP;
- takeOuts = 0 ;
- buttonsPressed = 0 ; //Reset så man ikke kan snyde og trykke før tid
- resetSwitchCounter = 0;
- checkRun = 0;
- runTime = 0;
- buttonNo = 0;
- oldDirection = 10;
- newDirection = 11;
- but1Pressed = 0;
- but2Pressed = 0;
- but3Pressed = 0;
- but1CheckRun = 0;
- but2CheckRun = 0;
- but3CheckRun = 0;
- but1StartTime = 0;
- but2StartTime = 0;
- but3StartTime = 0;
- endgameCheck = 0;
- if (gamemode==2){
- if (numberOfThings==1){
- client.publish("groupsix/turretBegin", "1");
- }
- else if (numberOfThings==2){
- client.publish("groupsix/turretBegin", "2");
- }
- else if (numberOfThings==3){
- client.publish("groupsix/turretBegin", "3");
- }
- }
- else{
- client.publish("groupsix/turretBegin", "3");
- }
- client.publish("groupsix/turretBegin", "3"); //fix - den skal ændre sige efter omd e skal døøøøø
- buttonState = LOW;
- }
- }
- }
- if (state == 4){
- //Screen information
- //Overskrift
- u8g2.clearBuffer();
- u8g2.setFont(u8g2_font_chroma48medium8_8r);
- ingameTime=(timeP-timeStarted)/100;
- if (gamemode == 1){
- u8g2.drawStr(0,7,"Jail escape!");
- }
- else if (gamemode == 2){
- u8g2.drawStr(0,7,"Take out!");
- }
- else if (gamemode == 3){
- u8g2.drawStr(0,7,"Agent COOP!");
- }
- //Difficulty
- if (diff == 1){
- u8g2.drawStr(0,16,"Normal");
- }
- else if (diff == 2){
- u8g2.drawStr(0,16,"Hard ");
- }
- else if (diff == 3){
- u8g2.drawStr(0,16,"INSANE");
- }
- //Time
- u8g2.drawStr(0,30,"Time:");
- u8g2.setCursor(40, 30);
- u8g2.print(ingameTime); //evt - her kunne sættes et komma på
- //Times caught
- u8g2.drawStr(0,39,"Times caught:");
- u8g2.setCursor(105, 39);
- u8g2.print(timesCaught);
- //GAMEMODES - Special - turrets killed or buttons pressed
- //GAMEMODE 1 (Jail escape)
- if (gamemode == 1){
- if (numberOfThings == 2){
- buttonsPressed=but2Pressed;
- }
- if (numberOfThings == 3){
- buttonsPressed=but2Pressed+but3Pressed;
- }
- if (but1Pressed == 1){
- if (buttonsPressed == numberOfThings-1){
- state=5;
- }
- but1Pressed=0;
- }
- //Graphical
- u8g2.drawStr(0,48,"Pressed:");
- u8g2.setCursor(64, 48);
- u8g2.print(buttonsPressed);
- u8g2.drawStr(71,48,"/");
- u8g2.setCursor(76, 48);
- u8g2.print(numberOfThings);
- }
- //Gamemode 2 (Take out)
- if (gamemode == 2){
- u8g2.drawStr(0,48,"Take outs:");
- u8g2.setCursor(80, 48);
- u8g2.print(takeOuts);
- u8g2.drawStr(87,48,"/");
- u8g2.setCursor(92, 48);
- u8g2.print(numberOfThings);
- if (but1CheckRun == 0){
- if (but1Pressed == 1){
- client.publish("groupsix/reset", "1");
- takeOuts=takeOuts+1;
- but1CheckRun = 1;
- }
- }
- if (numberOfThings>=2){
- if (but2CheckRun == 0){
- if (but2Pressed == 1){
- client.publish("groupsix/stopTurrets", "2");
- takeOuts=takeOuts+1;
- but2CheckRun = 1;
- }
- }
- }
- if (numberOfThings>=3){
- if (but3CheckRun == 0){
- if (but3Pressed == 1){
- client.publish("groupsix/stopTurrets", "3");
- takeOuts=takeOuts+1;
- but3CheckRun = 1;
- }
- }
- }
- if (but1CheckRun+but2CheckRun+but3CheckRun==numberOfThings){
- state=5; //u8g2.drawStr(0,48,"Pressed: O O O");
- }
- }
- //Gamemode 3 (COOP)
- if (gamemode == 3){
- u8g2.drawStr(0,48,"Pressed:");
- if (but1CheckRun == 0){
- but1StartTime=timeP;
- }
- if (but1Pressed == 1){
- but1CheckRun = 1;
- if (timeP-but1StartTime>3000){
- but1Pressed = 0;
- but1CheckRun = 0;
- }
- }
- if (but2CheckRun == 0){
- but2StartTime=timeP;
- }
- if (but2Pressed == 1){
- but2CheckRun = 1;
- if (timeP-but2StartTime>3000){
- but2Pressed = 0;
- but2CheckRun = 0;
- }
- }
- if (numberOfThings==2){ //2, da det er anden selection på menuen, men faktisk betyder det at 3 knapper skal aktiveres.
- if (but3CheckRun == 0){
- but3StartTime=timeP;
- }
- if (but3Pressed == 1){
- but3CheckRun = 1;
- if (timeP-but3StartTime>3000){
- but3Pressed = 0;
- but3CheckRun = 0;
- }
- }
- }
- if (but1CheckRun == 1){
- u8g2.drawStr(70,48,"o");
- }
- if (but2CheckRun == 1){
- u8g2.drawStr(80,48,"o");
- }
- if (but3CheckRun == 1){
- u8g2.drawStr(90,48,"o");
- }
- if (but1CheckRun+but2CheckRun+but3CheckRun==numberOfThings+1){
- state=5; //u8g2.drawStr(0,48,"Pressed: O O O");
- }
- }
- //Turret controls
- //SELECT TURRET
- if (buttonState == HIGH and controlLimiter == 0){
- nowControlling=(nowControlling+1)%4;
- if (nowControlling == 1){
- client.publish("groupsix/nowControlling", "1");
- }
- if (nowControlling == 2){
- client.publish("groupsix/nowControlling", "2");
- }
- if (nowControlling == 3){
- client.publish("groupsix/nowControlling", "3");
- }
- if (nowControlling == 0){
- client.publish("groupsix/nowControlling", "0");
- }
- controlLimiter = 1;
- }
- //Alting blev spammet hvilket var hårdt for turrets. Derfor limiter
- else if (buttonState == LOW and controlLimiter == 1){
- controlLimiter = 0;
- }
- //CONTROL TURRET
- if (potVal>720){
- if (oldDirection != newDirection){
- client.publish("groupsix/turretDirections", "1");
- oldDirection = 1;
- }
- u8g2.drawStr(90,62,"SLOW");
- newDirection = 1;
- }
- if (potVal>540 and potVal<720){
- if (oldDirection != newDirection){
- client.publish("groupsix/turretDirections", "2");
- oldDirection = 2;
- }
- u8g2.drawStr(90,62,"slow");
- newDirection = 2;
- }
- if (potVal>360 and potVal<540){
- if (oldDirection != newDirection){
- client.publish("groupsix/turretDirections", "3");
- oldDirection = 3;
- }
- u8g2.drawStr(90,62,"med");
- newDirection = 3;
- }
- if (potVal>180 and potVal<360){
- if (oldDirection != newDirection){
- client.publish("groupsix/turretDirections", "4");
- oldDirection = 4;
- }
- u8g2.drawStr(90,62,"fast");
- newDirection = 4;
- }
- if (potVal<180){
- if (oldDirection != newDirection){
- client.publish("groupsix/turretDirections", "5");
- oldDirection = 5;
- }
- u8g2.drawStr(90,62,"FAST");
- newDirection = 5;
- }
- //Turret screen
- u8g2.drawStr(0,62,"Controls");
- u8g2.setCursor(73, 62);
- u8g2.print(nowControlling);
- u8g2.sendBuffer();
- }
- if(state==5){
- u8g2.clearBuffer();
- u8g2.setFont(u8g2_font_ncenB14_tr);
- u8g2.drawStr(0,20,"Finished");
- //Gamemode
- u8g2.setFont(u8g2_font_chroma48medium8_8r);
- if (gamemode == 1){
- u8g2.drawStr(0,30,"Jail escape!");
- }
- else if (gamemode == 2){
- u8g2.drawStr(0,30,"Take out!");
- }
- else if (gamemode == 3){
- u8g2.drawStr(0,30,"Agent COOP!");
- }
- //Difficulty
- if (diff == 1){
- u8g2.drawStr(90,10,"Nor");
- u8g2.drawStr(90,20,"mal");
- }
- else if (diff == 2){
- u8g2.drawStr(90,10,"Hard ");
- }
- else if (diff == 3){
- u8g2.drawStr(90,12,"INS");
- u8g2.drawStr(90,20,"ANE");
- }
- //Time
- u8g2.drawStr(0,40,"Time");
- u8g2.setCursor(40, 40);
- u8g2.print(ingameTime); //FIX
- //Caught
- u8g2.drawStr(0,50,"Times caught:");
- u8g2.setCursor(105, 50);
- u8g2.print(timesCaught);
- //play again?
- u8g2.drawStr(0,60,"Press to restart!");
- if (buzzerLimiter == 0){
- client.publish("groupsix/reset", "1");
- tone(buzzer, 1000);
- delay(70);
- noTone(buzzer);
- delay(20);
- tone(buzzer, 1000);
- delay(100);
- tone(buzzer, 1200);
- delay(100);
- tone(buzzer, 1300);
- delay(100);
- tone(buzzer, 1500);
- delay(700);
- noTone(buzzer);
- buzzerLimiter = 1;
- }
- u8g2.sendBuffer();
- if (endgameCheck == 0){
- delay(1500); //så man ikke kommer til at springe over hvis man sidder og spammer knapper
- endgameCheck = 1;
- }
- if (buttonState==HIGH){
- state=6;
- buttonState=LOW;
- }
- }
- if (state == 6){
- resetSwitchCounter = 0;
- checkRun = 0;
- runTime = 0;
- gamemode=0;
- buttonNo = 0;
- diff = 0;
- numberOfThings = 0;
- hugeNumber = 0;
- timeStarted = 0;
- nowControlling = 0;
- oldDirection = 10;
- newDirection = 11;
- but1Pressed = 0;
- but2Pressed = 0;
- but3Pressed = 0;
- buttonsPressed = 0;
- takeOuts = 0;
- but1CheckRun = 0;
- but2CheckRun = 0;
- but3CheckRun = 0;
- but1StartTime = 0;
- but2StartTime = 0;
- but3StartTime = 0;
- timesCaught = 0;
- endgameCheck = 0;
- buzzerLimiter = 0;
- menuState = 1;
- state = 3;
- if (antiSpamReset==0){ //Reset bliver meget langsomt hvis de her bare spammes
- client.publish("groupsix/reset", "1");
- client.publish("groupsix/reset", "2");
- client.publish("groupsix/reset", "3");
- client.publish("groupsix/turretBegin", "0");
- antiSpamReset=1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement