Paso 4: código
Si usted abre su Arduino en su ordenador y comience un nuevo archivo y copia pega el código debajo de:
#include "pitches.h"
const int buttonPin = 2; bool volátiles aan = false;
const int aantalNoten = 8;
melodía de int [] = {NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4};
int noteDurations [] = {4, 8, 8, 4, 4, 4, 4, 4};
void setup() {pinMode(buttonPin, INPUT); attachInterrupt(digitalPinToInterrupt(buttonPin), playpause, levantamiento);}
void loop() {si (aan == true) {para (int thisNote = 0; thisNote < aantalNoten; thisNote ++) {}
int noteDuration = 1000 / noteDurations [thisNote]; tono (8, melodía [thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30; Delay(pauseBetweenNotes); noTone(8);
Si (aan == false) break; } } }
void playpause() {delay(15); si (digitalRead(buttonPin) == HIGH) {aan =! aan;}}