#include MKRIoTCarrier carrier; #define MAX_INT 4 // (så kan den bruges som pi) #define SIZE 120 #include "pitches.h" #include "image.c" void setup() { Serial.begin(9600); carrier.begin(); int red_sun_in_the_sky[] = { NOTE_D6, NOTE_D6, NOTE_D6, NOTE_D6, NOTE_D6, NOTE_F6, NOTE_D6, NOTE_AS5, NOTE_G5, NOTE_F5, NOTE_G5, NOTE_D6, NOTE_AS5, NOTE_D6, NOTE_AS5, NOTE_G5, NOTE_G5, NOTE_F5, NOTE_G5, NOTE_AS5, NOTE_D6, NOTE_AS5, NOTE_G5, NOTE_F5, NOTE_G5, NOTE_AS5, NOTE_D5, NOTE_F5, NOTE_G5, NOTE_AS5, NOTE_G5, NOTE_AS5, NOTE_G5, NOTE_AS5, NOTE_G5, NOTE_AS5, NOTE_F6, NOTE_D6, NOTE_D6, 0, NOTE_AS5, NOTE_G5, NOTE_AS5, NOTE_D6, NOTE_D6, NOTE_F6, NOTE_D6, NOTE_AS5, NOTE_G5, NOTE_G5, 0 }; int bpm = 139; int noteDurations[] = { 3, 1, 2, 2, 2, 2, 2, 2, 3, 1, 2, 2, 2, 2, 2, 2, 2, 1, 3, 2, 2, 4, 4, 2.5, 4, 2.5, 4, 2.5, 4,4,4,4, 2,2,2,2,2,2,4, 2,4,2,2,4,2, 4,4,2,2,4 }; for (int note_idx = 0; note_idx < sizeof(noteDurations) / sizeof(int); note_idx++) { // 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 = noteDurations[note_idx]/(139*8.0)*60*1000; Serial.println(noteDuration); carrier.Buzzer.sound(red_sun_in_the_sky[note_idx]); // to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: delay(noteDuration); carrier.Buzzer.noSound(); delay(noteDuration); } } void loop() { for (int x = 0; x < SIZE; x++) { for (int y = 0; y < SIZE; y++) { int idx = y * SIZE + x; unsigned short color = gimp_image[idx]; carrier.display.fillRect(x * 2, y * 2, 2, 2, color); } } delay(2500); }