Summer Library for Arduino
Author:  Alexander Brevig
Contact: alexanderbrevig@gmail.com


Navigation


Current version

1.0 2008-10-23: Initial Release


History

1.0 2008-10-23: Initial Release


Description

Summer is a library for the Arduino.

It is created to help Hardware Abstraction, and readability of code. It hides the pinMode, and digitalRead calls for the user.

Summer library is part of the Hardware Abstraction libraries.


Download, install and import

Download here: Attach:Summer.zip

Put the Summer folder in "hardware\libraries\".

In the Arduino IDE, create a new sketch (or open one) and

select from the menubar "Sketch->Import Library->Summer".

Once the library is imported, an "#include Summer.h" line will appear

at the top of your Sketch.


Creation

Summer(uint8_t summerPin)

Summer summer = Summer(9);

Instanciates a Summer object at pin 9


Functions

void check()

Will execute the function it is refered to. In this case, the void blink()

void setTone(byte tone)

Use PWM to generate a tone

void setTempo(uint tempo)

Set tempo that are used by playTone:beats

void beep(uint toneFrequency)

Wrapper for playTone, with beat=1 : equivalent of playTone(toneFrequency,1)

void playTone(uint toneFrequency, byte beats)

Plays a frequency over a period of time indicated as beats at a given tempo.


Example

/*
||
|| @author Alexander Brevig
|| @version 1.0
||
|| @description
|| Demonstrates the functionality of the Summer class
|| Alternate between A4 and A5, playing A5 twice as long
||
*/

#include <Summer.h>

Summer summer = Summer(9);

void setup() {
  summer.setTempo(300);
}

void loop() {
  summer.playTone(440,1); //A4
  summer.playTone(880,2); //A5
}


FAQ

How can I use multiple Summers?

Summer is a class. Therefore to Summer multiple digital pins, you must create an instance for each of them. In the example above, a Summer instance (Summer summer) is bound to the digital pin 9

Summer summer = Summer(9);

To add a Summer bound to digital pin 6, you could create the following instance summer2:

Summer summer2 = Summer(6);

And now it's just to use whatever function is wanted on both:

//update instances and possibly fire funcitons
  summer1.beep(440); 		//A4
  summer2.playTone(880,2);	//A5


Information about this page

Part of AlphaBeta Libraries.
Last Modified: December 01, 2011, at 01:15 AM
By: billabott

Share