aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorSudar <sudar@sudarmuthu.com>2014-09-21 12:05:12 +0530
committerSudar <sudar@sudarmuthu.com>2014-09-21 12:05:12 +0530
commitee1855c6b1aabf4d50afcfba69cecd2417d27237 (patch)
tree05db0503f3cb1ffbd41f077ecf6135a429d5b66b /examples
parent6f46722abb40c60dcaa0e40292342d015906c8bf (diff)
parentd092c14d7ec845246f6588704e22718615626982 (diff)
Merge pull request #268 from peplin/259-move-examples
Move tests back to 'examples', skip non-testable examples when testing. Fix #259 Fix #260
Diffstat (limited to 'examples')
-rw-r--r--examples/AnalogInOutSerial/AnalogInOutSerial.ino53
-rw-r--r--examples/AnalogInOutSerial/Makefile5
-rw-r--r--examples/Blink/Blink.ino19
-rw-r--r--examples/Blink/Makefile6
-rw-r--r--examples/BlinkChipKIT/BlinkChipKIT.pde19
-rw-r--r--examples/BlinkChipKIT/Makefile6
-rw-r--r--examples/BlinkInAVRC/Makefile17
-rw-r--r--examples/BlinkInAVRC/blink.c38
-rw-r--r--examples/BlinkWithoutDelay/BlinkWithoutDelay.ino65
-rw-r--r--examples/BlinkWithoutDelay/Makefile5
-rw-r--r--examples/Fade/Fade.ino31
-rw-r--r--examples/Fade/Makefile5
-rw-r--r--examples/HelloWorld/HelloWorld.ino58
-rw-r--r--examples/HelloWorld/Makefile5
-rw-r--r--examples/TestSuiteCommon.mk13
-rw-r--r--examples/WebServer/Makefile7
-rw-r--r--examples/WebServer/WebServer.ino82
-rw-r--r--examples/master_reader/Makefile7
-rw-r--r--examples/master_reader/master_reader.ino32
-rw-r--r--examples/toneMelody/Makefile5
-rw-r--r--examples/toneMelody/pitches.h95
-rw-r--r--examples/toneMelody/toneMelody.ino49
22 files changed, 622 insertions, 0 deletions
diff --git a/examples/AnalogInOutSerial/AnalogInOutSerial.ino b/examples/AnalogInOutSerial/AnalogInOutSerial.ino
new file mode 100644
index 0000000..e142f69
--- /dev/null
+++ b/examples/AnalogInOutSerial/AnalogInOutSerial.ino
@@ -0,0 +1,53 @@
+/*
+ Analog input, analog output, serial output
+
+ Reads an analog input pin, maps the result to a range from 0 to 255
+ and uses the result to set the pulsewidth modulation (PWM) of an output pin.
+ Also prints the results to the serial monitor.
+
+ The circuit:
+ * potentiometer connected to analog pin 0.
+ Center pin of the potentiometer goes to the analog pin.
+ side pins of the potentiometer go to +5V and ground
+ * LED connected from digital pin 9 to ground
+
+ created 29 Dec. 2008
+ modified 30 Aug 2011
+ by Tom Igoe
+
+ This example code is in the public domain.
+
+ */
+
+// These constants won't change. They're used to give names
+// to the pins used:
+const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
+const int analogOutPin = 9; // Analog output pin that the LED is attached to
+
+int sensorValue = 0; // value read from the pot
+int outputValue = 0; // value output to the PWM (analog out)
+
+void setup() {
+ // initialize serial communications at 9600 bps:
+ Serial.begin(9600);
+}
+
+void loop() {
+ // read the analog in value:
+ sensorValue = analogRead(analogInPin);
+ // map it to the range of the analog out:
+ outputValue = map(sensorValue, 0, 1023, 0, 255);
+ // change the analog out value:
+ analogWrite(analogOutPin, outputValue);
+
+ // print the results to the serial monitor:
+ Serial.print("sensor = " );
+ Serial.print(sensorValue);
+ Serial.print("\t output = ");
+ Serial.println(outputValue);
+
+ // wait 10 milliseconds before the next loop
+ // for the analog-to-digital converter to settle
+ // after the last reading:
+ delay(10);
+}
diff --git a/examples/AnalogInOutSerial/Makefile b/examples/AnalogInOutSerial/Makefile
new file mode 100644
index 0000000..872d069
--- /dev/null
+++ b/examples/AnalogInOutSerial/Makefile
@@ -0,0 +1,5 @@
+BOARD_TAG = uno
+ARDUINO_LIBS =
+
+include ../TestSuiteCommon.mk
+include ../../Arduino.mk
diff --git a/examples/Blink/Blink.ino b/examples/Blink/Blink.ino
new file mode 100644
index 0000000..1953c39
--- /dev/null
+++ b/examples/Blink/Blink.ino
@@ -0,0 +1,19 @@
+/*
+ Blink
+ Turns on an LED on for one second, then off for one second, repeatedly.
+
+ This example code is in the public domain.
+ */
+
+void setup() {
+ // initialize the digital pin as an output.
+ // Pin 13 has an LED connected on most Arduino boards:
+ pinMode(13, OUTPUT);
+}
+
+void loop() {
+ digitalWrite(13, HIGH); // set the LED on
+ delay(1000); // wait for a second
+ digitalWrite(13, LOW); // set the LED off
+ delay(1000); // wait for a second
+}
diff --git a/examples/Blink/Makefile b/examples/Blink/Makefile
new file mode 100644
index 0000000..d41effa
--- /dev/null
+++ b/examples/Blink/Makefile
@@ -0,0 +1,6 @@
+BOARD_TAG = uno
+ARDUINO_LIBS =
+
+include ../TestSuiteCommon.mk
+include ../../Arduino.mk
+
diff --git a/examples/BlinkChipKIT/BlinkChipKIT.pde b/examples/BlinkChipKIT/BlinkChipKIT.pde
new file mode 100644
index 0000000..1953c39
--- /dev/null
+++ b/examples/BlinkChipKIT/BlinkChipKIT.pde
@@ -0,0 +1,19 @@
+/*
+ Blink
+ Turns on an LED on for one second, then off for one second, repeatedly.
+
+ This example code is in the public domain.
+ */
+
+void setup() {
+ // initialize the digital pin as an output.
+ // Pin 13 has an LED connected on most Arduino boards:
+ pinMode(13, OUTPUT);
+}
+
+void loop() {
+ digitalWrite(13, HIGH); // set the LED on
+ delay(1000); // wait for a second
+ digitalWrite(13, LOW); // set the LED off
+ delay(1000); // wait for a second
+}
diff --git a/examples/BlinkChipKIT/Makefile b/examples/BlinkChipKIT/Makefile
new file mode 100644
index 0000000..bec2794
--- /dev/null
+++ b/examples/BlinkChipKIT/Makefile
@@ -0,0 +1,6 @@
+BOARD_TAG = mega_pic32
+ARDUINO_LIBS =
+
+include ../TestSuiteCommon.mk
+include ../../chipKIT.mk
+
diff --git a/examples/BlinkInAVRC/Makefile b/examples/BlinkInAVRC/Makefile
new file mode 100644
index 0000000..9080b24
--- /dev/null
+++ b/examples/BlinkInAVRC/Makefile
@@ -0,0 +1,17 @@
+# This sample Makefile, explains how you can compile plain AVR C file.
+#
+# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
+
+NO_CORE = Yes
+
+BOARD_TAG = atmega16
+MCU = atmega16
+F_CPU = 8000000L
+
+ISP_PROG = stk500v1
+AVRDUDE_ISP_BAUDRATE = 19200
+
+include ../TestSuiteCommon.mk
+include $(ARDMK_DIR)/Arduino.mk
+
+# !!! Important. You have to use make ispload to upload when using ISP programmer
diff --git a/examples/BlinkInAVRC/blink.c b/examples/BlinkInAVRC/blink.c
new file mode 100644
index 0000000..d8b7c8f
--- /dev/null
+++ b/examples/BlinkInAVRC/blink.c
@@ -0,0 +1,38 @@
+/*
+ * © Anil Kumar Pugalia, 2010. Email: email@sarika-pugs.com
+ *
+ * ATmega48/88/168, ATmega16/32
+ *
+ * Example Blink. Toggles all IO pins at 1Hz
+ */
+
+#include <avr/io.h>
+#include <util/delay.h>
+
+void init_io(void)
+{
+ // 1 = output, 0 = input
+ DDRB = 0b11111111; // All outputs
+ DDRC = 0b11111111; // All outputs
+ DDRD = 0b11111110; // PORTD (RX on PD0). Just for demo
+}
+
+int main(void)
+{
+ init_io();
+
+ while (1)
+ {
+ PORTC = 0xFF;
+ PORTB = 0xFF;
+ PORTD = 0xFF;
+ _delay_ms(500);
+
+ PORTC = 0x00;
+ PORTB = 0x00;
+ PORTD = 0x00;
+ _delay_ms(500);
+ }
+
+ return 0;
+}
diff --git a/examples/BlinkWithoutDelay/BlinkWithoutDelay.ino b/examples/BlinkWithoutDelay/BlinkWithoutDelay.ino
new file mode 100644
index 0000000..0143571
--- /dev/null
+++ b/examples/BlinkWithoutDelay/BlinkWithoutDelay.ino
@@ -0,0 +1,65 @@
+/* Blink without Delay
+
+ Turns on and off a light emitting diode(LED) connected to a digital
+ pin, without using the delay() function. This means that other code
+ can run at the same time without being interrupted by the LED code.
+
+ The circuit:
+ * LED attached from pin 13 to ground.
+ * Note: on most Arduinos, there is already an LED on the board
+ that's attached to pin 13, so no hardware is needed for this example.
+
+
+ created 2005
+ by David A. Mellis
+ modified 8 Feb 2010
+ by Paul Stoffregen
+
+ This example code is in the public domain.
+
+
+ http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
+ */
+
+// constants won't change. Used here to
+// set pin numbers:
+const int ledPin = 13; // the number of the LED pin
+
+// Variables will change:
+int ledState = LOW; // ledState used to set the LED
+long previousMillis = 0; // will store last time LED was updated
+
+// the follow variables is a long because the time, measured in miliseconds,
+// will quickly become a bigger number than can be stored in an int.
+long interval = 1000; // interval at which to blink (milliseconds)
+
+void setup() {
+ // set the digital pin as output:
+ pinMode(ledPin, OUTPUT);
+}
+
+void loop()
+{
+ // here is where you'd put code that needs to be running all the time.
+
+ // check to see if it's time to blink the LED; that is, if the
+ // difference between the current time and last time you blinked
+ // the LED is bigger than the interval at which you want to
+ // blink the LED.
+ unsigned long currentMillis = millis();
+
+ if(currentMillis - previousMillis > interval) {
+ // save the last time you blinked the LED
+ previousMillis = currentMillis;
+
+ // if the LED is off turn it on and vice-versa:
+ if (ledState == LOW)
+ ledState = HIGH;
+ else
+ ledState = LOW;
+
+ // set the LED with the ledState of the variable:
+ digitalWrite(ledPin, ledState);
+ }
+}
+
diff --git a/examples/BlinkWithoutDelay/Makefile b/examples/BlinkWithoutDelay/Makefile
new file mode 100644
index 0000000..872d069
--- /dev/null
+++ b/examples/BlinkWithoutDelay/Makefile
@@ -0,0 +1,5 @@
+BOARD_TAG = uno
+ARDUINO_LIBS =
+
+include ../TestSuiteCommon.mk
+include ../../Arduino.mk
diff --git a/examples/Fade/Fade.ino b/examples/Fade/Fade.ino
new file mode 100644
index 0000000..b47bf43
--- /dev/null
+++ b/examples/Fade/Fade.ino
@@ -0,0 +1,31 @@
+/*
+ Fade
+
+ This example shows how to fade an LED on pin 9
+ using the analogWrite() function.
+
+ This example code is in the public domain.
+
+ */
+int brightness = 0; // how bright the LED is
+int fadeAmount = 5; // how many points to fade the LED by
+
+void setup() {
+ // declare pin 9 to be an output:
+ pinMode(9, OUTPUT);
+}
+
+void loop() {
+ // set the brightness of pin 9:
+ analogWrite(9, brightness);
+
+ // change the brightness for next time through the loop:
+ brightness = brightness + fadeAmount;
+
+ // reverse the direction of the fading at the ends of the fade:
+ if (brightness == 0 || brightness == 255) {
+ fadeAmount = -fadeAmount ;
+ }
+ // wait for 30 milliseconds to see the dimming effect
+ delay(30);
+}
diff --git a/examples/Fade/Makefile b/examples/Fade/Makefile
new file mode 100644
index 0000000..872d069
--- /dev/null
+++ b/examples/Fade/Makefile
@@ -0,0 +1,5 @@
+BOARD_TAG = uno
+ARDUINO_LIBS =
+
+include ../TestSuiteCommon.mk
+include ../../Arduino.mk
diff --git a/examples/HelloWorld/HelloWorld.ino b/examples/HelloWorld/HelloWorld.ino
new file mode 100644
index 0000000..e99957d
--- /dev/null
+++ b/examples/HelloWorld/HelloWorld.ino
@@ -0,0 +1,58 @@
+/*
+ LiquidCrystal Library - Hello World
+
+ Demonstrates the use a 16x2 LCD display. The LiquidCrystal
+ library works with all LCD displays that are compatible with the
+ Hitachi HD44780 driver. There are many of them out there, and you
+ can usually tell them by the 16-pin interface.
+
+ This sketch prints "Hello World!" to the LCD
+ and shows the time.
+
+ The circuit:
+ * LCD RS pin to digital pin 12
+ * LCD Enable pin to digital pin 11
+ * LCD D4 pin to digital pin 5
+ * LCD D5 pin to digital pin 4
+ * LCD D6 pin to digital pin 3
+ * LCD D7 pin to digital pin 2
+ * LCD R/W pin to ground
+ * 10K resistor:
+ * ends to +5V and ground
+ * wiper to LCD VO pin (pin 3)
+
+ Library originally added 18 Apr 2008
+ by David A. Mellis
+ library modified 5 Jul 2009
+ by Limor Fried (http://www.ladyada.net)
+ example added 9 Jul 2009
+ by Tom Igoe
+ modified 22 Nov 2010
+ by Tom Igoe
+
+ This example code is in the public domain.
+
+ http://www.arduino.cc/en/Tutorial/LiquidCrystal
+ */
+
+// include the library code:
+#include <LiquidCrystal.h>
+
+// initialize the library with the numbers of the interface pins
+LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
+
+void setup() {
+ // set up the LCD's number of columns and rows:
+ lcd.begin(16, 2);
+ // Print a message to the LCD.
+ lcd.print("hello, world!");
+}
+
+void loop() {
+ // set the cursor to column 0, line 1
+ // (note: line 1 is the second row, since counting begins with 0):
+ lcd.setCursor(0, 1);
+ // print the number of seconds since reset:
+ lcd.print(millis()/1000);
+}
+
diff --git a/examples/HelloWorld/Makefile b/examples/HelloWorld/Makefile
new file mode 100644
index 0000000..0af2ed4
--- /dev/null
+++ b/examples/HelloWorld/Makefile
@@ -0,0 +1,5 @@
+BOARD_TAG = uno
+ARDUINO_LIBS = LiquidCrystal
+
+include ../TestSuiteCommon.mk
+include ../../Arduino.mk
diff --git a/examples/TestSuiteCommon.mk b/examples/TestSuiteCommon.mk
new file mode 100644
index 0000000..a66a007
--- /dev/null
+++ b/examples/TestSuiteCommon.mk
@@ -0,0 +1,13 @@
+ARDMK_DIR=../../
+DEPENDENCIES_FOLDER = /var/tmp/Arduino-Makefile-testing-dependencies
+DEPENDENCIES_MPIDE_DIR = $(DEPENDENCIES_FOLDER)/mpide-0023-linux64-20130817-test
+
+ifeq ($(MPIDE_DIR),)
+ MPIDE_DIR = $(DEPENDENCIES_MPIDE_DIR)
+endif
+
+DEPENDENCIES_ARDUINO_DIR = $(DEPENDENCIES_FOLDER)/arduino-1.0.5
+
+ifeq ($(ARDUINO_DIR),)
+ ARDUINO_DIR = $(DEPENDENCIES_ARDUINO_DIR)
+endif
diff --git a/examples/WebServer/Makefile b/examples/WebServer/Makefile
new file mode 100644
index 0000000..5fbefae
--- /dev/null
+++ b/examples/WebServer/Makefile
@@ -0,0 +1,7 @@
+# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
+
+BOARD_TAG = uno
+ARDUINO_LIBS = Ethernet SPI
+
+include ../TestSuiteCommon.mk
+include ../../Arduino.mk
diff --git a/examples/WebServer/WebServer.ino b/examples/WebServer/WebServer.ino
new file mode 100644
index 0000000..fb2a1b9
--- /dev/null
+++ b/examples/WebServer/WebServer.ino
@@ -0,0 +1,82 @@
+/*
+ Web Server
+
+ A simple web server that shows the value of the analog input pins.
+ using an Arduino Wiznet Ethernet shield.
+
+ Circuit:
+ * Ethernet shield attached to pins 10, 11, 12, 13
+ * Analog inputs attached to pins A0 through A5 (optional)
+
+ created 18 Dec 2009
+ by David A. Mellis
+ modified 4 Sep 2010
+ by Tom Igoe
+
+ */
+
+#include <SPI.h>
+#include <Ethernet.h>
+
+// Enter a MAC address and IP address for your controller below.
+// The IP address will be dependent on your local network:
+byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+IPAddress ip(192,168,1, 178);
+
+// Initialize the Ethernet server library
+// with the IP address and port you want to use
+// (port 80 is default for HTTP):
+EthernetServer server(80);
+
+void setup()
+{
+ // start the Ethernet connection and the server:
+ Ethernet.begin(mac, ip);
+ server.begin();
+}
+
+void loop()
+{
+ // listen for incoming clients
+ EthernetClient client = server.available();
+ if (client) {
+ // an http request ends with a blank line
+ boolean currentLineIsBlank = true;
+ while (client.connected()) {
+ if (client.available()) {
+ char c = client.read();
+ // if you've gotten to the end of the line (received a newline
+ // character) and the line is blank, the http request has ended,
+ // so you can send a reply
+ if (c == '\n' && currentLineIsBlank) {
+ // send a standard http response header
+ client.println("HTTP/1.1 200 OK");
+ client.println("Content-Type: text/html");
+ client.println();
+
+ // output the value of each analog input pin
+ for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
+ client.print("analog input ");
+ client.print(analogChannel);
+ client.print(" is ");
+ client.print(analogRead(analogChannel));
+ client.println("<br />");
+ }
+ break;
+ }
+ if (c == '\n') {
+ // you're starting a new line
+ currentLineIsBlank = true;
+ }
+ else if (c != '\r') {
+ // you've gotten a character on the current line
+ currentLineIsBlank = false;
+ }
+ }
+ }
+ // give the web browser time to receive the data
+ delay(1);
+ // close the connection:
+ client.stop();
+ }
+}
diff --git a/examples/master_reader/Makefile b/examples/master_reader/Makefile
new file mode 100644
index 0000000..8a42a8e
--- /dev/null
+++ b/examples/master_reader/Makefile
@@ -0,0 +1,7 @@
+# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
+
+BOARD_TAG = uno
+ARDUINO_LIBS = Wire
+
+include ../TestSuiteCommon.mk
+include ../../Arduino.mk
diff --git a/examples/master_reader/master_reader.ino b/examples/master_reader/master_reader.ino
new file mode 100644
index 0000000..4124d7d
--- /dev/null
+++ b/examples/master_reader/master_reader.ino
@@ -0,0 +1,32 @@
+// Wire Master Reader
+// by Nicholas Zambetti <http://www.zambetti.com>
+
+// Demonstrates use of the Wire library
+// Reads data from an I2C/TWI slave device
+// Refer to the "Wire Slave Sender" example for use with this
+
+// Created 29 March 2006
+
+// This example code is in the public domain.
+
+
+#include <Wire.h>
+
+void setup()
+{
+ Wire.begin(); // join i2c bus (address optional for master)
+ Serial.begin(9600); // start serial for output
+}
+
+void loop()
+{
+ Wire.requestFrom(2, 6); // request 6 bytes from slave device #2
+
+ while(Wire.available()) // slave may send less than requested
+ {
+ char c = Wire.read(); // receive a byte as character
+ Serial.print(c); // print the character
+ }
+
+ delay(500);
+}
diff --git a/examples/toneMelody/Makefile b/examples/toneMelody/Makefile
new file mode 100644
index 0000000..872d069
--- /dev/null
+++ b/examples/toneMelody/Makefile
@@ -0,0 +1,5 @@
+BOARD_TAG = uno
+ARDUINO_LIBS =
+
+include ../TestSuiteCommon.mk
+include ../../Arduino.mk
diff --git a/examples/toneMelody/pitches.h b/examples/toneMelody/pitches.h
new file mode 100644
index 0000000..55c7d54
--- /dev/null
+++ b/examples/toneMelody/pitches.h
@@ -0,0 +1,95 @@
+/*************************************************
+ * Public Constants
+ *************************************************/
+
+#define NOTE_B0 31
+#define NOTE_C1 33
+#define NOTE_CS1 35
+#define NOTE_D1 37
+#define NOTE_DS1 39
+#define NOTE_E1 41
+#define NOTE_F1 44
+#define NOTE_FS1 46
+#define NOTE_G1 49
+#define NOTE_GS1 52
+#define NOTE_A1 55
+#define NOTE_AS1 58
+#define NOTE_B1 62
+#define NOTE_C2 65
+#define NOTE_CS2 69
+#define NOTE_D2 73
+#define NOTE_DS2 78
+#define NOTE_E2 82
+#define NOTE_F2 87
+#define NOTE_FS2 93
+#define NOTE_G2 98
+#define NOTE_GS2 104
+#define NOTE_A2 110
+#define NOTE_AS2 117
+#define NOTE_B2 123
+#define NOTE_C3 131
+#define NOTE_CS3 139
+#define NOTE_D3 147
+#define NOTE_DS3 156
+#define NOTE_E3 165
+#define NOTE_F3 175
+#define NOTE_FS3 185
+#define NOTE_G3 196
+#define NOTE_GS3 208
+#define NOTE_A3 220
+#define NOTE_AS3 233
+#define NOTE_B3 247
+#define NOTE_C4 262
+#define NOTE_CS4 277
+#define NOTE_D4 294
+#define NOTE_DS4 311
+#define NOTE_E4 330
+#define NOTE_F4 349
+#define NOTE_FS4 370
+#define NOTE_G4 392
+#define NOTE_GS4 415
+#define NOTE_A4 440
+#define NOTE_AS4 466
+#define NOTE_B4 494
+#define NOTE_C5 523
+#define NOTE_CS5 554
+#define NOTE_D5 587
+#define NOTE_DS5 622
+#define NOTE_E5 659
+#define NOTE_F5 698
+#define NOTE_FS5 740
+#define NOTE_G5 784
+#define NOTE_GS5 831
+#define NOTE_A5 880
+#define NOTE_AS5 932
+#define NOTE_B5 988
+#define NOTE_C6 1047
+#define NOTE_CS6 1109
+#define NOTE_D6 1175
+#define NOTE_DS6 1245
+#define NOTE_E6 1319
+#define NOTE_F6 1397
+#define NOTE_FS6 1480
+#define NOTE_G6 1568
+#define NOTE_GS6 1661
+#define NOTE_A6 1760
+#define NOTE_AS6 1865
+#define NOTE_B6 1976
+#define NOTE_C7 2093
+#define NOTE_CS7 2217
+#define NOTE_D7 2349
+#define NOTE_DS7 2489
+#define NOTE_E7 2637
+#define NOTE_F7 2794
+#define NOTE_FS7 2960
+#define NOTE_G7 3136
+#define NOTE_GS7 3322
+#define NOTE_A7 3520
+#define NOTE_AS7 3729
+#define NOTE_B7 3951
+#define NOTE_C8 4186
+#define NOTE_CS8 4435
+#define NOTE_D8 4699
+#define NOTE_DS8 4978
+
+
diff --git a/examples/toneMelody/toneMelody.ino b/examples/toneMelody/toneMelody.ino
new file mode 100644
index 0000000..8593ab7
--- /dev/null
+++ b/examples/toneMelody/toneMelody.ino
@@ -0,0 +1,49 @@
+/*
+ Melody
+
+ Plays a melody
+
+ circuit:
+ * 8-ohm speaker on digital pin 8
+
+ created 21 Jan 2010
+ modified 30 Aug 2011
+ by Tom Igoe
+
+This example code is in the public domain.
+
+ http://arduino.cc/en/Tutorial/Tone
+
+ */
+ #include "pitches.h"
+
+// notes in the melody:
+int melody[] = {
+ NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};
+
+// note durations: 4 = quarter note, 8 = eighth note, etc.:
+int noteDurations[] = {
+ 4, 8, 8, 4,4,4,4,4 };
+
+void setup() {
+ // iterate over the notes of the melody:
+ for (int thisNote = 0; thisNote < 8; thisNote++) {
+
+ // to calculate the note duration, take one second
+ // divided by the note type.
+ //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
+ int noteDuration = 1000/noteDurations[thisNote];
+ tone(8, melody[thisNote],noteDuration);
+
+ // to distinguish the notes, set a minimum time between them.
+ // the note's duration + 30% seems to work well:
+ int pauseBetweenNotes = noteDuration * 1.30;
+ delay(pauseBetweenNotes);
+ // stop the tone playing:
+ noTone(8);
+ }
+}
+
+void loop() {
+ // no need to repeat the melody.
+}