Skip to content

Commit

Permalink
Major fixed
Browse files Browse the repository at this point in the history
Added fixes for lights and changes to how the buttons operate.
  • Loading branch information
LUTC CSNET committed Mar 7, 2018
1 parent a3f4bc9 commit 32cb2f3
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 54 deletions.
2 changes: 1 addition & 1 deletion arduino/matrix/matrix.ino
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion data.json
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 12 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down Expand Up @@ -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);
});
}
Expand Down
2 changes: 1 addition & 1 deletion python/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 9 additions & 9 deletions python/buttons.py
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
16 changes: 8 additions & 8 deletions python/lighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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();

Expand Down
35 changes: 18 additions & 17 deletions python/scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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();

Expand Down
15 changes: 10 additions & 5 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ <h1 id="answer"></h1>
docount();
question_fetch();


lighting_reset();
buttons_listen();

is_active = false;
Expand Down Expand Up @@ -226,7 +226,7 @@ <h1 id="answer"></h1>

// Lighting
function lighting_reset(){
socket.emit('lighting', 'reset');
socket.emit('reset_lighting', team);
}

// Buttons
Expand All @@ -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];
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -303,7 +308,7 @@ <h1 id="answer"></h1>
}
else
{
socket.emit('lighting', {status: team, button: data});
/* socket.emit('lighting', {status: team, button: data}); */
}
}
else
Expand Down

0 comments on commit 32cb2f3

Please sign in to comment.