From: Andrea Manni Date: Thu, 16 Apr 2015 13:45:41 +0000 (+0200) Subject: ezo e RGB X-Git-Url: http://git.piffa.net/web?p=sketchbook_andrea;a=commitdiff_plain;h=54de1d245a98a8032e8c41089158321f6be58b1c ezo e RGB --- diff --git a/README b/README index 6601373..5f7f14d 100644 --- a/README +++ b/README @@ -47,72 +47,104 @@ presentati con i PWM. Debug Seriale ================================ -basic/serial_debug/serial_hello_world/ +- basic/serial_debug/serial_hello_world/ Digital input ================================ Cicli condizionali -basic/buttons/button_1 -basic/buttons/button_2_serial_debug/ +- basic/buttons/button_1 +- basic/buttons/button_2_serial_debug/ (pull down e pull up) Analog input ================================ -basic/analog_input/analogInput_1/analogInput_1.ino -basic/analog_input/analogInput_2_serial/analogInput_2_serial.ino +- basic/analog_input/analogInput_1/analogInput_1.ino +- basic/analog_input/analogInput_2_serial/analogInput_2_serial.ino Programmazione ================================ -Data types: http://www.ladyada.net/learn/arduino/lesson4.html +- Data types: http://www.ladyada.net/learn/arduino/lesson4.html fare byte - int - long -Magari uno script con serial print, eventualmente anche esadecimale +- Magari uno script con serial print, eventualmente anche esadecimale Analog Output ================================ Cicli iterativi while -basic/pwm/pwm_0_manuale/pwm_0_manuale.ino Dimostrativo -basic/pwm/pwm_1_while_byte/pwm_1_while_byte.ino -basic/pwm/pwm_1_soluzione_doppio_while_byte/pwm_1_soluzione_doppio_while_byte.ino +- basic/pwm/pwm_0_manuale/pwm_0_manuale.ino Dimostrativo +- basic/pwm/pwm_1_while_byte/pwm_1_while_byte.ino +- basic/pwm/pwm_1_soluzione_doppio_while_byte/pwm_1_soluzione_doppio_while_byte.ino Programmazione: operatori binari ================================ -programming/operators/operator_1_basic/operator_1_basic.ino -programming/operators/operator_2_comparison/operator_2_comparison.ino +- programming/operators/operator_1_basic/operator_1_basic.ino +- programming/operators/operator_2_comparison/operator_2_comparison.ino Analog Output ================================ Cicli iterativi For, operatore ternario -basic/pwm/pwm_2_for_loop/pwm_2_for_loop.ino +- Introduzione for loop: basic/pwm/pwm_2_for_loop/pwm_2_for_loop.ino +- basic/pwm/pwm_3_fade_reverser/pwm_3_fade_reverser.ino +- basic/pwm/pwm_4_analog_input/pwm_4_analog_input.ino + +State machine +================= +Gestione stato di un bottone +Simple multitasking con millis() e due blink contemporanei + +- basic/buttons/button_state_3/button_state_3.ino +- basic/buttons/button_state_4_state/button_state_4_state.ino + Programmazione: operatori logici -================================ +----------------------------------- -programming/operators/operator_3_logic/operator_3_logic.ino +- programming/operators/operator_3_logic/operator_3_logic.ino +State machine: And +------------------- -Analog Output -================================ +- basic/buttons/button_state_4_state_and_condition/button_state_4_state_and_condition.ino -basic/pwm/pwm_3_fade_reverser/pwm_3_fade_reverser.ino -basic/pwm/pwm_4_analog_input/pwm_4_analog_input.ino For loop ========== +Approfondimento su i cicli for, uso degli array + +- programming/loops/loop_3_multi_led/loop_3_multi_led.ino +- Array: programming/loops/loop_4_multi_led_array/loop_4_multi_led_array.ino +- sketchbook_andrea/programming/loops/ +- Random e interruzione del flusso del programma tramite if + + +Light sensor +=============== + +- basic/analog_input/photo_3_serial/ +- Calibrazione manuale: basic/analog_input/photo_4_calibrated/ +- Calibrazione automatica: basic/analog_input/photo_5_calibration/ +- Smoothing: basic/analog_input/photo_6_smooth/ +- basic/analog_input/photo_7_tonePitchFollower/ + +Piezo +======== +- Traduzione tra due percezioni: basic/analog_input/photo_7_tonePitchFollower/ +- Singole note e pull up: piezo/keyboard_three_pullup_buttons/ +- Melodia: piezo/piezo_3_toneMelody/ +- Melodia: piezo/piezo_4_mario_tune/ + -sketchbook_andrea/programming/loops/ -Random e interruzione del flusso del programma tramite if Status ========== @@ -125,8 +157,8 @@ Completata la parte di: State machine ================= -Gestione stato di un bottone -Simple multitasking con millis() e due blink contemporanei (questo si potrebbe +- Gestione stato di un bottone +- Simple multitasking con millis() e due blink contemporanei (questo si potrebbe fare anche dopo). diff --git a/RGB_LED/RGB_PWM/RGB_PWM.ino b/RGB_LED/RGB_PWM/RGB_PWM.ino deleted file mode 100644 index 9563785..0000000 --- a/RGB_LED/RGB_PWM/RGB_PWM.ino +++ /dev/null @@ -1,60 +0,0 @@ -// This is meant for a Common Anodote RGB LED -// See all those (255 - val). - -#define GREEN 9 -#define BLUE 10 -#define RED 11 -#define delayTime 20 - -void setup() { - - pinMode(GREEN, OUTPUT); - pinMode(BLUE, OUTPUT); - pinMode(RED, OUTPUT); - digitalWrite(GREEN, HIGH); - digitalWrite(BLUE, HIGH); - digitalWrite(RED, HIGH); -} - -int redVal; -int blueVal; -int greenVal; - -void loop() { - - int redVal = 255; - int blueVal = 0; - int greenVal = 0; - for( int i = 0 ; i < 255 ; i += 1 ){ - greenVal += 1; - redVal -= 1; - analogWrite( GREEN, 255 - greenVal ); - analogWrite( RED, 255 - redVal ); - - delay( delayTime ); - } - - redVal = 0; - blueVal = 0; - greenVal = 255; - for( int i = 0 ; i < 255 ; i += 1 ){ - blueVal += 1; - greenVal -= 1; - analogWrite( BLUE, 255 - blueVal ); - analogWrite( GREEN, 255 - greenVal ); - - delay( delayTime ); - } - - redVal = 0; - blueVal = 255; - greenVal = 0; - for( int i = 0 ; i < 255 ; i += 1 ){ - redVal += 1; - blueVal -= 1; - analogWrite( RED, 255 - redVal ); - analogWrite( BLUE, 255 - blueVal ); - - delay( delayTime ); - } -} diff --git a/RGB_LED/ReadASCIIString/ReadASCIIString b/RGB_LED/ReadASCIIString/ReadASCIIString deleted file mode 100644 index 9da6b1e..0000000 --- a/RGB_LED/ReadASCIIString/ReadASCIIString +++ /dev/null @@ -1,66 +0,0 @@ -/* - Reading a serial ASCII-encoded string. - - This sketch demonstrates the Serial parseInt() function. - It looks for an ASCII string of comma-separated values. - It parses them into ints, and uses those to fade an RGB LED. - - Circuit: Common-anode RGB LED wired like so: - * Red cathode: digital pin 3 - * Green cathode: digital pin 5 - * blue cathode: digital pin 6 - * anode: +5V - - created 13 Apr 2012 - by Tom Igoe - - This example code is in the public domain. - */ - -// pins for the LEDs: -const int redPin = 3; -const int greenPin = 5; -const int bluePin = 6; - -void setup() { - // initialize serial: - Serial.begin(9600); - // make the pins outputs: - pinMode(redPin, OUTPUT); - pinMode(greenPin, OUTPUT); - pinMode(bluePin, OUTPUT); - -} - -void loop() { - // if there's any serial available, read it: - while (Serial.available() > 0) { - - // look for the next valid integer in the incoming serial stream: - int red = Serial.parseInt(); - // do it again: - int green = Serial.parseInt(); - // do it again: - int blue = Serial.parseInt(); - - // look for the newline. That's the end of your - // sentence: - if (Serial.read() == '\n') { - // constrain the values to 0 - 255 and invert - // if you're using a common-cathode LED, just use "constrain(color, 0, 255);" - red = 255 - constrain(red, 0, 255); - green = 255 - constrain(green, 0, 255); - blue = 255 - constrain(blue, 0, 255); - - // fade the red, green, and blue legs of the LED: - analogWrite(redPin, red); - analogWrite(greenPin, green); - analogWrite(bluePin, blue); - - // print the three numbers in one string as hexadecimal: - Serial.print(red, HEX); - Serial.print(green, HEX); - Serial.println(blue, HEX); - } - } -} diff --git a/RGB_LED/rgb_1_all_color/rgb_1_all_color.ino b/RGB_LED/rgb_1_all_color/rgb_1_all_color.ino new file mode 100644 index 0000000..29969ad --- /dev/null +++ b/RGB_LED/rgb_1_all_color/rgb_1_all_color.ino @@ -0,0 +1,45 @@ + /* + Adafruit Arduino - Lesson 3. RGB LED + */ + + int redPin = 11; + int greenPin = 10; + int bluePin = 9; + + //uncomment this line if using a Common Anode LED + //#define COMMON_ANODE + + void setup() + { + pinMode(redPin, OUTPUT); + pinMode(greenPin, OUTPUT); + pinMode(bluePin, OUTPUT); + } + + void loop() + { + setColor(255, 0, 0); // red + delay(1000); + setColor(0, 255, 0); // green + delay(1000); + setColor(0, 0, 255); // blue + delay(1000); + setColor(255, 255, 0); // yellow + delay(1000); + setColor(80, 0, 80); // purple + delay(1000); + setColor(0, 255, 255); // aqua + delay(1000); + } + + void setColor(int red, int green, int blue) + { + #ifdef COMMON_ANODE + red = 255 - red; + green = 255 - green; + blue = 255 - blue; + #endif + analogWrite(redPin, red); + analogWrite(greenPin, green); + analogWrite(bluePin, blue); + } diff --git a/RGB_LED/rgb_2_pwm/rgb_2_pwm.ino b/RGB_LED/rgb_2_pwm/rgb_2_pwm.ino new file mode 100644 index 0000000..9563785 --- /dev/null +++ b/RGB_LED/rgb_2_pwm/rgb_2_pwm.ino @@ -0,0 +1,60 @@ +// This is meant for a Common Anodote RGB LED +// See all those (255 - val). + +#define GREEN 9 +#define BLUE 10 +#define RED 11 +#define delayTime 20 + +void setup() { + + pinMode(GREEN, OUTPUT); + pinMode(BLUE, OUTPUT); + pinMode(RED, OUTPUT); + digitalWrite(GREEN, HIGH); + digitalWrite(BLUE, HIGH); + digitalWrite(RED, HIGH); +} + +int redVal; +int blueVal; +int greenVal; + +void loop() { + + int redVal = 255; + int blueVal = 0; + int greenVal = 0; + for( int i = 0 ; i < 255 ; i += 1 ){ + greenVal += 1; + redVal -= 1; + analogWrite( GREEN, 255 - greenVal ); + analogWrite( RED, 255 - redVal ); + + delay( delayTime ); + } + + redVal = 0; + blueVal = 0; + greenVal = 255; + for( int i = 0 ; i < 255 ; i += 1 ){ + blueVal += 1; + greenVal -= 1; + analogWrite( BLUE, 255 - blueVal ); + analogWrite( GREEN, 255 - greenVal ); + + delay( delayTime ); + } + + redVal = 0; + blueVal = 255; + greenVal = 0; + for( int i = 0 ; i < 255 ; i += 1 ){ + redVal += 1; + blueVal -= 1; + analogWrite( RED, 255 - redVal ); + analogWrite( BLUE, 255 - blueVal ); + + delay( delayTime ); + } +} diff --git a/RGB_LED/rgb_3_ReadASCIIString/rgb_3_ReadASCIIString.ino b/RGB_LED/rgb_3_ReadASCIIString/rgb_3_ReadASCIIString.ino new file mode 100644 index 0000000..9da6b1e --- /dev/null +++ b/RGB_LED/rgb_3_ReadASCIIString/rgb_3_ReadASCIIString.ino @@ -0,0 +1,66 @@ +/* + Reading a serial ASCII-encoded string. + + This sketch demonstrates the Serial parseInt() function. + It looks for an ASCII string of comma-separated values. + It parses them into ints, and uses those to fade an RGB LED. + + Circuit: Common-anode RGB LED wired like so: + * Red cathode: digital pin 3 + * Green cathode: digital pin 5 + * blue cathode: digital pin 6 + * anode: +5V + + created 13 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + */ + +// pins for the LEDs: +const int redPin = 3; +const int greenPin = 5; +const int bluePin = 6; + +void setup() { + // initialize serial: + Serial.begin(9600); + // make the pins outputs: + pinMode(redPin, OUTPUT); + pinMode(greenPin, OUTPUT); + pinMode(bluePin, OUTPUT); + +} + +void loop() { + // if there's any serial available, read it: + while (Serial.available() > 0) { + + // look for the next valid integer in the incoming serial stream: + int red = Serial.parseInt(); + // do it again: + int green = Serial.parseInt(); + // do it again: + int blue = Serial.parseInt(); + + // look for the newline. That's the end of your + // sentence: + if (Serial.read() == '\n') { + // constrain the values to 0 - 255 and invert + // if you're using a common-cathode LED, just use "constrain(color, 0, 255);" + red = 255 - constrain(red, 0, 255); + green = 255 - constrain(green, 0, 255); + blue = 255 - constrain(blue, 0, 255); + + // fade the red, green, and blue legs of the LED: + analogWrite(redPin, red); + analogWrite(greenPin, green); + analogWrite(bluePin, blue); + + // print the three numbers in one string as hexadecimal: + Serial.print(red, HEX); + Serial.print(green, HEX); + Serial.println(blue, HEX); + } + } +} diff --git a/RGB_LED/rgb_all_color/rgb_all_color.ino b/RGB_LED/rgb_all_color/rgb_all_color.ino deleted file mode 100644 index 29969ad..0000000 --- a/RGB_LED/rgb_all_color/rgb_all_color.ino +++ /dev/null @@ -1,45 +0,0 @@ - /* - Adafruit Arduino - Lesson 3. RGB LED - */ - - int redPin = 11; - int greenPin = 10; - int bluePin = 9; - - //uncomment this line if using a Common Anode LED - //#define COMMON_ANODE - - void setup() - { - pinMode(redPin, OUTPUT); - pinMode(greenPin, OUTPUT); - pinMode(bluePin, OUTPUT); - } - - void loop() - { - setColor(255, 0, 0); // red - delay(1000); - setColor(0, 255, 0); // green - delay(1000); - setColor(0, 0, 255); // blue - delay(1000); - setColor(255, 255, 0); // yellow - delay(1000); - setColor(80, 0, 80); // purple - delay(1000); - setColor(0, 255, 255); // aqua - delay(1000); - } - - void setColor(int red, int green, int blue) - { - #ifdef COMMON_ANODE - red = 255 - red; - green = 255 - green; - blue = 255 - blue; - #endif - analogWrite(redPin, red); - analogWrite(greenPin, green); - analogWrite(bluePin, blue); - } diff --git a/basic/analog_input/photo_5_calibration/photo_5_calibration.ino b/basic/analog_input/photo_5_calibration/photo_5_calibration.ino index db0d2b0..1cdc1b1 100644 --- a/basic/analog_input/photo_5_calibration/photo_5_calibration.ino +++ b/basic/analog_input/photo_5_calibration/photo_5_calibration.ino @@ -78,3 +78,4 @@ Domande: 1. Modificare lo sketch in modo che modifichi la luminosita' di un led via PWM tramite il valore letto dal sensore. 2. Come fare per costringere la variabile dentro un intervallo stabilito? + diff --git a/basic/analog_input/photo_7_tonePitchFollower/photo_7_tonePitchFollower.ino b/basic/analog_input/photo_7_tonePitchFollower/photo_7_tonePitchFollower.ino new file mode 100644 index 0000000..e74c7b3 --- /dev/null +++ b/basic/analog_input/photo_7_tonePitchFollower/photo_7_tonePitchFollower.ino @@ -0,0 +1,47 @@ +/* + Pitch follower + + Plays a pitch that changes based on a changing analog input + + circuit: + * 8-ohm speaker on digital pin 8 + * photoresistor on analog 0 to 5V + * 4.7K resistor on analog 0 to ground + + created 21 Jan 2010 + modified 31 May 2012 + by Tom Igoe, with suggestion from Michael Flynn + +This example code is in the public domain. + + http://arduino.cc/en/Tutorial/Tone2 + + */ + + +void setup() { + // initialize serial communications (for debugging only): + Serial.begin(9600); +} + +void loop() { + // read the sensor: + int sensorReading = analogRead(A0); + // print the sensor reading so you know its range + Serial.println(sensorReading); + // map the analog input range (in this case, 400 - 1000 from the photoresistor) + // to the output pitch range (120 - 1500Hz) + // change the minimum and maximum input numbers below + // depending on the range your sensor's giving: + int thisPitch = map(sensorReading, 400, 1000, 120, 1500); + + // play the pitch: + tone(9, thisPitch, 10); + delay(1); // delay in between reads for stability +} + + + + + + diff --git a/basic/analog_input/photo_7_tonePitchFollower/photo_7_tonePitchFollower_ino/photo_7_tonePitchFollower_ino.ino b/basic/analog_input/photo_7_tonePitchFollower/photo_7_tonePitchFollower_ino/photo_7_tonePitchFollower_ino.ino new file mode 100644 index 0000000..31d41a6 --- /dev/null +++ b/basic/analog_input/photo_7_tonePitchFollower/photo_7_tonePitchFollower_ino/photo_7_tonePitchFollower_ino.ino @@ -0,0 +1,64 @@ +/* +Pitch following + +The input from a photo resistor dictates the pitch of a piezo. + + + */ + +// These constants won't change: +const int sensorPin = A0; // pin that the sensor is attached to +const int ledPin = 9; // pin that the LED is attached to +int thisPitch ; + +// calibration variables: +int sensorValue = 0; // the sensor value +int sensorMin = 1023; // minimum sensor value +int sensorMax = 0; // maximum sensor value + + +void setup() { + // turn on LED to signal the start of the calibration period: + pinMode(13, OUTPUT); + digitalWrite(13, HIGH); + + // calibrate during the first five seconds + while (millis() < 5000) { + sensorValue = analogRead(sensorPin); + + // record the maximum sensor value + if (sensorValue > sensorMax) { + sensorMax = sensorValue; + } + + // record the minimum sensor value + if (sensorValue < sensorMin) { + sensorMin = sensorValue; + } + } + + // signal the end of the calibration period + digitalWrite(13, LOW); +} + +void loop() { + // read the sensor: + sensorValue = analogRead(sensorPin); + + // apply the calibration to the sensor reading + thisPitch = map(sensorValue, sensorMin, sensorMax, 120, 1500); + // map the analog input range (in this case, min - max from the photoresistor) + // to the output pitch range (120 - 1500Hz) + // change the minimum and maximum input numbers below + // depending on the range your sensor's giving: + + // in case the sensor value is outside the range seen during calibration + thisPitch = constrain(sensorValue, 120, 1500); + + + + // play the pitch: + tone(ledPin, thisPitch, 10); // Tone is built in function + delay(1); // delay in between reads for stability +} + diff --git a/libraries/pitches.h b/libraries/pitches.h new file mode 100644 index 0000000..55c7d54 --- /dev/null +++ b/libraries/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/piezo/piezo_1_tonePitchFollower/piezo_1_tonePitchFollower.ino b/piezo/piezo_1_tonePitchFollower/piezo_1_tonePitchFollower.ino new file mode 100644 index 0000000..e74c7b3 --- /dev/null +++ b/piezo/piezo_1_tonePitchFollower/piezo_1_tonePitchFollower.ino @@ -0,0 +1,47 @@ +/* + Pitch follower + + Plays a pitch that changes based on a changing analog input + + circuit: + * 8-ohm speaker on digital pin 8 + * photoresistor on analog 0 to 5V + * 4.7K resistor on analog 0 to ground + + created 21 Jan 2010 + modified 31 May 2012 + by Tom Igoe, with suggestion from Michael Flynn + +This example code is in the public domain. + + http://arduino.cc/en/Tutorial/Tone2 + + */ + + +void setup() { + // initialize serial communications (for debugging only): + Serial.begin(9600); +} + +void loop() { + // read the sensor: + int sensorReading = analogRead(A0); + // print the sensor reading so you know its range + Serial.println(sensorReading); + // map the analog input range (in this case, 400 - 1000 from the photoresistor) + // to the output pitch range (120 - 1500Hz) + // change the minimum and maximum input numbers below + // depending on the range your sensor's giving: + int thisPitch = map(sensorReading, 400, 1000, 120, 1500); + + // play the pitch: + tone(9, thisPitch, 10); + delay(1); // delay in between reads for stability +} + + + + + + diff --git a/piezo/piezo_1_tonePitchFollower/piezo_1_tonePitchFollower_ino/piezo_1_tonePitchFollower_ino.ino b/piezo/piezo_1_tonePitchFollower/piezo_1_tonePitchFollower_ino/piezo_1_tonePitchFollower_ino.ino new file mode 100644 index 0000000..b5e9d24 --- /dev/null +++ b/piezo/piezo_1_tonePitchFollower/piezo_1_tonePitchFollower_ino/piezo_1_tonePitchFollower_ino.ino @@ -0,0 +1,64 @@ +/* +Pitch following + +The input from a photo resistor dictates the pitch of a piezo. + + + */ + +// These constants won't change: +const int sensorPin = A0; // pin that the sensor is attached to +const int ledPin = 9; // pin that the LED is attached to +int thisPitch ; + +// calibration variables: +int sensorValue = 0; // the sensor value +int sensorMin = 1023; // minimum sensor value +int sensorMax = 0; // maximum sensor value + + +void setup() { + // turn on LED to signal the start of the calibration period: + pinMode(13, OUTPUT); + digitalWrite(13, HIGH); + + // calibrate during the first five seconds + while (millis() < 5000) { + sensorValue = analogRead(sensorPin); + + // record the maximum sensor value + if (sensorValue > sensorMax) { + sensorMax = sensorValue; + } + + // record the minimum sensor value + if (sensorValue < sensorMin) { + sensorMin = sensorValue; + } + } + + // signal the end of the calibration period + digitalWrite(13, LOW); +} + +void loop() { + // read the sensor: + sensorValue = analogRead(sensorPin); + + // apply the calibration to the sensor reading + thisPitch = map(sensorValue, sensorMin, sensorMax, 120, 1500); + // map the analog input range (in this case, min - max from the photoresistor) + // to the output pitch range (120 - 1500Hz) + // change the minimum and maximum input numbers below + // depending on the range your sensor's giving: + + // in case the sensor value is outside the range seen during calibration + thisPitch = constrain(sensorValue, 120, 1500); + + + + // play the pitch: + tone(ledPin, thisPitch, 10); // Tone is built in function + delay(1); // delay in between notes +} + diff --git a/piezo/piezo_2_keyboard/piezo_2_keyboard.ino b/piezo/piezo_2_keyboard/piezo_2_keyboard.ino new file mode 100644 index 0000000..ae3aabd --- /dev/null +++ b/piezo/piezo_2_keyboard/piezo_2_keyboard.ino @@ -0,0 +1,56 @@ +/* + Melody keyboard with Input Pullup Serial + Plays a pitch that changes based on 3 digital inputs + + This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a + digital input on pin 2 and prints the results to the serial monitor. + + Thecircuit: + * 3 buttons in pin 2,3,4 with no resistors + * Piezo on digital pin 9 + * Serial debug is available + + This example code is in the public domain + + Circuit: http://lab.piffa.net/schemi/piezo_2_keyboard_bb.png + + */ + + +int input[]= { + 1,2,3}; +int notes[] = { + 262, 392,880 }; // suona una prima, quinta, ottava in C4 + +// Carica un file di esempio con tutte le note +// #include "pitches.h"; +// int notes[] = {NOTE_C4, NOTE_G4,NOTE_A5 }; // suona una prima, quinta, ottava + +void setup(){ + //start serial connection + Serial.begin(9600); + //configure pin2/3/4 as an input and enable the internal pull-up resistor + pinMode(2, INPUT_PULLUP); + pinMode(3, INPUT_PULLUP); + pinMode(4, INPUT_PULLUP); + pinMode(9, OUTPUT); +} + +void loop(){ + for (int thisSensor = 2; thisSensor < 5; thisSensor++) { + int sensorReading = digitalRead(thisSensor); + if (sensorReading == LOW) { + Serial.println(thisSensor); + tone(9, notes[thisSensor -2], 50); // Notes array is translated + } + //delay(2); // eventuale delay + } +} +/* Domande + 1. Modificare le note suonate utilizzando come riferimento il file pitches.h: + suonare una prima, terza, quinta (C-E-G) + 2. Includere il file pitches.h . Come si potrebbe scrivere una melodia da far suonare + autnomamente ad Arduino? + */ + + diff --git a/piezo/piezo_3_toneMelody/piezo_3_toneMelody.ino b/piezo/piezo_3_toneMelody/piezo_3_toneMelody.ino new file mode 100644 index 0000000..a5c5701 --- /dev/null +++ b/piezo/piezo_3_toneMelody/piezo_3_toneMelody.ino @@ -0,0 +1,55 @@ +/* + 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" + +int piezoPin = 9 ; +// 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(piezoPin, 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(piezoPin); + } +} + +void loop() { + // no need to repeat the melody. + // RESET to play again +} + +/* Domande +1. Codificare Twinkle twinkle little star +*/ diff --git a/piezo/piezo_3_toneMelody/pitches.h b/piezo/piezo_3_toneMelody/pitches.h new file mode 100644 index 0000000..55c7d54 --- /dev/null +++ b/piezo/piezo_3_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/piezo/piezo_4_mario_tune/piezo_4_mario_tune.ino b/piezo/piezo_4_mario_tune/piezo_4_mario_tune.ino new file mode 100644 index 0000000..12dc602 --- /dev/null +++ b/piezo/piezo_4_mario_tune/piezo_4_mario_tune.ino @@ -0,0 +1,193 @@ +/* + Arduino Mario Bros Tunes + With Piezo Buzzer and PWM + by: Dipto Pratyaksa + last updated: 31/3/13 +*/ +#include +//#include "/home/utente/sketchbook-andrea/piezo/piezo_mario_tune/pitches.h"; +#define melodyPin 3 +//Mario main theme melody +int melody[] = { + NOTE_E7, NOTE_E7, 0, NOTE_E7, + 0, NOTE_C7, NOTE_E7, 0, + NOTE_G7, 0, 0, 0, + NOTE_G6, 0, 0, 0, + + NOTE_C7, 0, 0, NOTE_G6, + 0, 0, NOTE_E6, 0, + 0, NOTE_A6, 0, NOTE_B6, + 0, NOTE_AS6, NOTE_A6, 0, + + NOTE_G6, NOTE_E7, NOTE_G7, + NOTE_A7, 0, NOTE_F7, NOTE_G7, + 0, NOTE_E7, 0,NOTE_C7, + NOTE_D7, NOTE_B6, 0, 0, + + NOTE_C7, 0, 0, NOTE_G6, + 0, 0, NOTE_E6, 0, + 0, NOTE_A6, 0, NOTE_B6, + 0, NOTE_AS6, NOTE_A6, 0, + + NOTE_G6, NOTE_E7, NOTE_G7, + NOTE_A7, 0, NOTE_F7, NOTE_G7, + 0, NOTE_E7, 0,NOTE_C7, + NOTE_D7, NOTE_B6, 0, 0 +}; +//Mario main them tempo +int tempo[] = { + 12, 12, 12, 12, + 12, 12, 12, 12, + 12, 12, 12, 12, + 12, 12, 12, 12, + + 12, 12, 12, 12, + 12, 12, 12, 12, + 12, 12, 12, 12, + 12, 12, 12, 12, + + 9, 9, 9, + 12, 12, 12, 12, + 12, 12, 12, 12, + 12, 12, 12, 12, + + 12, 12, 12, 12, + 12, 12, 12, 12, + 12, 12, 12, 12, + 12, 12, 12, 12, + + 9, 9, 9, + 12, 12, 12, 12, + 12, 12, 12, 12, + 12, 12, 12, 12, +}; + +// + +//Underworld melody +int underworld_melody[] = { + NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4, + NOTE_AS3, NOTE_AS4, 0, + 0, + NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4, + NOTE_AS3, NOTE_AS4, 0, + 0, + NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4, + NOTE_DS3, NOTE_DS4, 0, + 0, + NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4, + NOTE_DS3, NOTE_DS4, 0, + 0, NOTE_DS4, NOTE_CS4, NOTE_D4, + NOTE_CS4, NOTE_DS4, + NOTE_DS4, NOTE_GS3, + NOTE_G3, NOTE_CS4, + NOTE_C4, NOTE_FS4,NOTE_F4, NOTE_E3, NOTE_AS4, NOTE_A4, + NOTE_GS4, NOTE_DS4, NOTE_B3, + NOTE_AS3, NOTE_A3, NOTE_GS3, + 0, 0, 0 +}; +//Underwolrd tempo +int underworld_tempo[] = { + 12, 12, 12, 12, + 12, 12, 6, + 3, + 12, 12, 12, 12, + 12, 12, 6, + 3, + 12, 12, 12, 12, + 12, 12, 6, + 3, + 12, 12, 12, 12, + 12, 12, 6, + 6, 18, 18, 18, + 6, 6, + 6, 6, + 6, 6, + 18, 18, 18,18, 18, 18, + 10, 10, 10, + 10, 10, 10, + 3, 3, 3 +}; + +void setup(void) +{ + pinMode(3, OUTPUT);//buzzer + pinMode(13, OUTPUT);//led indicator when singing a note + +} +void loop() +{ +//sing the tunes + sing(1); + sing(1); + sing(2); +} +int song = 0; + +void sing(int s){ + // iterate over the notes of the melody: + song = s; + if(song==2){ + Serial.println(" 'Underworld Theme'"); + int size = sizeof(underworld_melody) / sizeof(int); + for (int thisNote = 0; thisNote < size; 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/underworld_tempo[thisNote]; + + buzz(melodyPin, underworld_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: + buzz(melodyPin, 0,noteDuration); + + } + + }else{ + + Serial.println(" 'Mario Theme'"); + int size = sizeof(melody) / sizeof(int); + for (int thisNote = 0; thisNote < size; 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/tempo[thisNote]; + + buzz(melodyPin, 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: + buzz(melodyPin, 0,noteDuration); + + } + } +} + +void buzz(int targetPin, long frequency, long length) { + digitalWrite(13,HIGH); + long delayValue = 1000000/frequency/2; // calculate the delay value between transitions + //// 1 second's worth of microseconds, divided by the frequency, then split in half since + //// there are two phases to each cycle + long numCycles = frequency * length/ 1000; // calculate the number of cycles for proper timing + //// multiply frequency, which is really cycles per second, by the number of seconds to + //// get the total number of cycles to produce + for (long i=0; i < numCycles; i++){ // for the calculated length of time... + digitalWrite(targetPin,HIGH); // write the buzzer pin high to push out the diaphram + delayMicroseconds(delayValue); // wait for the calculated delay value + digitalWrite(targetPin,LOW); // write the buzzer pin low to pull back the diaphram + delayMicroseconds(delayValue); // wait again or the calculated delay value + } + digitalWrite(13,LOW); + +} diff --git a/piezo/piezo_4_mario_tune/pitches.h b/piezo/piezo_4_mario_tune/pitches.h new file mode 100644 index 0000000..55c7d54 --- /dev/null +++ b/piezo/piezo_4_mario_tune/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/piezo/piezo_mario_tune/piezo_mario_tune.ino b/piezo/piezo_mario_tune/piezo_mario_tune.ino deleted file mode 100644 index 12dc602..0000000 --- a/piezo/piezo_mario_tune/piezo_mario_tune.ino +++ /dev/null @@ -1,193 +0,0 @@ -/* - Arduino Mario Bros Tunes - With Piezo Buzzer and PWM - by: Dipto Pratyaksa - last updated: 31/3/13 -*/ -#include -//#include "/home/utente/sketchbook-andrea/piezo/piezo_mario_tune/pitches.h"; -#define melodyPin 3 -//Mario main theme melody -int melody[] = { - NOTE_E7, NOTE_E7, 0, NOTE_E7, - 0, NOTE_C7, NOTE_E7, 0, - NOTE_G7, 0, 0, 0, - NOTE_G6, 0, 0, 0, - - NOTE_C7, 0, 0, NOTE_G6, - 0, 0, NOTE_E6, 0, - 0, NOTE_A6, 0, NOTE_B6, - 0, NOTE_AS6, NOTE_A6, 0, - - NOTE_G6, NOTE_E7, NOTE_G7, - NOTE_A7, 0, NOTE_F7, NOTE_G7, - 0, NOTE_E7, 0,NOTE_C7, - NOTE_D7, NOTE_B6, 0, 0, - - NOTE_C7, 0, 0, NOTE_G6, - 0, 0, NOTE_E6, 0, - 0, NOTE_A6, 0, NOTE_B6, - 0, NOTE_AS6, NOTE_A6, 0, - - NOTE_G6, NOTE_E7, NOTE_G7, - NOTE_A7, 0, NOTE_F7, NOTE_G7, - 0, NOTE_E7, 0,NOTE_C7, - NOTE_D7, NOTE_B6, 0, 0 -}; -//Mario main them tempo -int tempo[] = { - 12, 12, 12, 12, - 12, 12, 12, 12, - 12, 12, 12, 12, - 12, 12, 12, 12, - - 12, 12, 12, 12, - 12, 12, 12, 12, - 12, 12, 12, 12, - 12, 12, 12, 12, - - 9, 9, 9, - 12, 12, 12, 12, - 12, 12, 12, 12, - 12, 12, 12, 12, - - 12, 12, 12, 12, - 12, 12, 12, 12, - 12, 12, 12, 12, - 12, 12, 12, 12, - - 9, 9, 9, - 12, 12, 12, 12, - 12, 12, 12, 12, - 12, 12, 12, 12, -}; - -// - -//Underworld melody -int underworld_melody[] = { - NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4, - NOTE_AS3, NOTE_AS4, 0, - 0, - NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4, - NOTE_AS3, NOTE_AS4, 0, - 0, - NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4, - NOTE_DS3, NOTE_DS4, 0, - 0, - NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4, - NOTE_DS3, NOTE_DS4, 0, - 0, NOTE_DS4, NOTE_CS4, NOTE_D4, - NOTE_CS4, NOTE_DS4, - NOTE_DS4, NOTE_GS3, - NOTE_G3, NOTE_CS4, - NOTE_C4, NOTE_FS4,NOTE_F4, NOTE_E3, NOTE_AS4, NOTE_A4, - NOTE_GS4, NOTE_DS4, NOTE_B3, - NOTE_AS3, NOTE_A3, NOTE_GS3, - 0, 0, 0 -}; -//Underwolrd tempo -int underworld_tempo[] = { - 12, 12, 12, 12, - 12, 12, 6, - 3, - 12, 12, 12, 12, - 12, 12, 6, - 3, - 12, 12, 12, 12, - 12, 12, 6, - 3, - 12, 12, 12, 12, - 12, 12, 6, - 6, 18, 18, 18, - 6, 6, - 6, 6, - 6, 6, - 18, 18, 18,18, 18, 18, - 10, 10, 10, - 10, 10, 10, - 3, 3, 3 -}; - -void setup(void) -{ - pinMode(3, OUTPUT);//buzzer - pinMode(13, OUTPUT);//led indicator when singing a note - -} -void loop() -{ -//sing the tunes - sing(1); - sing(1); - sing(2); -} -int song = 0; - -void sing(int s){ - // iterate over the notes of the melody: - song = s; - if(song==2){ - Serial.println(" 'Underworld Theme'"); - int size = sizeof(underworld_melody) / sizeof(int); - for (int thisNote = 0; thisNote < size; 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/underworld_tempo[thisNote]; - - buzz(melodyPin, underworld_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: - buzz(melodyPin, 0,noteDuration); - - } - - }else{ - - Serial.println(" 'Mario Theme'"); - int size = sizeof(melody) / sizeof(int); - for (int thisNote = 0; thisNote < size; 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/tempo[thisNote]; - - buzz(melodyPin, 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: - buzz(melodyPin, 0,noteDuration); - - } - } -} - -void buzz(int targetPin, long frequency, long length) { - digitalWrite(13,HIGH); - long delayValue = 1000000/frequency/2; // calculate the delay value between transitions - //// 1 second's worth of microseconds, divided by the frequency, then split in half since - //// there are two phases to each cycle - long numCycles = frequency * length/ 1000; // calculate the number of cycles for proper timing - //// multiply frequency, which is really cycles per second, by the number of seconds to - //// get the total number of cycles to produce - for (long i=0; i < numCycles; i++){ // for the calculated length of time... - digitalWrite(targetPin,HIGH); // write the buzzer pin high to push out the diaphram - delayMicroseconds(delayValue); // wait for the calculated delay value - digitalWrite(targetPin,LOW); // write the buzzer pin low to pull back the diaphram - delayMicroseconds(delayValue); // wait again or the calculated delay value - } - digitalWrite(13,LOW); - -} diff --git a/piezo/piezo_mario_tune/pitches.h b/piezo/piezo_mario_tune/pitches.h deleted file mode 100644 index 55c7d54..0000000 --- a/piezo/piezo_mario_tune/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 - -