SPKDisplay - A mbed display class and processing imaging tools for 128x64 OLEDs using the SSD1305 driver, connected via SPI.

Dependents:   SPK-DVIMXR SPK-DMXer

Committer:
tobyspark
Date:
Sun Apr 15 16:51:01 2012 +0000
Revision:
0:76bb084fa033
Child:
1:dd3faa2ab1dd
Initial commit after internal dev as part of SPK-DVIMXR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tobyspark 0:76bb084fa033 1 int w = 132;
tobyspark 0:76bb084fa033 2 int h = 64;
tobyspark 0:76bb084fa033 3 int scaleFactor = 10;
tobyspark 0:76bb084fa033 4
tobyspark 0:76bb084fa033 5 PImage imgPixel;
tobyspark 0:76bb084fa033 6 color white = color(255, 255, 255, 255);
tobyspark 0:76bb084fa033 7 color black = color(0, 0, 0, 255);
tobyspark 0:76bb084fa033 8
tobyspark 0:76bb084fa033 9 void setup()
tobyspark 0:76bb084fa033 10 {
tobyspark 0:76bb084fa033 11 size(w*scaleFactor, h*scaleFactor);
tobyspark 0:76bb084fa033 12 imgPixel = loadImage("spk_dvimxr_screen.png");
tobyspark 0:76bb084fa033 13
tobyspark 0:76bb084fa033 14 noSmooth();
tobyspark 0:76bb084fa033 15 }
tobyspark 0:76bb084fa033 16
tobyspark 0:76bb084fa033 17 void draw()
tobyspark 0:76bb084fa033 18 {
tobyspark 0:76bb084fa033 19 background(0);
tobyspark 0:76bb084fa033 20 image(imgPixel, 0, 0, w*scaleFactor, h*scaleFactor);
tobyspark 0:76bb084fa033 21 }
tobyspark 0:76bb084fa033 22
tobyspark 0:76bb084fa033 23 void mouseDragged()
tobyspark 0:76bb084fa033 24 {
tobyspark 0:76bb084fa033 25 int x = mouseX/scaleFactor;
tobyspark 0:76bb084fa033 26 int y = mouseY/scaleFactor;
tobyspark 0:76bb084fa033 27
tobyspark 0:76bb084fa033 28 imgPixel.set(x, y, white);
tobyspark 0:76bb084fa033 29 }
tobyspark 0:76bb084fa033 30
tobyspark 0:76bb084fa033 31 void mousePressed()
tobyspark 0:76bb084fa033 32 {
tobyspark 0:76bb084fa033 33 int x = mouseX/scaleFactor;
tobyspark 0:76bb084fa033 34 int y = mouseY/scaleFactor;
tobyspark 0:76bb084fa033 35
tobyspark 0:76bb084fa033 36 if (imgPixel.get(x, y) == white)
tobyspark 0:76bb084fa033 37 {
tobyspark 0:76bb084fa033 38 imgPixel.set(x, y, black);
tobyspark 0:76bb084fa033 39 }
tobyspark 0:76bb084fa033 40 else
tobyspark 0:76bb084fa033 41 {
tobyspark 0:76bb084fa033 42 imgPixel.set(x, y, white);
tobyspark 0:76bb084fa033 43 }
tobyspark 0:76bb084fa033 44 }
tobyspark 0:76bb084fa033 45
tobyspark 0:76bb084fa033 46 void keyPressed()
tobyspark 0:76bb084fa033 47 {
tobyspark 0:76bb084fa033 48 println("{");
tobyspark 0:76bb084fa033 49 for (int page = 0; page < 8; page++)
tobyspark 0:76bb084fa033 50 {
tobyspark 0:76bb084fa033 51 for (int i = 0; i < w; i++)
tobyspark 0:76bb084fa033 52 {
tobyspark 0:76bb084fa033 53 byte theByte = 0;
tobyspark 0:76bb084fa033 54 for (int j = 0; j < 8; j++)
tobyspark 0:76bb084fa033 55 {
tobyspark 0:76bb084fa033 56 if (imgPixel.get(i, (page*8)+j) == white)
tobyspark 0:76bb084fa033 57 {
tobyspark 0:76bb084fa033 58 theByte += pow(2, j);
tobyspark 0:76bb084fa033 59 }
tobyspark 0:76bb084fa033 60 }
tobyspark 0:76bb084fa033 61 print("0x" + hex(theByte, 2));
tobyspark 0:76bb084fa033 62 print(", ");
tobyspark 0:76bb084fa033 63 }
tobyspark 0:76bb084fa033 64 println();
tobyspark 0:76bb084fa033 65 }
tobyspark 0:76bb084fa033 66 println("}");
tobyspark 0:76bb084fa033 67 }