Paso 8: programación
Programar el tema de dinastía de pato que tenía que ver música coro piano en línea para obtener exactamente las notas. Desde allí había tomar esas notas y traducirlas en código lo hice en Arduino.cc/ed/tutorial/tone. Entonces tuve que escribir la nota duración (rapidez cada nota era para reproducirse).
Aquí está todo mi código escrito:
int whiteLeds = 10;
int rojo = 9;
greenLed int = 5;
blueLed int = 6;
int zipperswitch = A5;
int zipperswitch2 = A3;
int zipperswitch3 = A4;
int speakerPin = A2;
int r;
int g;
int b;
int fadeSpeed = 1;
#include "pitches.h"
Notas de la melodía:
melodía de int [] = {}
NOTE_DS4, NOTE_DS4, 0, NOTE_DS4, NOTE_DS4, 0, NOTE_DS4, NOTE_DS4, NOTE_DS4, NOTE_C4, NOTE_DS4,
NOTE_F4, NOTE_FS4, NOTE_FS4, NOTE_FS4, 0, NOTE_B4, NOTE_B4, NOTE_B4, NOTE_B4, NOTE_B4, NOTE_B4,
NOTE_B4, NOTE_B4, NOTE_G3, NOTE_C4, 0, NOTE_C4, NOTE_FS4, NOTE_G4, NOTE_G4, NOTE_DS4, NOTE_C4, NOTE_C4,
NOTE_G3, NOTE_AS3, NOTE_C4, NOTE_C4, 0,
};
int noteDurations [] = {}
4, 4, 2, 4, 4, 2, 8, 2.7, 8, 8, 8, 8, 4, 4, 8, 8,
8, 4, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 8, 8, 4, 8, 8, 8, 8, 4, 4, 2, 1};
para ir más rápido o más lento
void setup() {}
pinMode (whiteLeds, salida);
pinMode (rojo, salida);
pinMode (greenLed, salida);
pinMode (blueLed, salida);
pinMode (speakerPin, salida);
pinMode (zipperswitch, INPUT_PULLUP);
pinMode (zipperswitch2, INPUT_PULLUP);
pinMode (zipperswitch3, INPUT_PULLUP);
}
void loop() {}
if((digitalRead(zipperswitch) == 0)) {}
colorFade();
rLEDFade();
gLEDFade();
bLEDFade();
} else {}
digitalWrite (rojo, 1);
digitalWrite (greenLed, 1);
digitalWrite (blueLed, 1);
}
if((digitalRead(zipperswitch2) == 0)) {}
DuckDynasty ();
} else {}
digitalWrite (speakerPin, bajo);
}
if((digitalRead(zipperswitch3) == 0)) {}
digitalWrite (whiteLeds, HIGH);
Delay(500);
digitalWrite (whiteLeds, bajo);
Delay(500);
} else {}
digitalWrite (whiteLeds, bajo);
}
Color void)
{
digitalWrite (rojo, baja);
digitalWrite (blueLed, HIGH);
digitalWrite (greenLed, HIGH);
Delay(500);
digitalWrite (rojo, alto);
digitalWrite (blueLed, HIGH);
digitalWrite (greenLed, LOW);
Delay(500);
digitalWrite (rojo, alto);
digitalWrite (blueLed, LOW);
digitalWrite (greenLed, HIGH);
Delay(500);
digitalWrite (rojo, alto);
digitalWrite (blueLed, HIGH);
digitalWrite (greenLed, HIGH);
Delay(1000);
}
void analogColor)
{
analogWrite (rojo, 0);
analogWrite (blueLed, 255); rojo
analogWrite (greenLed, 255);
Delay(1000);
analogWrite (rojo, 255);
analogWrite (blueLed, 255); verde
analogWrite (greenLed, 0);
Delay(1000);
analogWrite (rojo, 255);
analogWrite (blueLed, 0); azul
analogWrite (greenLed, 255);
Delay(1000);
analogWrite (rojo, 0);
analogWrite (blueLed, 0); púrpura
analogWrite (greenLed, 255);
Delay(1000);
analogWrite (rojo, 0);
analogWrite (blueLed, 255); naranja
analogWrite (greenLed, 0);
Delay(1000);
analogWrite (rojo, 255);
analogWrite (blueLed, 0); Teal
analogWrite (greenLed, 0);
Delay(1000);
analogWrite (rojo, 255);
analogWrite (blueLed, 255); de
analogWrite (greenLed, 255);
Delay(1000);
}
void rLEDFade()
{
analogWrite (blueLed, 255);
analogWrite (greenLed, 255);
analogWrite (rojo, 255);
para (r = 255; r > 0; i--) {}
analogWrite (rojo, r);
Delay(fadeSpeed);
}
para (i = 0; i < 256; i ++) {}
analogWrite (rojo, r);
Delay(fadeSpeed);
}
}
void gLEDFade()
{
analogWrite (blueLed, 255);
analogWrite (greenLed, 255);
analogWrite(redLed,255);
para (g = 255, g > 0; g--) {}
analogWrite (greenLed, g);
Delay(fadeSpeed);
}
para (g = 0 g < 256; g ++) {}
analogWrite (greenLed, g);
Delay(fadeSpeed);
}
}
void bLEDFade()
{
analogWrite (blueLed, 255);
analogWrite (greenLed, 255);
analogWrite(redLed,255);
para (b = 255, b > 0; b--) {}
analogWrite (blueLed, b);
Delay(fadeSpeed);
}
para (b = 0; b < 256; b ++) {}
analogWrite (blueLed, b);
Delay(fadeSpeed);
}
}
void colorFade)
{
analogWrite (blueLed, 0);
para (r = 255; r > 0; i--) {}
analogWrite (rojo, r);
Delay(fadeSpeed);
}
para (b = 0; b < 256; b ++) {}
analogWrite (blueLed, b);
Delay(fadeSpeed);
}
para (g = 255, g > 0; g--) {}
analogWrite (greenLed, g);
Delay(fadeSpeed);
}
para (i = 0; i < 256; i ++) {}
analogWrite (rojo, r);
Delay(fadeSpeed);
}
para (b = 255, b > 0; b--) {}
analogWrite (blueLed, b);
Delay(fadeSpeed);
}
para (g = 0 g < 256; g ++) {}
analogWrite (greenLed, g);
Delay(fadeSpeed);
}
analogWrite (blueLed, 255);
Delay(500);
}
void () DuckDynasty
{
para (int thisNote = 0; thisNote < 40; thisNote ++) {}
int noteDuration = 1500/noteDurations [thisNote];
tono (speakerPin, melody[thisNote],noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
Delay(pauseBetweenNotes);
noTone(speakerPin);
}
}