Skip to content

Commit e092a3d

Browse files
Merge pull request #123 from stefanhaustein/master
Add a demo for the Waveshare 12890 128x64 oled hat
2 parents e90b6fd + b19bc3f commit e092a3d

5 files changed

Lines changed: 39 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ The following table the currently supported devices within this project:
5656
| A/D | SPI | (1)(3) | [MCP3008 A/D 10bit converter](src/main/java/com/pi4j/devices/mcp3008/README.md)
5757
| A/D | I2C | (1) | [MCP4725 12 bit DAC](src/main/java/com/pi4j/devices/mcp4725/README.md)
5858
| HAT | | | [Raspberry SenseHat](src/main/java/com/pi4j/examples/hat/raspberry/sensehat/)
59+
| HAT | | | [Waveshare 13890 Mini OLED Display Hat](src/main/java/com/pi4j/examples/hat/waveshare/waveshare13890/)
5960
| HAT | | | [Waveshare 13891 Mini Display Hat](src/main/java/com/pi4j/examples/hat/waveshare/waveshare13891/)
6061
| HAT | | | [Waveshare 14972 Mini Display Hat](src/main/java/com/pi4j/examples/hat/waveshare/waveshare14972/)
6162
| HAT | | | [Waveshare GamePi13 Hat](src/main/java/com/pi4j/examples/hat/waveshare/gamepi13/)

src/main/java/com/pi4j/examples/games/bricks/Bricks.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ private void actionKey(boolean on) {
7878
}
7979

8080
private void initializeBricks() {
81-
display.fillRect(0, 0, display.getWidth(), display.getHeight(), 0);
81+
display.fillRect(0, 0, display.getWidth(), display.getHeight(), 0xffffffff);
82+
display.fillRect(x0, y0, scale * FIELD_SIZE, scale * FIELD_SIZE, 0xff000000);
8283
for (int i = 0; i < 4; i++) {
8384
for (int j = 0; j < 3; j++) {
8485
setBrick(i, j, true);
@@ -203,6 +204,6 @@ private void setBrick(int x, int y, boolean alive) {
203204
y0 + 8 * (y + 1) * scale + 1,
204205
14 * scale,
205206
6 * scale,
206-
alive ? (y == 0 ? 0xff0000 : y == 1 ? 0xff00 : 0xff) : 0);
207+
alive ? (y == 0 ? 0xffff8888 : y == 1 ? 0xffff8888 : 0xff88ff88) : 0);
207208
}
208209
}

src/main/java/com/pi4j/examples/games/snake/Snake.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ private void addSegment(int x, int y) {
7979

8080
private void initialize() {
8181
arena = new Entity[AREA_SIZE][AREA_SIZE];
82-
display.fillRect(0, 0, display.getWidth(), display.getHeight(), 0);
82+
display.fillRect(0, 0, display.getWidth(), display.getHeight(), 0xffffffff);
83+
display.fillRect(x0, y0, scale * AREA_SIZE, scale * AREA_SIZE, 0xff000000);
8384
body.clear();
8485
length = 1;
8586

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.pi4j.examples.hat.waveshare.waveshare13890;
2+
3+
import com.pi4j.Pi4J;
4+
import com.pi4j.context.Context;
5+
import com.pi4j.drivers.hat.waveshare.Waveshare13890;
6+
import com.pi4j.examples.hat.DisplayHatDemo;
7+
8+
/**
9+
* A simple demo running a "Snake" game. Exit by holding the center button for one second.
10+
*/
11+
public class Demo {
12+
13+
static void main(String[] args) {
14+
Context pi4j = Pi4J.newAutoContext();
15+
Waveshare13890 hat = new Waveshare13890(pi4j);
16+
17+
new DisplayHatDemo(
18+
hat.getDisplay(),
19+
null,
20+
hat.getController(),
21+
null,
22+
null,
23+
null).run();
24+
25+
hat.getDisplay().close();
26+
hat.getController().close();
27+
pi4j.shutdown();
28+
}
29+
30+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Waveshare 13890 Display Hat Demo
2+
3+
A small demo allowing the user to play two mini games.

0 commit comments

Comments
 (0)