Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pitches.h"
- byte a = 0;
- byte a1 = 0;
- int noteDuration;
- // notes in the melody:
- int melody[] = {
- NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3
- };
- int melody1[] = {
- NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5
- };
- int noteDurations[] = {
- 4, 8, 8, 4
- };
- int noteDurations1[] = {
- 4, 1, 1, 4
- };
- unsigned long previousMillis = 0;
- unsigned long pauseBetweenNotes;
- int thisNote = 10;
- void setup() {
- Serial.begin(9600);
- }
- void loop() {
- if (Serial.available() > 0) {
- char state = Serial.read();
- if (state == '+' ) {
- Serial.print("+ ");
- a = 2;
- }
- if (state == '-' ) {
- Serial.print("- ");
- a = 1;
- }
- }
- unsigned long currentMillis = millis();
- if (a != 0 && a != a1) {
- thisNote = 0;
- Serial.println(" cambio ");
- }
- a1 = a;
- if (thisNote < 4 && currentMillis - previousMillis >= pauseBetweenNotes) {
- Serial.println(" Note ");
- previousMillis = currentMillis;
- if (a == 1) {
- noteDuration = 1000 / noteDurations[thisNote];
- tone(8, melody1[thisNote], noteDuration);
- }
- if (a == 2) {
- noteDuration = 1000 / noteDurations1[thisNote];
- tone(8, melody[thisNote], noteDuration);
- }
- pauseBetweenNotes = noteDuration * 1.30;
- thisNote++;
- }
- if (thisNote >= 4 ) {
- a = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement