Permalink
Browse files

Major fixed

Added fixes for lights and changes to how the buttons operate.
  • Loading branch information...
LUTC CSNET
LUTC CSNET committed Mar 7, 2018
1 parent a3f4bc9 commit 32cb2f366ca4d9cb8cb32dbe1ce40b8a55126a6c
Showing with 59 additions and 54 deletions.
  1. +1 −1 arduino/matrix/matrix.ino
  2. +1 −1 data.json
  3. +11 −12 main.js
  4. +1 −1 python/api.py
  5. +9 −9 python/buttons.py
  6. +8 −8 python/lighting.py
  7. +18 −17 python/scoring.py
  8. +10 −5 static/index.html
2 arduino/matrix/matrix.ino 100755 → 100644
@@ -177,7 +177,7 @@ void LED(int D){
}
void getChar() {
if (Serial.available()){
if (Serial.available()){data[maxInUse] = 0; // Bad way to remove overflow
while (Serial.available()){
char data[0];
Serial.readBytes(data, maxInUse);
@@ -1 +1 @@
{"response_code": 0, "results": [{"category": "Entertainment: Video Games", "type": "boolean", "question": "Peter Molyneux was the founder of Bullfrog Productions.", "difficulty": "easy", "correct_answer": "True", "incorrect_answers": ["False"]}, {"category": "Science & Nature", "type": "boolean", "question": "Type 1 diabetes is a result of the liver working improperly.", "difficulty": "medium", "correct_answer": "False", "incorrect_answers": ["True"]}, {"category": "Science: Computers", "type": "boolean", "question": "To bypass US Munitions Export Laws, the creator of the PGP published all the source code in book form. ", "difficulty": "medium", "correct_answer": "True", "incorrect_answers": ["False"]}, {"category": "Entertainment: Video Games", "type": "boolean", "question": "Niko Bellic is the protagonist of Grand Theft Auto IV.", "difficulty": "easy", "correct_answer": "True", "incorrect_answers": ["False"]}, {"category": "Science: Computers", "type": "boolean", "question": ""HTML" stands for Hypertext Markup Language.", "difficulty": "easy", "correct_answer": "True", "incorrect_answers": ["False"]}, {"category": "Entertainment: Video Games", "type": "boolean", "question": "In the game "Subnautica", a "Cave Crawler" will attack you.", "difficulty": "medium", "correct_answer": "True", "incorrect_answers": ["False"]}, {"category": "Science: Mathematics", "type": "boolean", "question": "Zero factorial is equal to zero. ", "difficulty": "medium", "correct_answer": "False", "incorrect_answers": ["True"]}, {"category": "Science: Mathematics", "type": "boolean", "question": "In Topology, the complement of an open set is a closed set.", "difficulty": "hard", "correct_answer": "True", "incorrect_answers": ["False"]}, {"category": "Politics", "type": "boolean", "question": "George Clinton, Vice President of the United States (1805-1812), is an ancestor of President Bill Clinton.", "difficulty": "hard", "correct_answer": "False", "incorrect_answers": ["True"]}, {"category": "Entertainment: Video Games", "type": "boolean", "question": "The game "Pocket Morty" has a Morty called "Pocket Mortys Morty"?", "difficulty": "easy", "correct_answer": "True", "incorrect_answers": ["False"]}]}
{"response_code": 0, "results": [{"category": "Animals", "type": "boolean", "question": "The Axolotl is an amphibian that can spend its whole life in a larval state.", "difficulty": "easy", "correct_answer": "True", "incorrect_answers": ["False"]}, {"category": "Animals", "type": "boolean", "question": "A slug’s blood is green.", "difficulty": "easy", "correct_answer": "True", "incorrect_answers": ["False"]}, {"category": "History", "type": "boolean", "question": "The Cold War ended with Joseph Stalin's death.", "difficulty": "easy", "correct_answer": "False", "incorrect_answers": ["True"]}, {"category": "Geography", "type": "boolean", "question": "The flag of South Africa features 7 colours.", "difficulty": "medium", "correct_answer": "False", "incorrect_answers": ["True"]}, {"category": "General Knowledge", "type": "boolean", "question": "The US emergency hotline is 911 because of the September 11th terrorist attacks.", "difficulty": "medium", "correct_answer": "False", "incorrect_answers": ["True"]}, {"category": "Geography", "type": "boolean", "question": "Israel is 7 hours ahead of New York.", "difficulty": "medium", "correct_answer": "True", "incorrect_answers": ["False"]}, {"category": "Sports", "type": "boolean", "question": "Soccer player Cristiano Ronaldo opened a museum dedicated to himself.", "difficulty": "medium", "correct_answer": "True", "incorrect_answers": ["False"]}, {"category": "Entertainment: Books", "type": "boolean", "question": "The book 1984 was published in 1949.", "difficulty": "easy", "correct_answer": "True", "incorrect_answers": ["False"]}, {"category": "Entertainment: Film", "type": "boolean", "question": "The Xenomorph from the science fiction film "Alien" has acidic blood.", "difficulty": "medium", "correct_answer": "True", "incorrect_answers": ["False"]}, {"category": "Entertainment: Japanese Anime & Manga", "type": "boolean", "question": "Throughout the entirety of "Dragon Ball Z", Goku only kills two characters: a miniboss named Yakon and Kid Buu.", "difficulty": "hard", "correct_answer": "True", "incorrect_answers": ["False"]}]}
23 main.js
@@ -139,17 +139,15 @@ io.on('connection', function(socket){
socket.on('lighting', function(data){
if(typeof data != undefined){
console.log('questions');
switch (data) {
case 'update':
updateLights(socket, data.team, data.button);
case 'reset':
resetLights(socket);
break;
default:
//socket.emit('error', 'Invalid Action');
break;
}
console.log('lighting');
updateLights(socket, data.status, data.button);
}
});
socket.on('reset_lighting', function(data){
if(typeof data != undefined){
console.log('lighting');
resetLights(socket, data);
}
});
@@ -233,10 +231,11 @@ function resetScore(socket){
// Lighting
function updateLights(socket, status, button_pressed){
console.log('lighting: status - ' + status + " button -" + button_pressed);
var cmd = process.spawn("python", [lighting_file, status, button_pressed]);
cmd.stdout.on('data', function(output){
console.log(output);
console.log(output.toString());
socket.emit('lighting', output);
});
}
@@ -6,7 +6,7 @@
question = json.loads(open('data.json').read())
print json.dumps(question);
else:
url = urllib.urlopen("https://opentdb.com/api.php?amount=10&type=boolean");
url = urllib.urlopen("http://opentdb.com/api.php?amount=10&type=boolean");
question = json.loads(url.read().decode());
open('data.json', 'w').close();
@@ -1,16 +1,16 @@
from gpiozero import Button
from gpiozero import Button;
# Team A
Btn1 = Button(4,pull_up=False)
Btn2 = Button(14,pull_up=False)
Btn3 = Button(15,pull_up=False)
Btn4 = Button(25,pull_up=False)
Btn1 = Button(4,pull_up=False);
Btn2 = Button(14,pull_up=False);
Btn3 = Button(15,pull_up=False);
Btn4 = Button(25,pull_up=False);
# Team B
Btn5 = Button(11,pull_up=False)
Btn6 = Button(8,pull_up=False)
Btn7 = Button(7,pull_up=False)
Btn8 = Button(21,pull_up=False)
Btn5 = Button(11,pull_up=False);
Btn6 = Button(8,pull_up=False);
Btn7 = Button(7,pull_up=False);
Btn8 = Button(21,pull_up=False);
output = 0;
@@ -13,10 +13,10 @@
LED4 = 22;
# Team B
LED5 = 11;
LED6 = 12;
LED7 = 13;
LED8 = 15;
LED5 = 12;
LED6 = 13;
LED7 = 19;
LED8 = 16;
lights = [LED1, LED2, LED3, LED4, LED5, LED6, LED7, LED8];
@@ -48,15 +48,15 @@ def render():
output = starter;
elif (len(args) == 2):
output = starter;
output[args[1]] = 0;
output[(int(args[1]) -1)] = 0;
elif (len(args) == 3):
if (args[2] == 0):
if (args[1] == 0):
output = teamA;
elif (args[2] == 1):
elif (args[1] == 1):
output = teamB;
else:
output = starter;
output[int(args[1])] = 0;
output[(int(args[2]) - 1)] = 0;
render();
@@ -14,12 +14,12 @@
def calculate():
if (game_state == 0):
if(answer_state == 'correct'):
score[answer_team] = int(score[answer_team]) + int(10);
score[answer_team] = int(score[answer_team]) + int(1);
else:
score[answer_team] = int(score[answer_team]) - int(5);
score[answer_team] = int(score[answer_team]) - int(1);
elif (game_state == 1):
if(answer_state == 'correct'):
score[answer_team] = score[answer_team] + 5;
score[answer_team] = score[answer_team] + 1;
else:
score[answer_team] = score[answer_team];
@@ -35,34 +35,35 @@ def render():
score_a = list(str(score[0]));
score_b = list(str(score[1]));
output = [" ", " ", " ", " ", " ", " "];
output = [" ", " ", " ", " "];
i=0;
for i in range(0,5):
for i in range(0,3):
if(len(score_a) == 1):
output[0] = score_a[0];
elif (len(score_a) == 2):
output[0] = score_a[0];
output[1] = score_a[1];
elif (len(score_a) == 3):
output[0] = score_a[0];
output[1] = score_a[1];
output[2] = score_a[2];
#elif (len(score_a) == 3):
# output[0] = score_a[0];
# output[1] = score_a[1];
# output[2] = score_a[2];
if(len(score_b) == 1):
output[3] = score_b[0];
output[2] = score_b[0];
elif (len(score_b) == 2):
output[3] = score_b[0];
output[4] = score_b[1];
elif (len(score_b) == 3):
output[3] = score_b[0];
output[4] = score_b[1];
output[5] = score_b[2];
output[2] = score_b[0];
output[3] = score_b[1];
#elif (len(score_b) == 3):
# output[3] = score_b[0];
# output[4] = score_b[1];
# output[5] = score_b[2];
for j in range(0,5):
for j in range(0,4):
output_str = output_str + str(output[j]);
#print(output_str);
serPort.write(str.encode(str(output_str)));
serPort.close();
@@ -176,7 +176,7 @@ <h1 id="answer"></h1>
docount();
question_fetch();
lighting_reset();
buttons_listen();
is_active = false;
@@ -226,7 +226,7 @@ <h1 id="answer"></h1>
// Lighting
function lighting_reset(){
socket.emit('lighting', 'reset');
socket.emit('reset_lighting', team);
}
// Buttons
@@ -247,7 +247,11 @@ <h1 id="answer"></h1>
document.getElementById(field_score + "_" + 0).innerHTML = data[0];
document.getElementById(field_score + "_" + 1).innerHTML = data[1];
});
socket.on('lighting', function(data){
console.log('lighting');
});
socket.on('lights', function(data){
for (var i=1; i<=players; i++){
document.getElementById(field_lights + "_" + i).innerHTML = data[i];
@@ -257,6 +261,7 @@ <h1 id="answer"></h1>
socket.on('buttons', function(data){
if(data != "0"){
socket.emit('lighting', {status: team, button: data});
console.log("Button: " + data + "pressed");
charStr = data;
is_active = true;
@@ -293,7 +298,7 @@ <h1 id="answer"></h1>
}
else
{
socket.emit('lighting', {status: team, button: data});
/* socket.emit('lighting', {status: team, button: data}); */
}
}
else if (team == 0)
@@ -303,7 +308,7 @@ <h1 id="answer"></h1>
}
else
{
socket.emit('lighting', {status: team, button: data});
/* socket.emit('lighting', {status: team, button: data}); */
}
}
else

0 comments on commit 32cb2f3

Please sign in to comment.