Where's Waldo? created by Chaitanya Garg and Giorgio Pizzorni
Find all 5 of the characters, press the paper where they are, a tone will play for each one found and a victory tone will play when all 5 are found (and the game resets).
We tried to 3D print a box to hold our circuitry, however the resources at the Leslie eLab were closed to us over break. Instead, we ended up soldering wires and the force sensitive resistor.
Intended user: basically anyone. A child can play it and so can an adult (it's not the easiest game if you don't cheat!).
Limitations and capabilities: assumes no limitations and capabilities of a human being
How design of toy takes above into account: requires sight and ability to press; an infant can play this game, but their strategy would probably just be random guessing
Affordances the toy offers: Press the game board for input, keep the entire game on a table, listen to sounds for output
Here is the code we used:
/**
* Interactive toy: Where's Waldo?
* Created by Chaitanya Garg and Giorgio Pizzorni
*/
#include "pitches.h"
#define THRESHOLD 100
#define TONE_TIME 500
const int fsr[5] = { A0, A1, A2, A3, A4 };
const int tones[5] = { NOTE_C5, NOTE_D5, NOTE_E5, NOTE_F5, NOTE_G5 };
const int speaker = 11;
bool activated[5] = { false, false, false, false, false };
void reset()
{
for (int i = 0; i < 5; i++)
{
activated[i] = false;
}
}
void setup()
{
Serial.begin(9600);
// initialize input/output pins
pinMode(speaker, OUTPUT);
for (int i = 0; i < 5; i++)
{
pinMode(fsr[i], INPUT);
}
}
void play(int note, int duration)
{
tone(speaker, note, duration);
}
void loop()
{
int readings[5] = { 0, 0, 0, 0, 0 };
bool pressed[5] = { false, false, false, false, false };
for (int i = 0; i < 5; i++)
{
readings[i] = analogRead(fsr[i]);
if (readings[i] > THRESHOLD)
{
pressed[i] = true;
activated[i] = true;
}
}
// if two are pressed at once, picks the "first" one based on array index
int pressed_fsr = index_of(pressed, 5, true);
if (pressed_fsr == -1)
{
// implies that no fsr was pressed
return;
}
// play tone corresponding to which fsr was pressed
play(tones[pressed_fsr], TONE_TIME);
// now check if all 5 are pressed
if (all_pressed())
{
victory();
}
}
void victory()
{
// play all 5 tones in order
for (int i = 0; i < 5; i++)
{
play(tones[i], TONE_TIME);
delay(TONE_TIME);
}
reset();
}
int index_of(bool *arr, int size, bool val)
{
for (int i = 0; i < size; i++)
{
if (arr[i] == val)
{
return i;
}
}
return -1;
}
bool all_pressed()
{
for (int i = 0; i < 5; i++)
{
if (activated[i] == false)
{
return false;
}
}
return true;
}
No comments:
Post a Comment