Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
## SparkFun Useful stuff
#################

## Emacs Temp Files
*~
\#*\#

## AVR Development
*.eep
*.elf
Expand Down
205 changes: 205 additions & 0 deletions Code/James_Bond_Bomb_Game.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
/*
*******************************************************************************************************
******** JAMES BOND BOMB GAME **********************
*******************************************************************************************************
*/

/*
* Author: Matthew Lind
* Github: https://github.com/MatthewCLind/James-Bond-Bomb-Game
* This goes along with a YouTube video: https://youtu.be/jQ43RBiS8FQ
*
* License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
*
* Non-license requests:
* -Please leave this comment block in, I'd appreciate it
* -Also, please feel to reach out to me with comments and questions,
* and also to share anything cool you do with this code!
*
* This code replicates a bomb-diffusing game. It uses a couple of LEDs to show the bomb's state and some jumper wires
* that you can cut to disarm the bomb --or not--
*
* The purpose of this code is first to show a tidy way to program sketches using defined states rather than if/else trees to
* determine behavior. This code is also useful as a template for games and puzzles e.g. in an escape room setting
*
*/

// STATE VARIABLES
const int STANDBY = 0;
const int COUNTDOWN = 1;
const int ZAPPING = 2;
const int DISARMED = 3;

//LED PINS
const int ZAP_LED = 10;
const int COUNT_LED = 11;

//WIRES
const int NUM_WIRES = 4;
const int WIRE_PINS[NUM_WIRES] = {3, 4, 5, 6};
const int CORRECT_WIRE = 5;

//TIME
const long BOMB_TIME = 30000L; //30 seconds before you get what's coming to you!

/*
Standby mode
default state, wait for bomb to be armed

-Both LEDs off
-Counting down = false

-Can move to countdown mode once all wires are inserted
*/
int standby_func()
{
int next_state = STANDBY;

digitalWrite(ZAP_LED, LOW);
digitalWrite(COUNT_LED, LOW);

boolean all_wires_inserted = true;
for(int i = 0; i < NUM_WIRES; i++)
{
// input pullup
all_wires_inserted = all_wires_inserted && digitalRead(WIRE_PINS[i]) == LOW;
}

if(all_wires_inserted)
{
next_state = COUNTDOWN;
}

return next_state;
}


/*
Countdowm mode
the main part of the game where the clock starts ticking down. Players must disarm during this state

-Counting down = true
-Zapping LED is off
-Counting-down-LED is blinking

-Can move to Zapping mode when time runs out or any wrong wire is pulled
-Can move to disarmed mode when correct wire is pulled
*/
int countdown_func()
{
int next_state = COUNTDOWN;
static long time_to_die = 0;

//first time in this function
if(time_to_die == 0)
{
time_to_die = millis() + BOMB_TIME;
}

//flash the COUNT_LED to indicate that time is running out
digitalWrite(ZAP_LED, LOW);
static boolean blink_on = true;
int blink_duration = 500;
static long next_blink = millis() + blink_duration;
if(millis() > next_blink)
{
blink_on = !blink_on;
next_blink = millis() + blink_duration;
}
digitalWrite(COUNT_LED, blink_on);

//look for incorrect wire pulls, which means you blow up
boolean any_wrong_wire_pulled = false;
for(int i = 0; i < NUM_WIRES; i++)
{
any_wrong_wire_pulled = any_wrong_wire_pulled || (digitalRead(WIRE_PINS[i]) == HIGH && WIRE_PINS[i] != CORRECT_WIRE);
}

if(millis() > time_to_die || any_wrong_wire_pulled)
{
//You done lost
next_state = ZAPPING;
time_to_die = 0;
}
else if(digitalRead(CORRECT_WIRE) == HIGH)
{
//You did it!
next_state = DISARMED;
time_to_die = 0;
}

return next_state;
}

/*
Zapping mode
the "you lost" state

-Zapping LED is on and angry
-Counting-down LED is off

-Cannot move to any other state. u ded. Though, you might want to change this if you want to play multiple times in a row
*/
int zapping_func()
{
int next_state = ZAPPING;

digitalWrite(ZAP_LED, HIGH);
digitalWrite(COUNT_LED, LOW);

return next_state;
}


/*
Disarmed mode
"You win" state

-Counting-down LED is on solid
-Zapping LED is off

-Can move to standby mode when all wires are pulled out
*/
int disarmed_func()
{
int next_state = DISARMED;

digitalWrite(COUNT_LED, HIGH);
digitalWrite(ZAP_LED, LOW);

boolean all_wires_pulled = true;
for(int i = 0; i < NUM_WIRES; i++)
{
all_wires_pulled = all_wires_pulled && digitalRead(WIRE_PINS[i]) == HIGH;
}

if(all_wires_pulled)
{
next_state = STANDBY;
}

return next_state;
}



void setup()
{
pinMode(ZAP_LED, OUTPUT);
pinMode(COUNT_LED, OUTPUT);
for(int i = 0; i < NUM_WIRES; i++)
{
pinMode(WIRE_PINS[i], INPUT_PULLUP);
}
}

//Define the function-pointer array
typedef int (* Generic_State_Function_Array)();
Generic_State_Function_Array Bomb_States[4] = {standby_func, countdown_func, zapping_func, disarmed_func};

void loop()
{
static int next_state = 0;
next_state = Bomb_States[next_state]();
}

2 changes: 1 addition & 1 deletion Code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ Code samples from one of your personal projects is preferred, though the followi
Additional points
------------------

* Samples will be read, not executed.
* Samples will be read, not executed.
* Less is more
* This must be your original work. Any partial contributions from others should be attributed.
58 changes: 58 additions & 0 deletions Documentation/Guitar_Tuning_By_Ear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Guitar Tuning By Ear
================
**Assumptions**
> This is a basic guide for getting started with tuning your guitar by ear. It assumes that you have experience tuning a guitar with an electronic tuner, and that you know the basics of guitar playing.

The Gist
-----------

1. Find a source you trust, or, if there is none, tune relative to your low E-string
2. Always tune *up* to the target pitch
3. Try plucking in different ways
4. Listen for the **audio beats** to slow down as your string becomes in-tune
5. Check intonation by playing some open chords, like E

Steps
-------
### 1. Pick your tone source
There's an unlimited number of options here. Use a piano, a keyboard, another guitar, or search online for "online guitar tuner".

If you have no other source to tune to, you can always tune relative to your low E-string. If it has been a long time, go ahead and tune the low E-string up a touch to approximately make up for the strings stretching out.
You can use the 5th-fret on the lower string to produce the next string's note (4th-fret in case of the G and B-strings). You can also use the harmonic over the 5th fret on the lower string to produce the harmonic over the 7th fret on the higher string (again, except for the G and B-strings). Also consider simply playing a string open with its neighbor and listening for the chord to become in-tune.

### 2. De-tune your string slightly
It is easier to tune *up* to your target note than it is to tune down. So, the first thing you should do is tune down a little bit.

This is more a matter of mechanics than anything else. Tuning up keeps a smooth amount of tension on the tuning mechanism which allows you to have finer control. This also will keep your string in tune longer since it shores up the slop in-between the gears which might otherwise give-way after a short amount of playing.

### 3. Pluck in different ways

While tuning, consider trying to pluck in a few different ways to emphasize different timbres. Use a pick, your finger, or your finger-nail to achieve different attacks. Also try playing nearer to, or farther away from the bridge.

### 4. Tune up, listening for the audio beats to slow down

The clearest sign that you are close to being in tune, but you are not yet, is listening for the [audio beats](https://en.wikipedia.org/wiki/Beat_%28acoustics%29). This is a wave phenomenon where two nearly-identical waves produce a 3rd tone by periodically cancelling each other out. It can sound like a "wah-wah", almost a click noise, or another note.

Your goal while tuning is to get the audio beat to drop in frequency (make the "wah-wah" slow down, the clicks spread out, or the note drop in pitch. Mathematically speaking, perfect intonation means the beat has an infinitely long period. Nice.

### 5. Play a couple of chords

Once you've gone through each string, make sure that the strings sound good together. Play a few open chords, like an E-major chord. Sometimes you'll notice a sour note. Often, you'll be reminded of how beautiful an in-tune guitar sounds.


Motivation
--------------
>*Why bother tuning by ear when I have a perfect electronic tuner?*

Good question.
There's two reasons: it is practical, and it makes you a better musician.

Practicality is obvious - maybe you run out of batteries or forget your tuner. Tune by ear. Done.

Greater musicianship may be less obvious, and it is far more important. Tuning by ear means training your ear. When you first start out, you can't hear how out of tune your guitar is, in the same way I can't taste "hints of coriander and black pepper" that a sommelier insists is there.

Over time, you will acquire the taste of intonation. You'll begin to hear if your guitar is out of tune by simply playing one chord. Then you'll be able to hear whether you are in tune with other instruments. If you like to sing, you'll better notice when your voice isn't quite hitting the right notes, and you'll be able to better appreciate when it is. When you bend a string, you'll bend to an actual note, rather than to a vague upward direction.

I said the practicality is obvious. Then again, maybe there is more to it. When you go to play a duet with a pianist, do you expect the piano to be in agreement with your electronic tuner? Just like guitar strings, piano strings drop in pitch over time. If you want to play perfectly in tune, you'll have to use your ear.

These benefits are gradual, subtle, and take time. That's ok, because the cost is maybe 2 minutes each time you tune your guitar. Soon enough, you'll be able to tune your guitar just as fast by ear.
2 changes: 1 addition & 1 deletion Documentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Requirements
Additional points
------------------

* How-to guides will be read, not executed.
* How-to guides will be read, not executed.
* Less is more (clear, concise information is the best)
* This must be your original work. Any partial contributions from others should be attributed.

Expand Down
Loading