Added main file which counts the goals

This commit is contained in:
BuildTools 2016-07-09 19:48:08 +02:00
commit 9b44c84696

76
main.cpp Normal file
View File

@ -0,0 +1,76 @@
#include "Homie.h"
int red = 0;
int blue = 0;
unsigned long lastThingDone = 0;
int lastOne = 0; //0 nobody; 1 blue; 2 red;
HomieNode nodeGoal("goals", "goals");
void homieLoop(){
if(digitalRead(12) == LOW && digitalRead(13) == LOW){
digitalWrite(14, LOW);
}
if(digitalRead(12) == LOW){
blue = 0;
red = 0;
lastOne = 0;
Homie.setNodeProperty(nodeGoal, "reset", "true", false);
lastThingDone = millis();
delay(500);
}
else if(digitalRead(13) == LOW){
if(lastOne == 1){
--blue;
lastOne = 0;
Homie.setNodeProperty(nodeGoal, "blue", String(blue), false);
delay(500);
}
else if(lastOne == 2){
--red;
lastOne = 0;
Homie.setNodeProperty(nodeGoal, "red", String(red), false);
delay(500);
}
lastThingDone = millis();
}
else if(digitalRead(5) == HIGH){
++red;
Homie.setNodeProperty(nodeGoal, "red", String(red), false);
lastOne = 2;
lastThingDone = millis();
delay(500);
}
else if(digitalRead(4) == HIGH){
++blue;
Homie.setNodeProperty(nodeGoal, "blue", String(blue), false);
lastOne = 1;
lastThingDone = millis();
delay(500);
}
else if((millis() - lastThingDone) >= 300000){
digitalWrite(14, LOW);
}
}
void setup(){
pinMode(5, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(14, OUTPUT);
pinMode(12, INPUT_PULLUP);
pinMode(13, INPUT_PULLUP);
digitalWrite(14, HIGH);
Homie.registerNode(nodeGoal);
Homie.setFirmware("Table Soccer GoalCounter", "1.0");
Homie.setLoopFunction(homieLoop);
Homie.setup();
}
void loop() {
Homie.loop();
}