Skip to content
Snippets Groups Projects
Commit 829b5cb0 authored by Václav Aubrecht's avatar Václav Aubrecht
Browse files

added description, removed garbage

parent f931bf86
No related branches found
No related tags found
No related merge requests found
//Toto je dementní selftest, kde půlka esenciálních informací jistě chybí
#include "LedControl.h"
//Konfigurace segmentů, protože jistý Václav Aubrecht se slepej
const int s1 = 0;
const int s2 = 1;
const int s3 = 3;
......@@ -12,7 +8,7 @@ const int s6 = 2;
const int s7 = 6;
const int s8 = 7;
//Inicializace SPI pro instanci LedControl ic
//Inicializace SPI
LedControl lc=LedControl(11, 13, 9 ,1);
unsigned long delaytime=250;
......@@ -82,7 +78,7 @@ void setup() {
*/
void intro() {
while(true) {
while(true) { //Když bude alespoň jedno tlačítko LOW, hra se spustí.
lc.setRow(0, s3, P);
lc.setRow(0, s4, r);
lc.setRow(0, s5, E);
......@@ -174,33 +170,29 @@ void question(){
int digit1;
int digit2;
number1 = random(0, 10);
number1 = random(0, 10); //Vygeneruje číslo z malé násobilky
number2 = random(0, 10);
lc.setDigit(0, s1, number1, false);
lc.setDigit(0, s2, number2, false);
correctanswerindex = random(1, 4);
Serial.println(correctanswerindex);
Serial.println(" ");
correctanswerindex = random(1, 4); //Určí, u které dvojice segmentů bude správná odpověď.
if(correctanswerindex ==1){ //OPTION 1
Serial.println("option1 = true");
option1 = number1*number2;
option1 = number1*number2; //Vytáhne z výsledku cifry a vypíše je do segmentů.
digit1 = option1/10;
digit2 = option1%10;
lc.setDigit(0,s3,digit1,false);
lc.setDigit(0,s4,digit2,false);
}
else{
Serial.println("option1 = false");
while(true){
while(true){ //Vygeneruje jiné číslo, než je výsledek a vypíše je do segmentů.
option1 = random(0,10)*random(0,10);
if((number1*number2) != option1){
break;
}
}
digit1 = option1/10;
digit1 = option1/10;
digit2 = option1%10;
lc.setDigit(0,s3,digit1,false);
lc.setDigit(0,s4,digit2,false);
......@@ -209,7 +201,6 @@ void question(){
if(correctanswerindex ==2){ //OPTION 2
Serial.println("option2 = true");
option2 = number1*number2;
digit1 = option2/10;
digit2 = option2%10;
......@@ -217,10 +208,9 @@ void question(){
lc.setDigit(0,s6,digit2,false);
}
else{
Serial.println("option2 = false");
while(true){
option2 = random(0,10)*random(0,10);
if((number1*number2) != option2 && option2 != option1){
if((number1*number2) != option2 && option2 != option1){ //Vyjede číslo, které není výsledek a není možnost 1 a vypíše ho.
break;
}
}
......@@ -232,7 +222,6 @@ void question(){
delay(25);
if(correctanswerindex ==3){ //OPTION 3
Serial.println("option3 = true");
option3 = number1*number2;
digit1 = option3/10;
digit2 = option3%10;
......@@ -240,10 +229,9 @@ void question(){
lc.setDigit(0,s8,digit2,false);
}
else{
Serial.println("option3 = false");
while(true){
option3 = random(0,10)*random(0,10);
if((number1*number2) != option3 && option3 != option1 && option3 != option2){
if((number1*number2) != option3 && option3 != option1 && option3 != option2){ //Vyjede číslo, které není výsledek a není možnost 1 ani 2 a vypíše ho.
break;
}
}
......@@ -252,7 +240,7 @@ void question(){
lc.setDigit(0,s7,digit1,false);
lc.setDigit(0,s8,digit2,false);
}
Serial.println(" ");
}
void buttoncheck(){
......@@ -270,11 +258,10 @@ void buttoncheck(){
if(digitalRead(button1) ==LOW){
if(correctanswerindex == 1){ //BUTTON 1
lc.clearDisplay(0);
Serial.println("button1 pressed");
points = points +1;
points_temp = points;
points = points +1; //Připíše 1 bod.
points_temp = points; //Přepíše body do proměnné point_temp.
digit6 = points_temp%10;
digit6 = points_temp%10; //Rozloží hodnotu v point_temp na cifry.
points_temp = points_temp/10;
digit5 = points_temp%10;
points_temp = points_temp/10;
......@@ -287,7 +274,7 @@ void buttoncheck(){
digit1 = points_temp%10;
points_temp = points_temp/10;
lc.setDigit(0,s3,digit1,false);
lc.setDigit(0,s3,digit1,false); //Vypíše je.
lc.setDigit(0,s4,digit2,false);
lc.setDigit(0,s5,digit3,false);
lc.setDigit(0,s6,digit4,false);
......@@ -297,10 +284,10 @@ void buttoncheck(){
break;
}
else{
points =0;
points =0; //Vynuluje body.
lose =1;
lc.clearDisplay(0);
lc.setRow(0, s6, n);
lc.setRow(0, s6, n); //vypíše "nah".
lc.setRow(0, s7, A);
lc.setRow(0, s8, H);
break;
......@@ -310,7 +297,6 @@ void buttoncheck(){
if(digitalRead(button2) ==LOW){
if(correctanswerindex == 2){ //BUTTON 2
lc.clearDisplay(0);
Serial.println("button1 pressed");
points = points +1;
points_temp = points;
......@@ -351,7 +337,6 @@ void buttoncheck(){
if(digitalRead(button3) ==LOW){
if(correctanswerindex == 3){ //BUTTON 3
lc.clearDisplay(0);
Serial.println("button1 pressed");
points = points +1;
points_temp = points;
......@@ -393,14 +378,14 @@ void buttoncheck(){
void loop() {
intro();
while(true){
while(true){
question();
delay(100);
buttoncheck();
if(lose ==1){
lose =0;
delay(1000);
break;
break; //Když se odpoví špatně, pokračuj za while loop.
}
lc.clearDisplay(0);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment