convert to new image format

This commit is contained in:
Theis Pieter Hollebeek 2024-04-03 09:02:23 +02:00
parent c1ed7b057a
commit 0e60faa538
2 changed files with 21 additions and 1720 deletions

File diff suppressed because one or more lines are too long

View File

@ -2,6 +2,7 @@
MKRIoTCarrier carrier; MKRIoTCarrier carrier;
#define MAX_INT 4 // (så kan den bruges som pi) #define MAX_INT 4 // (så kan den bruges som pi)
#define SIZE 120 #define SIZE 120
#include "pitches.h" #include "pitches.h"
#include "image.c" #include "image.c"
@ -9,10 +10,7 @@ MKRIoTCarrier carrier;
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
carrier.begin(); carrier.begin();
carrier.display.fillScreen(ST77XX_BLACK); // Start med en ren skærm
Serial.println("start");
int red_sun_in_the_sky[] = { int red_sun_in_the_sky[] = {
NOTE_D6, NOTE_D6, NOTE_D6, NOTE_D6, NOTE_D6, NOTE_F6, NOTE_D6, NOTE_AS5, NOTE_D6, NOTE_D6, NOTE_D6, NOTE_D6, NOTE_D6, NOTE_F6, NOTE_D6, NOTE_AS5,
@ -20,9 +18,9 @@ void setup() {
NOTE_F5, NOTE_G5, NOTE_AS5, NOTE_D6, NOTE_AS5, 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_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_G5,
NOTE_AS5, NOTE_G5, NOTE_AS5, NOTE_F6, NOTE_D6, NOTE_D6, 0, 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_AS5, NOTE_G5, NOTE_AS5, NOTE_D6, NOTE_D6, NOTE_F6,
NOTE_D6, NOTE_AS5, NOTE_G5, NOTE_G5, 0 NOTE_D6, NOTE_AS5, NOTE_G5, NOTE_G5, 0
}; };
int bpm = 139; int bpm = 139;
@ -32,10 +30,9 @@ NOTE_D6, NOTE_AS5, NOTE_G5, NOTE_G5, 0
1, 3, 2, 2, 4, 4, 1, 3, 2, 2, 4, 4,
2.5, 4, 2.5, 4, 2.5, 2.5, 4, 2.5, 4, 2.5,
4,4,4,4, 4,4,4,4,
2,2,2,2,2,2,4, 2,2,2,2,2,2,4,
2,4,2,2,4,2, 2,4,2,2,4,2,
4,4,2,2,4 4,4,2,2,4
}; };
for (int note_idx = 0; note_idx < sizeof(noteDurations) / sizeof(int); note_idx++) { for (int note_idx = 0; note_idx < sizeof(noteDurations) / sizeof(int); note_idx++) {
@ -48,37 +45,18 @@ NOTE_D6, NOTE_AS5, NOTE_G5, NOTE_G5, 0
// to distinguish the notes, set a minimum time between them. // to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well: // the note's duration + 30% seems to work well:
delay(noteDuration); delay(noteDuration);
// stop the tone playing:
carrier.Buzzer.noSound(); carrier.Buzzer.noSound();
delay(noteDuration); 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() { void loop() {
Serial.println(":3");
for (int x = 0; x < SIZE; x++) { for (int x = 0; x < SIZE; x++) {
for (int y = 0; y < SIZE; y++) { for (int y = 0; y < SIZE; y++) {
int idx = 3 * (y * SIZE + x); int idx = y * SIZE + x;
// for some reason unsigned short color = gimp_image[idx];
// 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); carrier.display.fillRect(x * 2, y * 2, 2, 2, color);
} }
} }
delay(2500); // Vent lidt før næste måling delay(2500);
} }