Getting Started

(lily) #1

Chapter 8: C Pointers and Arrays


t again Sam Software.

d
gs

lay it again Sam, and copy the .c and .h files and the
er directory. From the WinAVR Butterfly port, bf_gcc
sound.h. In Programmers Notepad, create a new
:

******************************************************

yte sets
empo. A high byte will give a low tempo, and opposite.
sts of two bytes. The first gives the length of
her gives the frequency. The frequencies for
ach tone are defined in the "sound.h". Timer0 controls the
po and the length of each tone, while Timer1 with PWM gives
the frequency. The second last byte is a "0" which indicates
the end, and the very last byte makes the song loop if it's
t's "0".

*** ***********************************?

mt ur Elise";
t r Elise";

__f
t

8,e2, 8,xd2, 8,e2, 8,xd2, 8,e2, 8,b1, 8,d2, 8,c2, 4,a1,
8,p, 8,c1, 8,e1, 8,a1, 4,b1, 8,p, 8,e1, 8,c2, 8,b1, 4,a1,

The Play i


For some reason, the Butterfly code commented out the songs Minuet an
AuldLangSyne, but the WinAVR version uses them, so we get to hear two son
absent on the store-bought Butterfly.


Create a new directory: P
makefile from the Messeng
directory copy sound.c and
C/C++ file, tunes.h and add


// tunes.h


#include "sound.h"


Then copy the following from sound.c to tunes.h


/**





  • A song is defined by a table of notes. The first b

  • the t

  • Each tone consi

  • the tone, the ot

  • e

  • tem





  • "1", and not loop if i






// __flash char TEXT_SONG1[] = "F
cons char TEXT_SONG1[] PROGMEM = "Fu


// lash int FurElise[] =
cons int FurElise[] PROGMEM=
{
3,
8,e2, 8,xd2, 8,e2, 8,xd2, 8,e2, 8,b1, 8,d2, 8,c2, 4,a1, 8,p, 8,c1, 8,e1, 8,a1, 4,b1,
8,p, 8,e1, 8,xg1, 8,b1, 4,c2, 8,p, 8,e1,

Free download pdf