From 086c6e96ca4b98e8a144b5f7f37a7b3b6fedc61d Mon Sep 17 00:00:00 2001 From: Christopher Peplin Date: Sat, 20 Sep 2014 16:14:32 -0400 Subject: Move tests back to 'examples', skip non-testable examples when testing. This fixes https://github.com/sudar/Arduino-Makefile/issues/259. --- examples/AnalogInOutSerial/AnalogInOutSerial.ino | 53 +++++++++++++ examples/AnalogInOutSerial/Makefile | 5 ++ examples/Blink/Blink.ino | 19 +++++ examples/Blink/Makefile | 6 ++ examples/BlinkChipKIT/BlinkChipKIT.pde | 19 +++++ examples/BlinkChipKIT/Makefile | 6 ++ examples/BlinkInAVRC/Makefile | 17 +++++ examples/BlinkInAVRC/blink.c | 38 ++++++++++ examples/BlinkWithoutDelay/BlinkWithoutDelay.ino | 65 ++++++++++++++++ examples/BlinkWithoutDelay/Makefile | 5 ++ examples/Fade/Fade.ino | 31 ++++++++ examples/Fade/Makefile | 5 ++ examples/HelloWorld/HelloWorld.ino | 58 +++++++++++++++ examples/HelloWorld/Makefile | 5 ++ examples/TestSuiteCommon.mk | 13 ++++ examples/WebServer/Makefile | 7 ++ examples/WebServer/WebServer.ino | 82 ++++++++++++++++++++ examples/master_reader/Makefile | 7 ++ examples/master_reader/master_reader.ino | 32 ++++++++ examples/toneMelody/Makefile | 5 ++ examples/toneMelody/pitches.h | 95 ++++++++++++++++++++++++ examples/toneMelody/toneMelody.ino | 49 ++++++++++++ script/runtests.sh | 22 +++++- tests/AnalogInOutSerial/AnalogInOutSerial.ino | 53 ------------- tests/AnalogInOutSerial/Makefile | 5 -- tests/Blink/Blink.ino | 19 ----- tests/Blink/Makefile | 6 -- tests/BlinkChipKIT/BlinkChipKIT.pde | 19 ----- tests/BlinkChipKIT/Makefile | 6 -- tests/BlinkInAVRC/Makefile | 17 ----- tests/BlinkInAVRC/blink.c | 38 ---------- tests/BlinkWithoutDelay/BlinkWithoutDelay.ino | 65 ---------------- tests/BlinkWithoutDelay/Makefile | 5 -- tests/Fade/Fade.ino | 31 -------- tests/Fade/Makefile | 5 -- tests/HelloWorld/HelloWorld.ino | 58 --------------- tests/HelloWorld/Makefile | 5 -- tests/TestSuiteCommon.mk | 13 ---- tests/WebServer/Makefile | 7 -- tests/WebServer/WebServer.ino | 82 -------------------- tests/master_reader/Makefile | 7 -- tests/master_reader/master_reader.ino | 32 -------- tests/toneMelody/Makefile | 5 -- tests/toneMelody/pitches.h | 95 ------------------------ tests/toneMelody/toneMelody.ino | 49 ------------ 45 files changed, 643 insertions(+), 623 deletions(-) create mode 100644 examples/AnalogInOutSerial/AnalogInOutSerial.ino create mode 100644 examples/AnalogInOutSerial/Makefile create mode 100644 examples/Blink/Blink.ino create mode 100644 examples/Blink/Makefile create mode 100644 examples/BlinkChipKIT/BlinkChipKIT.pde create mode 100644 examples/BlinkChipKIT/Makefile create mode 100644 examples/BlinkInAVRC/Makefile create mode 100644 examples/BlinkInAVRC/blink.c create mode 100644 examples/BlinkWithoutDelay/BlinkWithoutDelay.ino create mode 100644 examples/BlinkWithoutDelay/Makefile create mode 100644 examples/Fade/Fade.ino create mode 100644 examples/Fade/Makefile create mode 100644 examples/HelloWorld/HelloWorld.ino create mode 100644 examples/HelloWorld/Makefile create mode 100644 examples/TestSuiteCommon.mk create mode 100644 examples/WebServer/Makefile create mode 100644 examples/WebServer/WebServer.ino create mode 100644 examples/master_reader/Makefile create mode 100644 examples/master_reader/master_reader.ino create mode 100644 examples/toneMelody/Makefile create mode 100644 examples/toneMelody/pitches.h create mode 100644 examples/toneMelody/toneMelody.ino delete mode 100644 tests/AnalogInOutSerial/AnalogInOutSerial.ino delete mode 100644 tests/AnalogInOutSerial/Makefile delete mode 100644 tests/Blink/Blink.ino delete mode 100644 tests/Blink/Makefile delete mode 100644 tests/BlinkChipKIT/BlinkChipKIT.pde delete mode 100644 tests/BlinkChipKIT/Makefile delete mode 100644 tests/BlinkInAVRC/Makefile delete mode 100644 tests/BlinkInAVRC/blink.c delete mode 100644 tests/BlinkWithoutDelay/BlinkWithoutDelay.ino delete mode 100644 tests/BlinkWithoutDelay/Makefile delete mode 100644 tests/Fade/Fade.ino delete mode 100644 tests/Fade/Makefile delete mode 100644 tests/HelloWorld/HelloWorld.ino delete mode 100644 tests/HelloWorld/Makefile delete mode 100644 tests/TestSuiteCommon.mk delete mode 100644 tests/WebServer/Makefile delete mode 100644 tests/WebServer/WebServer.ino delete mode 100644 tests/master_reader/Makefile delete mode 100644 tests/master_reader/master_reader.ino delete mode 100644 tests/toneMelody/Makefile delete mode 100644 tests/toneMelody/pitches.h delete mode 100644 tests/toneMelody/toneMelody.ino 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 +#include + +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 + +// 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..5fa4f50 --- /dev/null +++ b/examples/TestSuiteCommon.mk @@ -0,0 +1,13 @@ +ARDMK_DIR=../../ +DEPENDENCIES_FOLDER = ../../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 +#include + +// 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("
"); + } + 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 + +// 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 + +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. +} diff --git a/script/runtests.sh b/script/runtests.sh index ad42f74..5f513da 100755 --- a/script/runtests.sh +++ b/script/runtests.sh @@ -1,11 +1,31 @@ #!/usr/bin/env bash +TESTS_DIR=examples + failures=() -for dir in tests/*/ +# These examples cannot be tested easily at the moment as they require +# alternate cores. The MakefileExample doesn't actually contain any source code +# to compile. +NON_TESTABLE_EXAMPLES=(ATtinyBlink MakefileExample TinySoftWareSerial) + +for dir in $TESTS_DIR/*/ do dir=${dir%*/} example=${dir##*/} + example_is_testable=true + for non_testable_example in "${NON_TESTABLE_EXAMPLES[@]}"; do + if [[ $example == $non_testable_example ]]; then + example_is_testable=false + break + fi + done + + if ! $example_is_testable; then + echo "Skipping non-testable example $example..." + continue + fi + pushd $dir echo "Compiling $example..." make_output=`make clean` diff --git a/tests/AnalogInOutSerial/AnalogInOutSerial.ino b/tests/AnalogInOutSerial/AnalogInOutSerial.ino deleted file mode 100644 index e142f69..0000000 --- a/tests/AnalogInOutSerial/AnalogInOutSerial.ino +++ /dev/null @@ -1,53 +0,0 @@ -/* - 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/tests/AnalogInOutSerial/Makefile b/tests/AnalogInOutSerial/Makefile deleted file mode 100644 index 872d069..0000000 --- a/tests/AnalogInOutSerial/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -BOARD_TAG = uno -ARDUINO_LIBS = - -include ../TestSuiteCommon.mk -include ../../Arduino.mk diff --git a/tests/Blink/Blink.ino b/tests/Blink/Blink.ino deleted file mode 100644 index 1953c39..0000000 --- a/tests/Blink/Blink.ino +++ /dev/null @@ -1,19 +0,0 @@ -/* - 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/tests/Blink/Makefile b/tests/Blink/Makefile deleted file mode 100644 index d41effa..0000000 --- a/tests/Blink/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -BOARD_TAG = uno -ARDUINO_LIBS = - -include ../TestSuiteCommon.mk -include ../../Arduino.mk - diff --git a/tests/BlinkChipKIT/BlinkChipKIT.pde b/tests/BlinkChipKIT/BlinkChipKIT.pde deleted file mode 100644 index 1953c39..0000000 --- a/tests/BlinkChipKIT/BlinkChipKIT.pde +++ /dev/null @@ -1,19 +0,0 @@ -/* - 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/tests/BlinkChipKIT/Makefile b/tests/BlinkChipKIT/Makefile deleted file mode 100644 index bec2794..0000000 --- a/tests/BlinkChipKIT/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -BOARD_TAG = mega_pic32 -ARDUINO_LIBS = - -include ../TestSuiteCommon.mk -include ../../chipKIT.mk - diff --git a/tests/BlinkInAVRC/Makefile b/tests/BlinkInAVRC/Makefile deleted file mode 100644 index 9080b24..0000000 --- a/tests/BlinkInAVRC/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -# 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/tests/BlinkInAVRC/blink.c b/tests/BlinkInAVRC/blink.c deleted file mode 100644 index d8b7c8f..0000000 --- a/tests/BlinkInAVRC/blink.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - * © Anil Kumar Pugalia, 2010. Email: email@sarika-pugs.com - * - * ATmega48/88/168, ATmega16/32 - * - * Example Blink. Toggles all IO pins at 1Hz - */ - -#include -#include - -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/tests/BlinkWithoutDelay/BlinkWithoutDelay.ino b/tests/BlinkWithoutDelay/BlinkWithoutDelay.ino deleted file mode 100644 index 0143571..0000000 --- a/tests/BlinkWithoutDelay/BlinkWithoutDelay.ino +++ /dev/null @@ -1,65 +0,0 @@ -/* 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/tests/BlinkWithoutDelay/Makefile b/tests/BlinkWithoutDelay/Makefile deleted file mode 100644 index 872d069..0000000 --- a/tests/BlinkWithoutDelay/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -BOARD_TAG = uno -ARDUINO_LIBS = - -include ../TestSuiteCommon.mk -include ../../Arduino.mk diff --git a/tests/Fade/Fade.ino b/tests/Fade/Fade.ino deleted file mode 100644 index b47bf43..0000000 --- a/tests/Fade/Fade.ino +++ /dev/null @@ -1,31 +0,0 @@ -/* - 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/tests/Fade/Makefile b/tests/Fade/Makefile deleted file mode 100644 index 872d069..0000000 --- a/tests/Fade/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -BOARD_TAG = uno -ARDUINO_LIBS = - -include ../TestSuiteCommon.mk -include ../../Arduino.mk diff --git a/tests/HelloWorld/HelloWorld.ino b/tests/HelloWorld/HelloWorld.ino deleted file mode 100644 index e99957d..0000000 --- a/tests/HelloWorld/HelloWorld.ino +++ /dev/null @@ -1,58 +0,0 @@ -/* - 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 - -// 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/tests/HelloWorld/Makefile b/tests/HelloWorld/Makefile deleted file mode 100644 index 0af2ed4..0000000 --- a/tests/HelloWorld/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -BOARD_TAG = uno -ARDUINO_LIBS = LiquidCrystal - -include ../TestSuiteCommon.mk -include ../../Arduino.mk diff --git a/tests/TestSuiteCommon.mk b/tests/TestSuiteCommon.mk deleted file mode 100644 index 5fa4f50..0000000 --- a/tests/TestSuiteCommon.mk +++ /dev/null @@ -1,13 +0,0 @@ -ARDMK_DIR=../../ -DEPENDENCIES_FOLDER = ../../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/tests/WebServer/Makefile b/tests/WebServer/Makefile deleted file mode 100644 index 5fbefae..0000000 --- a/tests/WebServer/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# 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/tests/WebServer/WebServer.ino b/tests/WebServer/WebServer.ino deleted file mode 100644 index fb2a1b9..0000000 --- a/tests/WebServer/WebServer.ino +++ /dev/null @@ -1,82 +0,0 @@ -/* - 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 -#include - -// 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("
"); - } - 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/tests/master_reader/Makefile b/tests/master_reader/Makefile deleted file mode 100644 index 8a42a8e..0000000 --- a/tests/master_reader/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# 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/tests/master_reader/master_reader.ino b/tests/master_reader/master_reader.ino deleted file mode 100644 index 4124d7d..0000000 --- a/tests/master_reader/master_reader.ino +++ /dev/null @@ -1,32 +0,0 @@ -// Wire Master Reader -// by Nicholas Zambetti - -// 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 - -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/tests/toneMelody/Makefile b/tests/toneMelody/Makefile deleted file mode 100644 index 872d069..0000000 --- a/tests/toneMelody/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -BOARD_TAG = uno -ARDUINO_LIBS = - -include ../TestSuiteCommon.mk -include ../../Arduino.mk diff --git a/tests/toneMelody/pitches.h b/tests/toneMelody/pitches.h deleted file mode 100644 index 55c7d54..0000000 --- a/tests/toneMelody/pitches.h +++ /dev/null @@ -1,95 +0,0 @@ -/************************************************* - * 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/tests/toneMelody/toneMelody.ino b/tests/toneMelody/toneMelody.ino deleted file mode 100644 index 8593ab7..0000000 --- a/tests/toneMelody/toneMelody.ino +++ /dev/null @@ -1,49 +0,0 @@ -/* - 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. -} -- cgit v1.2.3