Skip to content

Commit

Permalink
Make more interesting use of the palette mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jepler committed Feb 27, 2025
1 parent 9c70f0d commit ee8007f
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions examples/01palettetest/01palettetest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ DVHSTX8 display(DVHSTX_PINOUT_DEFAULT, DVHSTX_RESOLUTION_640x360);
// The order is: {CKP, D0P, D1P, D2P} DVHSTX8 display({12, 14, 16, 18},
// DVHSTX_RESOLUTION_640x360);

struct moving_point {
int x, y, dx, dy;
void step() {
x += dx;
if (x < 0) { x = 0; dx = random(3) + 1; }
if (x >= display.width()) { x = display.width() - 1; dx = -random(3) - 1; }

y += dy;
if (y < 0) { y = 0; dy = random(3) + 1; }
if (y >= display.height()) { y = display.height() - 1; dy = -random(3) - 1; }
}
};

moving_point p1, p2;

int random_with_sign(int n) {
return random(2) ? random(n-1)+1 : -random(n-1)-1;
}

void setup() {
Serial.begin(115200);
// while(!Serial);
Expand All @@ -19,12 +38,20 @@ void setup() {
digitalWrite(LED_BUILTIN, (millis() / 500) & 1);
}
Serial.println("display initialized");
p1 = moving_point{random(display.width()), random(display.height()), random_with_sign(3), random_with_sign(3)};
p2 = moving_point{random(display.width()), random(display.height()), random_with_sign(3), random_with_sign(3)};
}

void loop() {
// Draw random lines
display.drawLine(random(display.width()), random(display.height()),
random(display.width()), random(display.height()),
random(65536));
sleep_ms(1);
static int j;
display.drawLine(p1.x, p1.y, p2.x, p2.y, 1 + (j + 254) % 255);
Serial.printf("%d %d %d %d\r\n", p1.x, p1.y, p1.dx, p1.dy);
p1.step();
p2.step();

for(int i=1; i<256; i++) {
display.setColor(i, ((i + j) % 255) * 0x010101);
}
j += 1;
delay(3);
}

0 comments on commit ee8007f

Please sign in to comment.