Выбрать главу

  pinMode(sounderPinB, OUTPUT);

}

The loop function that follows calls two functions to wave the flag and to sound the buzzer:

void loop()

{

  wave();

  wave();

  makeNoise();

}

The wave function is called twice to waggle the flag back and forth. In case a bit of movement isn’t enough to catch a zombie’s attention, makeNoise is also called to sound the buzzer. With any luck, the zombies will mistake the noises and movement for something with a brain and will head straight for the distraction!

At the end of the sketch, define the functions that cause the distractions:

void wave()

{

  // Wave vigorously from left to right

  for (int angle = minServoAngle; angle < maxServoAngle; angle++)

  {

    arm.write(angle);

    delay(stepPause);

  }

  for (int angle = maxServoAngle; angle > minServoAngle; angle--)

  {

    arm.write(angle);

    delay(stepPause);

  }

}

The wave function contains two loops: one loop moves the servo from its minimum to its maximum angle at the preselected speed, and the second loop does the reverse.

Now, let’s look at makeNoise:

void makeNoise()

{

  for (int i = 0; i < 5; i++)

  {

    beep(500);

    delay(1000);

  }

}

This function contains a loop that calls the beep function five times for five beeps of the buzzer. The parameter to beep is the duration of the sound in milliseconds (in this case, 500). Between each beep there is a delay of one second (1000 milliseconds).

NOTE

If using the same values all the time causes local zombies to become immune to your distractor’s effects, try tweaking the numbers you pass to beep and delay. You could even randomize the values, using Arduino’s random() function.

The beep function itself generates the AC signal on the two buzzer pins:

   void beep(long duration)

   {

➊   long sounderPeriodMicros = 500000l / f;

➋   long cycles = (duration * 1000) / sounderPeriodMicros / 2;

     for (int i = 0; i < cycles; i++)

     {

       digitalWrite(sounderPinA, HIGH);

       digitalWrite(sounderPinB, LOW);

       delayMicroseconds(sounderPeriodMicros);

       digitalWrite(sounderPinA, LOW);

       digitalWrite(sounderPinB, HIGH);

       delayMicroseconds(sounderPeriodMicros);

     }

   }

First, we calculate the period of each oscillation ➊ using the frequency f. The resulting value must be further divided by 2 ➋, because what we really want is the duration of delay between swapping the polarity of the pins, and we need two such delays for a complete oscillation.

Using that divided period, the beep function calculates the total number of cycles needed to produce a beep of the correct duration. The for loop that follows uses this information to generate the pulses that are needed.

USING THE SOUND AND MOVEMENT DISTRACTOR

Both of the projects in this chapter need to be kept dry. To weatherproof the sound and movement distractor, you might craft some kind of housing or protective roof shelter. If your build is freestanding, a large plastic bin with a lid could do the trick. I’m sure you can scavenge one from the nearest abandoned discount retail store.

Just cut off one side of the bin so the zombies can see and hear the distractor, affix the project itself to the lid, and snap the bin on top, upside down. Attach this box to a lever and pulley system, and you could even lower it to the ground from the safety of your base, creating a new sport: zombie fishing. Who says you can’t have fun during an apocalypse?

Of course, the sound and movement distractor has many practical postapocalyptic uses, too:

• Place it opposite the most vulnerable point in your stronghold to draw away attacking zombie hordes and give you time to reinforce your bunker.

• Plant it by your zombie pit to draw them into the trap.

• Sneak it into your neighbor’s yard to thin out the competition for survivor salvage.

In case you want to find other survivors (whether to join forces or avoid them), in the next chapter, we’ll look at using wireless technology to communicate.

10

COMMUNICATING WITH OTHER SURVIVORS

In Chapter 1, we discussed the pros and cons of teaming up with other humans when zombies walk the Earth. Associating with other people can certainly be worthwhile: you can protect each other, share knowledge, pool resources, and so on. Of course, they can also take your stuff and put you between themselves and the oncoming zombies. If you decide to take the risk and reach out to your fellow life forms, then build the projects in this chapter.

First, we’ll build a beacon to broadcast a voice signal that can be heard on an FM radio, so any survivors scanning the airwaves can hear your message, whether that’s “Stay away!” or “Help, I’m trapped on the roof of a shopping mall!” After that, you’ll also build a Morse code flasher that will blink out any message you care to translate into dots and dashes.

Of course, if you want to be the one scanning frequency bands, this chapter also explains how to hack a radio receiver to search for a signal. Then, you can lurk silently while you decide whether what’s out there is worth broadcasting to (see Figure 10-1).

Figure 10-1: Zombies like the radio too.

PROJECT 17: A RASPBERRY PI RADIO TRANSMITTER BEACON

The Raspberry Pi is a versatile device that can, given the right software, act as an FM radio transmitter. The only extra hardware you’ll need is a length of wire to act as an antenna.

WHAT YOU WILL NEED

This is another Raspberry Pi project, so you will need to have a working Raspberry Pi system complete with keyboard, mouse, and screen as described in Chapter 5. Once the program that transmits the radio signal is up and running, you can turn off the screen to save power if you wish.

RADIO TRANSMITTER LEGALITY

If you’re reading this after the zombie apocalypse, there will be no legal problems with building a transmitter because there won’t be any government to enforce the regulations. If, however, you are building in preparation, then the legality of the transmitter in this project is covered by the same legislation as FM transmitters designed to be connected to an MP3 player for car audio.

These transmitters are legal in the United States if the effective range is 200 feet (60 m) or less. If you use a full-length antenna, this transmitter will have a longer range than that, so to stay within the law, use a small antenna of about 3 or 4 inches (7 to 10 cm).