~josealberto4444/arduino-quiz

b75190a627f8830546ddf828f6202fd18742bfb5 — josealberto4444 3 years ago e27b606 master
Add all the documentation

Yes, I should have done that sooner. Life...
2 files changed, 64 insertions(+), 3 deletions(-)

A README.md
M quiz/quiz.ino
A README.md => README.md +61 -0
@@ 0,0 1,61 @@
# Quiz

This was inspired as a question-and-answer game intended to keep running at home all day long. The idea is having the device at the living room, so when you pass, it asks for your attention and shows you a question related with physics. Then you can make the calculations (questions are not easy since they are the same as in exams) and reply calmly with an infrared remote controller.

## Instructions

You should clone this repository and simply upload the Arduino program to your Arduino board. You will need to change the values for remote controlling since they are remote-dependent. Also, the libraries [LiquidCrystal\_I2C](https://hmario.home.xs4all.nl/arduino/LiquidCrystal_I2C/) and [IRremote](https://github.com/z3t0/Arduino-IRremote) are needed (you can install both from Arduino IDE library manager). Tweak IRremote for using timer1 instead of timer2, or it will conflict with tone function (at the moment of writing, this is done uncommenting line 194 and commentind 195 in `boarddefs.h` file).

For hardware:

- Buzzer: attached to pin 8 using a 100 Ω resistance and ground.
- IR receptor: attached to pin 10, 5 V source and ground.
- Motion sensor: attached to pin 2, 5 V source and ground.
- LCD: connected via I2C using pins SDA and SCL, and attached to 5 V source and ground.

## Features

It has a motion sensor to detect when there are people nearby, so it greets you (with sound, blinking the screen and a message) and shows you a question. It keeps on while it detecs activity (either motion or interaction via remote control), with a certain timeout that can be set.

You can change the scrolling direction of the text (vertically or horizontally) with a button of the remote. You can also pause the scrolling.

Of course, you can answer the questions, and it will tell you if that was correct or not (currently there are only two questions introduced as a demonstration) both in the screen and with sound.

### At programming level

This is a project where you can learn how to make multi-tasking with Arduino, as you can see a lot of code running concurrently. Also, all the questions and answers are stored in flash memory, so you can use it for saving space in your own project (isn't free software great?). You have several perifericals working at the same time and you can see that some modifications in timers are necessary or there will be conflics (as I mentioned before). Debugging mode is also used (with serial communication).

## Missing features

There were some ideas that I couldn't finish on time (this was the final work for an Arduino course I did online, I had no idea of Arduino two months ago):

- Multi-player support: asking first of all who you are and then letting you answer the question, with points associated with every player.
- A kind of manual scrolling of the text, using the remote arrows for moving the text.
- Being able to change more scrolling parameters, as speed or amount of characters in every step.
- Saving those parameters for every player.
- Maybe it's a good idea to store the questions in an SD card as flash memory is not so big (32 KiB in Arduino Uno).
- It'd also be nice to select one of them randomly every time the Arduino board starts.

## Copyright and licence

Copyright © 2018 José Alberto Orejuela García (josealberto4444)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

### Additional permission under GNU AGPL version 3 section 7

If you modify this program, or any covered work, by linking or combining it
with LiquidCrystal\_I2C (or a modified version of that library), containing
parts covered by the terms of LiquidCrystal\_I2C's license, the licensors of
this program grant you additional permission to convey the resulting work.

M quiz/quiz.ino => quiz/quiz.ino +3 -3
@@ 26,6 26,7 @@
// simulator). The purpose is to have a screen where some questions will appear,
// and answer them with a remote control.


#include <LiquidCrystal_I2C.h>  // Unlicensed, then non-free, so that's the reason for that additional permission in the preamble.
#include <IRremote.h>           // LGPL-2.1 (great, no problem).
// IMPORTANT: Tweak IRremote library for using timer1 instead of timer2, or it


@@ 33,6 34,7 @@
// ATmega328), this is done (at the moment of writing) uncommenting line 194 and
// commentind 195 in boarddefs.h file.


// Set-up variables
const byte motionPin = 2;          // Motion sensor pin.
LiquidCrystal_I2C lcd(0x27,16,2);  // LCD address and size.


@@ 42,6 44,7 @@ decode_results results;
char message[64];                  // Displaying message, will be populated from FLASH memory.
//#define _DEBUG 0                 // Uncomment to get debugging messages via serial port in certain steps.


// State-recording variables
volatile bool motion = false;     // Is there any movement that should turn on the device?
bool screenState = false;         // Is the screen actually on?


@@ 78,9 81,6 @@ class Scroller {
  // 
  // If scrolling horizontally, charStep is  the amount of characters in every
  // step.
  // 
  // TODO: A kind of manual scrolling, using the remote to move the text.
  // TODO: Change in charStep and speed, saving it for every player (TODO: multi-player support XD ).
  unsigned short counter;
  const String spaceFilling = "                ";
  unsigned long prevMillis;