Introduction: Bell Model 202 Bluetooth Telephone (1930-2018)
Using the magic of Arduino, I revived an antique Bell model 202 telephone and added Bluetooth capability to it.
There are two parts to this. On one end I have an ancient phone from the 1930's. On the other end, I have one of a dozen "name tags" with hidden LEDs. When a person dials the correct number on the phone, a bluetooth connection is made to a name tag pinned to a person's lapel. When the connection is made, the phone plays a funny message and the name tag flashes in all sorts of crazy colors.
As Arduino projects go, this one is quite complicated but full of gems. This Instructable will show you how to do all of the following:
- Capture numbers dialed on a rotary telephone.
- Debounce noisy switches.
- Play sounds found on an SD Card wired to an Arduino.
- Arduino bluetooth with a Bluno Nano and Buno Beetle.
- Serial connection between two Arduinos using only two digital pins.
- Gently glow an LED so it feels relaxing and "natural". (An extremely nice feature often overlooked in designs.)
- Wildly blink an orchestra of colors in an interesting attention-grabbing pattern.
I created this as a Christmas game. The game is all about matching a present to a person. Gifts under the Christmas tree are labeled with a 6-digit "phone number". Someone dials the phone. Magic bluetooth signals talk to a name tag hanging from a person's shirt. If your name tag lights up like crazy, the gift is for you -- go ahead and open it!
If you enjoy "escape room" experiences you will enjoy this. If you've never heard of "escape room" I'm sure you will like it too!
You can find all 30+ years of these kinds of gadgets from Christmases past at madwrapper.com .
Step 1: Phone Parts
Phone Parts
- Bell model 202 telephone (or any dial telephone from 1930 to 1970)
- Antique wooden Cigar box
- DF Robot Bluno Nano (DF Robot)
- Deek-Robot Nano Terminal adapter (Amazon)
- SPI Micro SD Card Reader (Amazon)
- Micro SD Card (Amazon)
- 220 Ohm resistor (connected to the headset speaker)
- 2x 10K Ohm resistors (connected to phone dial)
- Female power jack (Amazon)
- 5V (or up to 12V) power supply (Amazon)
Step 2: Name Tag Parts
This is the list of items to make one name tag. I made 10 of them.
(Note: I short-circuited one of mine rendering it partially dysfunctional. Plan ahead: maybe order an extra one or two blunos or come up with a plan "B" in case you break one too!)
- DF Robot Bluno Beetle (DF Robot)
- 4x 100 Ohm Resistors (Amazon)
- Blue wearable LED (Amazon)
- Red wearable LED (Amazon)
- Yellow wearable LED (Amazon)
- Green wearable LED (Amazon)
- 9V Double capacity (1200mAh) Lithium Battery (Amazon)
- 9V Battery connector (Amazon)
- Miniature switch (Amazon)
- A 2cmx8cm proto board (cut in half) (Amazon)
- Name tag holder with clip (Amazon)
- Avery 5141 "Hello my name is" Name Tag (Amazon)
Step 3: Wiring the Phone
The arduino inside the phone needs to perform all of the following tasks. This section describes how to wire everything together.
- Turn on the Arduino when someone picks up the headset
- dial the phone
- grab sounds from an SD Card
- play sounds on the headset speaker
Schematics
Attached are schematics both as raw images and in Fritzing format. You can download the Fritzing app here: fritzing.org
Dialing and Power Switches
There are three switches inside the phone that need to be connected.
- "On-hook" switch that applies power to Vin on the Bluno Nano.
- When the receiver is placed on the hook, this switch is disconnected.
- "Actively Dialing" switch that indicates that the wheel is not in its home position. This is wired to cause pin D8 to be +5v when active and 0v when not.
- On my phone this switch is normally connected when the phone is in its resting position. As soon as the user starts moving the dial, the switch disconnects. I attached one end to ground on the Arduino. I connected the other end to D8 on the arduino. D8 is also connected to a 10K Ohm resistor to +5. This configuration generates a "high" enable signal to tell the Sketch program it is time to start counting pulses.
- (On some other phones this switch is normally disconnected when the dial is "resting". If you have that type of phone you will need to wire it opposite from mine: one end to +5, other end to D8 and a 10K resistor that goes to ground.)
- "Pulse" switch that generates a pulse every time the dial passes a number as it travels from release back to the home position. This is wired to generate +5V pulses on pin D7.
- On my phone this switch is normally connected when the dial is "resting". After the user releases the wheel this switch disconnects each time it passes a number. I attached one end to ground on the Arduino. I connected the other end to D7 on the arduino. D7 is also connected to a 10K Ohm resistor that leads to +5 causing the pin to be pulled high when the switch disconnects. This configuration generates "high" pulses for the Sketch program to count.
- (On some other phones, this switch is normally disconnected when the dial is "resting". If you have that type of phone you will need to wire it opposite from mine: one end to +5, other end to D7 and a 10K resistor to ground.)
I did not add any special circuitry such as a capacitor for debouncing. I handled this with software. Every time the switch opens or closes, you will get a bunch of spikes of electricity (++++-+-+-+-+-+-------) until it settles. The software just waits until the value on the input pin settles to one voltage or another for a long enough period of time before deciding that the state has actually changed.
The Earpiece Speaker
The output pin for generating sound needs to be a pin with PWM capability. Additionally, depending on which Arduino you are using, you may need to pay attention to the timer needed for running the PWM and possibly enable it. Pin D9 on the Arduino Nano (Bluno Nano in my case) is a good default choice since this is configured correctly by default.
There are three wires that go into the headset. Simplifying, these are: ground, earpiece, and mouthpiece. It's not quite that simple since the earpiece and mouthpiece are loosely connected. I put my voltmeter to "on" position for measuring resistance. In this mode the voltmeter generates a small amount of electricity that produces a "static" scratchy sound in the earpiece when you probe the correct two terminals.
Connect one terminal to ground. Connect the other terminal to a 220 Ohm resistor that leads to D9 PWM pin. This was perfect for the sound level I wanted in the standard telephone earpiece speaker.
(If you want to create a "speaker phone", you will need to add some extra circuitry to amplify the sound into an external speaker for all to hear. I did not do this in my implementation but would have been a nice enhancement.)
(If you want to add volume control, you can connect a potentiometer to one of the analog input pins and adjust sound level based on input voltage reading.)
Micro SD Card SPI
SPI is straightforward to wire into the Arduino Nano. GND to GND, +5 to +5, MISO to MISO, MOSI to MOSI, and SCK to SCK. I used pin D4 as my select pin so: D4 to CS. (If you are using a 5v Arduino such as a Nano, make sure you use a 5v SD Card controller.)
Wires
I cut a section of cat-5 Ethernet cable and ran it from the connectors on the phone through a hole drilled into the base down to the Arduino housed underneath in a cigar box. The 8 wires in the Ethernet cable were more than enough for my connections and should be enough for any standard dial phone. 8 wires were over-kill for me since I connected all grounds together inside the phone and only ran one ground down to the Arduino. I did not need to run a +5 wire up to the phone, but you may find it necessary to do that if you use a different type of phone. Either way, 8 wires should be more than enough for almost any project.
I also drilled a small hole in the back of the cigar box which allowed me to pass a power cable in after I cut the end off it. The end is spliced back together inside the box then connected to the power supply.
Expose the USB Connector for Programming
I completely wrapped the Nano with electrical tape, leaving only the USB connector exposed and accessible for programming. If you decide to leave the USB cable inside the box even when you are not programming, you must ensure that the end of the cable is isolated from all electrical parts. Static electricity will mess up the electronics causing strange things to happen such an unexpected resets or worse.
Analog pin A0
Note: do not connect anything to pin A0. This pin is used to seed the random number generator so it needs to float unconnected.
Optional: two Arduinos to offload sounds
I've provided a schematic if you need to offload sounds to a second Arduino. Do this if you run out of RAM or need to boot faster. A standard Arduino Nano handles the sound. A Bluno Beetle handles dialing and Bluetooth connection.
Wire the two Arduinos together: D2 to D2, and D3 to D3.
Step 4: Wiring the Name Tag
The wiring diagram for the electronics inside the name tag is fairly simple: just a few LEDs, a switch and a battery. The "wearable" LEDs are a little tricky to work with. My wire wrap tool came in handy here.
Before You Begin
Before wiring the Bluno Beetle name tags, I recommend pre-programing each one so they flash all Digital pins (D2, D3, D4, D5) in sequence at startup. (Define START_WITH_BLINK in the provided Sketch, or write your own simple Sketch to do this.) This will allow you to test for bad solder connections immediately after assembly.
Wire Wrap and Solder the LEDs
- Solder all four resistors to the pins D2, D3, D4, and D5
- Clip off the leads from the back of the circuit board.
- Clip off the resistor leads to leaving about an inch (2cm)
- Solder a bare lead to the ground leaving 1.5 to 2 inches (3-4cm).
- Use a wire wrap tool, wrap the red wire of the green LED to the D2 resistor and solder it into place
- Wire wrap the black lead to the ground pin.
- Repeat steps 5 and 6 for the Blue LED, yellow LED, and red LED.
- Verify that no pins are accidently touching a neighbor.
- Verify again.
- Plug in the USB cable to a charger power outlet and verify that all four LEDs flash in the correct order on startup.
- If everything appears to be connected properly, slide a piece of heat-shrink tubing over each exposed pin including the ground pin and shrink it so it is snug. I used my soldering iron to accomplish this. That works but a heat-shrink gun (aka hot "blow dryer") would be a better choice if you have one.
Solder the Switch and Battery
- Cut a breadboard to roughly 3" x .5" (5cm x 1cm) (about half the height of the box the Bluno Beetle arrived in.
- Solder the switch in the top three holes of the breadboard.
- Solder one end pin.
- make sure both ends of the switch are snug with the breadboard and potentially resolder the first pin if needed.
- Solder the other two switch pins to the breadboard.
- On the back of the circuit board: solder the positive end (red wire) of the battery connector to the top pin of the switch. (Solder to the breadboard so it is connected to the top pin.)
- Solder the negative end (black wire) of the battery to a ground hole on the Bluno.
- Cut, strip, and solder a red wire to the middle pin of the switch. (Solder to the back of the breadboard for electrical connection to the switch.)
- Thread the wire through a couple of holes for strain relief.
- Solder the other end of the red wire to VIN hole on the Bluno so 9 Volts will be applied to VIN when the switch is on.
- Verify that there are no crossed wires.
- Connect a battery and test to make sure the Bluno powers on and blinks when the switch is on.
- Wrap electrical tape to cover the entire breadboard.
- Wrap the Bluno with electrical tape until you are happy with wire strain relief and isolated connections.
- Leave an opening for connecting the USB cable for future programming.
- Turn it on and test again.
Attachments
Step 5: Packaging the Name Tag
These are the steps to packaging the wearable name tag inside the box the Bluno Beetle came in.
- Cut a rectangular hole for the switch with sharp scalpel Exacto knife
- Place the switch and circuit board into the box and press it against the side to find the right pace to cut the hole.
- Jam switch into place using foam and battery.
- Place the battery inside the box next to the circuit board
- The Bluno came with a piece of foam. Roll that up and tape it, then jam that into the box so the switch stays solidly in place.
- Cut a hole for the LED wires in the front so it does not interfere with the flap when closed, about .75" (1.5cm) from the top. Size does not matter too much. It will be hidden later. I made my hole about 1.5" x .25" (1cm x .5cm).
- Feed LEDs through hole
- Stick LED facing out with clear tape. Clear tape insures that the LEDs are secure and face out to the world for full brightness.
- Push Bluno into the box with the USB connector up and accessible for programming.
- Peal off an Avery 5141 name tag and stick it to white paper. Then cut it to shape. It is best not to stick the name tag directly to the box because odds are you will need to remove it sometime in the future.
- Cover over the LEDs and tape down the "Hello my name is" name tag.
- Cut a plastic name tag holder so it can be taped securely to the back of the box.
- Attach the clip.
Step 6: Arduino Sketches
I've provided all four Sketches needed to configure and run the Bluno Arduinos in this project.
Download the Arduino IDE if you haven't already. Here: arduino.cc
Unpack the zip file that contains the sketches and open them from the Arduino IDE. These are the Sketches:
- blunoBasic: used for initializing all Blunos
- blunoPhone: runs on a Bluno Nano in the phone
- blunoPhoneSounds (optional): plays the sounds on the phone
- blunoNameTag: runs on the "wearable" name tag
Attachments
Step 7: Preparing BLE on Central Phone
Load the Sketch BlunoBasic onto the Arduino Bluno Nano that will be housed inside the phone and do the following:
- Open the serial monitor
- Set "No line ending"type "+++" and send
- should say "Enter AT Mode"
- Now we are in "AT" mode for configuring the BLE Bluetooth on the board.
- set "Both NL & CR"
- AT+MAC=?
- Copy the MAC address
- Open the blunoNameTag Sketch.
- Find the correct "centralMAC"
- Paste the MAC to assign for proper connection.
- Enter all of the following commands to finish the configuration:
- AT+ROLE=ROLE_CENTRAL
- AT+CMODE=UNIQUE
- AT+IBEACONS=OFF
- AT+BLUNODEBUG=OFF
- AT+USBDEBUG=OFF
- AT+EXIT
- Now reprogram the bluno with the Sketch blunoPhone for normal operation.
Step 8: Preparing BLE on Name Tag
Load the Sketch BlunoBasic onto each Bluno Beetle that will be housed inside a name tag and do the following:
- Open the serial monitor
- Set "No line ending"
- type "+++" and send
- should say "Enter AT Mode"
- Now we are in "AT" mode for configuring the BLE Bluetooth on the board.
- set "Both NL & CR"
- AT+MAC=?
- Copy the MAC address
- Open the blunoPhone Sketch.
- Find "phoneLookup_t phoneBook [] = {"
- Paste the MAC into the appropriate place in the array, possibly creating a new entry.
- remove the most significant 4 digits thus creating a 32-bit hexadecimal number.
- make sure MAC_PREFIX matches the most significant 4 digits removed in the previous step.
- (Steps 5 and 6 implement an optimization to save precious RAM on the phone Sketch.)
- Bind to the MAC of the bluno phone. If, for example, the Bluno central MAC is 0xB4994C50236A then you would do this on the peripheral name tag:
- AT+BIND=0xB4994C50236A
- Decide on a number as an ID for the name tag. For instance "8". Insert that number into the phoneBook[] array entry discussed above and do this on the peripheral name tag bluno:
- AT+NAME=8
- Enter all of the following commands to finish the configuration:
- AT+ROLE=ROLE_PERIPHERAL
- AT+CMODE=UNIQUE
- AT+IBEACONS=OFF
- AT+BLUNODEBUG=OFF
- AT+USBDEBUG=OFF
- AT+EXIT
- Now reprogram the bluno with the Sketch blunoNameTag for normal operation.
Step 9: Creating Sounds
I've attached a zip file that contains all of the sounds I installed on my SDCard. The sounds originate from various websites:
- Funny sounds from freesound.org
- Phone recordings from: http://stuff.gigo.com/phone/
If you want a different set of sounds, you can generate some or download from various websites. But they will need to be converted to simple mono 8-bit 16KHz WAV format. I did it this way:
- Go to: https://audio.online-convert.com/convert-to-wav
- Change bit resolution: 8 bit
- Change sampling rate: 16000 Hz
- Change audio channels: mono
- Advanced:
- PCM Format: PCM unsigned 8-bit
- Start Conversion
- Download
- If needed, rename the files so there are 8 or fewer characters in the file name and ".wav" for the extension (aka 8.3 format).
- Insert SD Card into your computer
- copy all files into the top-most directory on the micro SD Card
- Eject
- Insert the micro SD Card into the controller wired into your Arduino via SPI interface.
The blunoPhone Sketch takes care of mounting the SD Card and playing the sound files using libraries: SD.h, SPI.h, and TMRpcm.h
Attachments
Step 10: Arduino Phone Sketch Software
The Sketch blunoPhone that runs on the Bluno Nano housed inside the phone is designed to communicate using BLE Bluetooth with another Sketch blunoNameTag that executes on battery powered "wearable" Bluno Beetles housed in "name tags" held by people scattered around the room.
Optionally phone sounds can be played from a separate Arduino that would also be housed inside the phone. There are various reasons to do so that are described later in comments. Define OFFLOAD_SOUND if you want another Arduino to play the sounds using the Sketch nanoPhoneSounds. I built one phone with a single Bluno Nano inside. I built a second phone that houses a Bluno Beetle for communication, and a standard Arduino Nano for playing sounds. For the most part I'm documenting the phone with a single Bluno Nano but know that there are other options.
This program is large for an Arduino. RAM is maxed out so, if you add more features or increase the number of variables, you might encounter some strange behaviour such as program reset and unexpected reboot. The program uses some advanced techniques to conserve RAM (and some hacks to conserve RAM). (You should seriously consider offloading sound functionality to another Arduino if you have RAM issues.)
The Bluno BLE appears to be designed for communication between only two Bluetooth never-changing endpoints: one central and one peripheral. It seems that I'm using it for a purpose it was not specifically designed for. With some effort I got it to work -- mostly. Sometimes it takes multiple tries to get a connection.
The design of this program has one central Bluno and many peripherals. Only one peripheral is connected at any given time but the central Bluno dynamically selects from a list of known peripheral devices. Usually a connection is made fairly quickly (within 15 seconds) but sometimes it takes much longer (a couple of minutes). The peripherals (name tags) have a watchdog built into the code to force a reboot occasionally. This "hack" seemed to help but its not perfect. Manually switching off/on all peripherals as well as the central phone seems to help get a solid connection sometimes.
This sketch dynamically runs the "AT+BIND" command followed by "AT+RESTART" to connect with the desired peripheral. That sequence does not always work. It seems to be a lot more stable if called twice in a loop instead of just once. Unfortunately, each time through the loop adds an extra second of delay. Consider adjusting the program to call AT+BIND three times for better stability if you are not concerned about the extra delay.
When programming a Sketch into the Bluno central or any peripheral via the USB cable, I found it be most stable if I power off all other Blunos in the room. Because of the serial connection over Bluetooth from one Bluno to another, the programmer seems to get confused on which Bluno is target to be programmed.
This uses the PlainProtocol library for formatting the commands sent over bluetooth. This can be found on GitHub:
git clone https://github.com/DFRobot/BlunoAccessoryShieldDe...
When messing with AT commands by hand on the Serial Monitor, I found it best to run the Sketch blunoBasic.
Normal Program Flow
The software has various states where different functionality comes into play. The normal software path looks like this:
- When the handset is placed on the switch-hook, electricity does not flow and the Bluno is powered off.
- When someone picks up the handset, power is applied and the Bluno begins to boot the the function setup() is called.
- During initialization the SD Card is mounted, the bluetooth BLE is initialized, and the relevant digital pins are initialized. This takes several seconds.
- As soon as everything is initialized, a dial tone is played. This sound, like all sounds, comes from a file found on the SD Card. The dial tone is actually a relatively short sound file that repeats as soon as it completes.
- As soon the wheel on the phone begins to move, the software detects the change on pin D8 and stops the dial tone.
- Each digit in the phone number is calculated based on the number of pulses detected on pin D7.
- Once all 6 digits have been dialed, the program starts the ringing sound, finds the number in the phoneBook[] array, and binds to the listed MAC address that identifies a name tag.
- As soon as a simple handshake is complete to verify that the MAC address matches the expected name tag ID, a long (somewhat silly) series of "hello" voices are played on the headset speaker (which would be when the Sketch on the name tag begins to flash colors crazy fast).
- Usually the person will automatically hang up the phone at this point and watch someone open a gift. Power is off so the Bluno does nothing.
Special conditions result in special things
- If person dials the number written on the phone itself (869-869 or "TMW-TMW") then a random answering message is played. Also, The Mad Wrapper has stealthily hidden one extra Bluno Beetle "name tag" deep in the Christmas Tree. That Bluno begins to blink crazy fast. There up in the tree is a special gift for all to enjoy!
- Various standard AT&T error messages are played for such things as unknown numbers and ringing too long without an answer.
- If the phone is left off-hook for 4 minutes, an off-hook AT&T "blat-blat-blat..." sound indicates to hang up the phone.
Lots of timers
Every time through the loop, the program checks the time and looks to see if any "timers" have expired. Timers are used for a bunch of things including normal operation and error testing:
- There is a watchdog timer for resetting and rebinding to the desired name tag.
- There is a timer for debouncing the "dial-moving" pin D8. We wait for the noisy signal to settle before declaring that a state has changed.
- There is a timer for debouncing the pulses on pin D7.
- There is a timer for throttling the handshake communication to the name tag as it begins to sync up.
Not enough RAM for Variables and Arrays
The program is completely maxed out on RAM usage resulting in the following warning
Low memory available, stability problems may occur.
Odds are, if you add any new functionality, the program will begin to behave quite strangely, including rebooting. I implemented a few tricks to minimize RAM usage:
- Strings such as file names of sounds are stored as constants in ROM. The function pgm_read_word() is used to retrieve constants for ROM.
- MAC address is a 48-bit hexadecimal number. My original implementation stored the MAC addresses as 52-character strings. That was fine when I only had three name tags to communicate with. As soon as I enabled 10 remote Blunos, I ran out of RAM. I was able to revive the program by storing 10 32-bit long integers. The most significant 16 bits of all Bluno Beetle MAC addresses are always the same for the devices that I have so I simply prepended the 16 bits to the unique 32-bit number for binding.
- Another way to save RAM (and probably the best way) is to split the tasks between two Arduinos. If OFFLOAD_SOUND is defined, sound producing functionlality is removed. This is replaced with functionality to communicate with another Arduino wired to D3 and D4 using the SoftwareSerial library. Doing it this way leaves plenty of room in RAM to support a number of new features or more name tags.
Step 11: Debouncing the Noisy Phone Switch
When a switch inside the phone opens or closes, it does not do so cleanly. The voltage will bounce +5, 0, +5, 0, +5, 0, ... for a while until it settle to one or the other. This could be handled with some electronics such as a capacitor. I handled it in software. The blunoPhone sketch checks the value if it changes then waits a period of time to verify that the value has not changed again.
A delay of 10ms works great!
#define DEBOUNCE_DELAY 10 // wait 10ms for the circuit to settle during puls transition
A variable for tracking the time:
long timeOfPulsePinStateChange = 0; // save the time for debouncing
Some code to debounce:
if (pulseInputLastState != pulseInputPinState) {
timeOfPulsePinStateChange = millis(); } if ((millis() - timeOfPulsePinStateChange) > DEBOUNCE_DELAY) { // debounce - this happens once it's stabilized if (pulseInputTrueState != pulseInputPinState) { // this means that the switch has either just gone from closed->open or vice versa. pulseInputTrueState = pulseInputPinState; }
Step 12: Arduino Name Tag Sketch Software
The Sketch blunoNameTag implements a wearable "name tag" that runs on a DFRobot Bluno Beetle.
It uses BLE Bluetooth connectivity to communicate with a central Bluno that is hidden inside the antique telephone.
- In the idle state -- when there is no connection to the phone -- a blue LED gently pulses glowing brighter then dimmer.
- As communication handshake begins, a couple of LEDs of different colors light up and the blue LED glows full brightness no longer pulsing.
- The handshake requires replying with the name tag's ID. This is the results returned from AT+NAME=?. Important instructions on configuring AT+NAME with the appropriate number are described in another section of this Instructable.
- Once communication is fully established, all colors of LEDs begin blinking wildly.
Lots of Timers
Every time through the loop, the program checks the time and looks to see if any "timers" have expired.
- There is a timer to update the brightness of the blue LED. (I really like this simple subtle feature. The gentle calming pulses during idle state add a little "natural" humanness to the project.)
- There is a timer for each colored LED to tell it to blink at a certain time. The blink rate of each LED is different resulting is a slightly random light pattern.
- There is a timer to check for messages from the phone.
- There is a watchdog timer that resets the entire Bluno Beetle. Sometimes, starting completely fresh is the only way to sync with a central Bluno that is attempting contact.
Step 13: Gently Glow the LED for a Nice Calming Effect
Whenever possible I try to add some subtle "natural" effects to my apps. If done right this will add a level of comfort and gain a bit of trust from the user. It makes people feel good. It is good design.
The easy thing to do if you simply need to show users that a your gadget is powered on, is to simply light an LED during boot and forget about it.
Meh.
Use the Arduino PWM feature and do something interesting. Do it! It's not that hard (especially since I've provided some code for you to copy/paste into your application).
I like the effect of the following code which implements the blue LED gently glowing brighter and dimmer at a calm "breathing" rate. It feels good!
I connected the blue LED to a pin that is PWM-capable (pin D3 on the Bluno Beetle).
#define BLUE_LED 3 // blue LED
I set some parameters on how fast and how bright to glow the LED
#define GLOW_MIN 15 //15 // min brightness of glow #define GLOW_MAX 100 //120 // max brightness of glow #define GLOW_UPDATE_DELAY 40 // when to increment #define GLOW_STEP_SIZE 2
And related variables
long timeOfLastPulseUpdate = 0; int glowValue = 0; // led brightness 0-255 int glowIncrement = GLOW_STEP_SIZE; // Either + or - depending on up/down glow
I created a utility function to help decide if it is time to adjust the brightness of the LED:
// gently glow bright/dim when not connected<br>bool timeToUpdateGlow () { long now = millis(); if ((now - timeOfLastPulseUpdate) > GLOW_UPDATE_DELAY) { timeOfLastPulseUpdate = now; return true; } else { return false; } }
Then, every pass through the loop, if it is time to change the brightness, change it. If glowIncrement is a positive number the LED is nudged slightly brighter. If glowIncrement is a negative number, the blue LED gets slightly dimmer.
void loop() { ... if (timeToUpdateGlow()) { glowValue += glowIncrement; if (glowValue <= GLOW_MIN) { glowValue = GLOW_MIN; glowIncrement = GLOW_STEP_SIZE; // +1 so start glowing brighter } else if (glowValue >= GLOW_MAX) { glowValue = GLOW_MAX; glowIncrement = -GLOW_STEP_SIZE; // start dimming now } analogWrite(BLUE_LED, glowValue); } ... }
Step 14: Crazy Flashy Colors Attract Attention
A great way to draw attention to a gadget is to "randomly" splatter flashy colors using a few LEDs. I'm happy with the effect I used. Each LED blinks at a different fast rate to create an interesting orchestra of colors.
Define the blink rates and variables:
// blink rates when connected spaced to look like random orchestrated splatter #define BLUE_BLINK_DELAY 300 // blink rate 0.3 seconds #define YELLOW_BLINK_DELAY 500 // blink rate 0.5 seconds #define RED_BLINK_DELAY 800 // blink rate 0.8 seconds #define GREEN_BLINK_DELAY 1300 // blink rate 1.3 seconds long timeOfLastBlueBlink = 0; long timeOfLastGreenBlink = 0; long timeOfLastYellowBlink = 0; long timeOfLastRedBlink = 0;
Some utility functions to determine when to blink the LED
// after connected we wildly blink the blue LED bool timeForBlueBlink () { long now = millis(); if ((now - timeOfLastBlueBlink) > BLUE_BLINK_DELAY) { timeOfLastBlueBlink = now; return true; } else { return false; } } // after connected we wildly blink the green LED bool timeForGreenBlink () { long now = millis(); if ((now - timeOfLastGreenBlink) > GREEN_BLINK_DELAY) { timeOfLastGreenBlink = now; return true; } else { return false; } } // after connected we wildly blink the yellow LED bool timeForYellowBlink () { long now = millis(); if ((now - timeOfLastYellowBlink) > YELLOW_BLINK_DELAY) { timeOfLastYellowBlink = now; return true; } else { return false; } } // after connected we wildly blink the red LED bool timeForRedBlink () { long now = millis(); if ((now - timeOfLastRedBlink) > RED_BLINK_DELAY) { timeOfLastRedBlink = now; return true; } else { return false; } }
And a function to blink.
void blink (int pin) { digitalWrite(pin, HIGH); delay(100); digitalWrite(pin, LOW); }
And, if in the right state, once per loop, check the time and blink the LED
void loop() { ... if (timeForBlueBlink()) { blink (BLUE_LED); } if (timeForGreenBlink()) { blink (GREEN_LED); } if (timeForYellowBlink()) { blink (YELLOW_LED); } if (timeForRedBlink()) { blink (RED_LED); } ... }
Step 15: Christmas Packages
The theme this year was silver wrapping paper with clothes pins to hold the label.
I put all name tags in a box and labeled it "To: Be opened First. From: The Mad Wrapper"
I put the phone in another box and labeled it "To: Be opened Second. From: The Mad Wrapper"
Each gift was labeled with a silly "Lost and Found" instructions with a 6-digit phone number to call to report of claim the "found" item. Here are some samples of the silly instructions:
- Unclaimed Beverages Claims Department suggests you file a claim to claim your goods. 869-342
- Lost item! If found please contact the NH Bureau of Recovery of Forestry Byproducts at 869-263
- Roundabout Circulation Claims and Reclaims Department. 869-345
- Lost in the shuffle? Call 869-647
Lots of smiles. Lots of fun. A great success!