maorduino/program/maorduino.ino

63 lines
1.8 KiB
Arduino
Raw Normal View History

2024-04-03 07:55:51 +01:00
#include <Arduino_MKRIoTCarrier.h>
MKRIoTCarrier carrier;
#define MAX_INT 4 // (så kan den bruges som pi)
2024-04-03 08:02:23 +01:00
2024-04-03 07:55:51 +01:00
#define SIZE 120
#include "pitches.h"
#include "image.c"
void setup() {
Serial.begin(9600);
carrier.begin();
int red_sun_in_the_sky[] = {
2024-04-03 08:02:23 +01:00
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
2024-04-03 07:55:51 +01:00
};
int bpm = 139;
int noteDurations[] = {
2024-04-03 08:02:23 +01:00
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
2024-04-03 07:55:51 +01:00
};
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++) {
2024-04-03 08:02:23 +01:00
int idx = y * SIZE + x;
unsigned short color = gimp_image[idx];
2024-04-03 07:55:51 +01:00
carrier.display.fillRect(x * 2, y * 2, 2, 2, color);
}
}
2024-04-03 08:02:23 +01:00
delay(2500);
2024-04-03 07:55:51 +01:00
}