85 lines
2.4 KiB
C++
85 lines
2.4 KiB
C++
#include <Arduino_MKRIoTCarrier.h>
|
|
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();
|
|
carrier.display.fillScreen(ST77XX_BLACK); // Start med en ren skærm
|
|
Serial.println("start");
|
|
|
|
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);
|
|
// stop the tone playing:
|
|
carrier.Buzzer.noSound();
|
|
delay(noteDuration);
|
|
}
|
|
}
|
|
|
|
inline int color_u8_to_u6(int v) {
|
|
const double conversion_ratio = 63.0 / 255.0;
|
|
return (int)(v * conversion_ratio);
|
|
}
|
|
|
|
inline int color_u8_to_u5(int v) {
|
|
const double conversion_ratio = 31.0 / 255.0;
|
|
return (int)(v * conversion_ratio);
|
|
}
|
|
|
|
void loop() {
|
|
Serial.println(":3");
|
|
for (int x = 0; x < SIZE; x++) {
|
|
for (int y = 0; y < SIZE; y++) {
|
|
int idx = 3 * (y * SIZE + x);
|
|
// for some reason
|
|
// red = 5 bytes
|
|
// green = 6 bytes
|
|
// blue = 5 bytes
|
|
int r = (int)gimp_image[idx] & 0xFF;
|
|
int g = (int)gimp_image[idx + 1] & 0xFF;
|
|
int b = (int)gimp_image[idx + 2] & 0xFF;
|
|
int color = (color_u8_to_u5(r) << 11) | (color_u8_to_u6(g) << 5) | color_u8_to_u5(b);
|
|
carrier.display.fillRect(x * 2, y * 2, 2, 2, color);
|
|
}
|
|
}
|
|
delay(2500); // Vent lidt før næste måling
|
|
}
|