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 19:48:11 2012 +0000
Revision:
2:8187d69071f8
Parent:
1:dd3faa2ab1dd
Child:
3:ade83210ecf6
Documentation update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tobyspark 2:8187d69071f8 1 // OLED display using SSD1305 driver
tobyspark 2:8187d69071f8 2 // Copyright *spark audio-visual 2012
tobyspark 2:8187d69071f8 3 //
tobyspark 2:8187d69071f8 4 // This library is free software; you can redistribute it and/or
tobyspark 2:8187d69071f8 5 // modify it under the terms of the GNU Lesser General Public
tobyspark 2:8187d69071f8 6 // License version 3 as published by the Free Software Foundation.
tobyspark 2:8187d69071f8 7
tobyspark 2:8187d69071f8 8 int w = 132;
tobyspark 2:8187d69071f8 9 int h = 64;
tobyspark 2:8187d69071f8 10 int scaleFactor = 5;
tobyspark 2:8187d69071f8 11
tobyspark 2:8187d69071f8 12 PImage imgPixel;
tobyspark 2:8187d69071f8 13 color white = color(255, 255, 255, 255);
tobyspark 2:8187d69071f8 14 color black = color(0, 0, 0, 255);
tobyspark 2:8187d69071f8 15
tobyspark 2:8187d69071f8 16 void setup()
tobyspark 2:8187d69071f8 17 {
tobyspark 2:8187d69071f8 18 imgPixel = loadImage("spk_dvimxr_font.png");
tobyspark 2:8187d69071f8 19 w = imgPixel.width;
tobyspark 2:8187d69071f8 20 h = imgPixel.height;
tobyspark 2:8187d69071f8 21
tobyspark 2:8187d69071f8 22 size(w*scaleFactor, h*scaleFactor);
tobyspark 2:8187d69071f8 23
tobyspark 2:8187d69071f8 24 noSmooth();
tobyspark 2:8187d69071f8 25 }
tobyspark 2:8187d69071f8 26
tobyspark 2:8187d69071f8 27 void draw()
tobyspark 2:8187d69071f8 28 {
tobyspark 2:8187d69071f8 29 background(0);
tobyspark 2:8187d69071f8 30 image(imgPixel, 0, 0, w*scaleFactor, h*scaleFactor);
tobyspark 2:8187d69071f8 31 }
tobyspark 2:8187d69071f8 32
tobyspark 2:8187d69071f8 33 void mouseDragged()
tobyspark 2:8187d69071f8 34 {
tobyspark 2:8187d69071f8 35 int x = mouseX/scaleFactor;
tobyspark 2:8187d69071f8 36 int y = mouseY/scaleFactor;
tobyspark 2:8187d69071f8 37
tobyspark 2:8187d69071f8 38 imgPixel.set(x, y, white);
tobyspark 2:8187d69071f8 39 }
tobyspark 2:8187d69071f8 40
tobyspark 2:8187d69071f8 41 void mousePressed()
tobyspark 2:8187d69071f8 42 {
tobyspark 2:8187d69071f8 43 int x = mouseX/scaleFactor;
tobyspark 2:8187d69071f8 44 int y = mouseY/scaleFactor;
tobyspark 2:8187d69071f8 45
tobyspark 2:8187d69071f8 46 if (imgPixel.get(x, y) == white)
tobyspark 2:8187d69071f8 47 {
tobyspark 2:8187d69071f8 48 imgPixel.set(x, y, black);
tobyspark 2:8187d69071f8 49 }
tobyspark 2:8187d69071f8 50 else
tobyspark 2:8187d69071f8 51 {
tobyspark 2:8187d69071f8 52 imgPixel.set(x, y, white);
tobyspark 2:8187d69071f8 53 }
tobyspark 2:8187d69071f8 54 }
tobyspark 2:8187d69071f8 55
tobyspark 2:8187d69071f8 56 void keyPressed()
tobyspark 2:8187d69071f8 57 {
tobyspark 2:8187d69071f8 58 int startID = 33;
tobyspark 2:8187d69071f8 59 int stopID = 126;
tobyspark 2:8187d69071f8 60
tobyspark 2:8187d69071f8 61 for (int charID = startID; charID <= stopID; charID++)
tobyspark 2:8187d69071f8 62 {
tobyspark 2:8187d69071f8 63 boolean blank = false;
tobyspark 2:8187d69071f8 64 String output = "";
tobyspark 2:8187d69071f8 65 int counter = 0;
tobyspark 2:8187d69071f8 66 while (blank == false)
tobyspark 2:8187d69071f8 67 {
tobyspark 2:8187d69071f8 68 int x = (charID-startID)*8 + counter;
tobyspark 2:8187d69071f8 69
tobyspark 2:8187d69071f8 70 byte theByte = 0;
tobyspark 2:8187d69071f8 71 for (int b = 0; b < 8; b++)
tobyspark 2:8187d69071f8 72 {
tobyspark 2:8187d69071f8 73 if (imgPixel.get(x, b) == white)
tobyspark 2:8187d69071f8 74 {
tobyspark 2:8187d69071f8 75 theByte += pow(2, b);
tobyspark 2:8187d69071f8 76 }
tobyspark 2:8187d69071f8 77 }
tobyspark 2:8187d69071f8 78
tobyspark 2:8187d69071f8 79 if (theByte > 0)
tobyspark 2:8187d69071f8 80 {
tobyspark 2:8187d69071f8 81 if (output.length() > 0) output = output + ", ";
tobyspark 2:8187d69071f8 82 output = output + "0x" + hex(theByte, 2);
tobyspark 2:8187d69071f8 83 }
tobyspark 2:8187d69071f8 84 else
tobyspark 2:8187d69071f8 85 {
tobyspark 2:8187d69071f8 86 blank = true;
tobyspark 2:8187d69071f8 87 println("const uint8_t char" + charID + "[] = {" + counter + ", " + output + "};");
tobyspark 2:8187d69071f8 88 }
tobyspark 2:8187d69071f8 89
tobyspark 2:8187d69071f8 90 counter++;
tobyspark 2:8187d69071f8 91 }
tobyspark 2:8187d69071f8 92 }
tobyspark 2:8187d69071f8 93 println();
tobyspark 2:8187d69071f8 94 println("const int characterBytesStartChar = " + startID + ";");
tobyspark 2:8187d69071f8 95 println("const int characterBytesEndChar = " + stopID + ";");
tobyspark 2:8187d69071f8 96 print("const uint8_t* characterBytes[] = {");
tobyspark 2:8187d69071f8 97 for (int charID = startID; charID <= stopID; charID++)
tobyspark 2:8187d69071f8 98 {
tobyspark 2:8187d69071f8 99 print("char" + charID + ", ");
tobyspark 2:8187d69071f8 100 }
tobyspark 2:8187d69071f8 101 println("};");
tobyspark 2:8187d69071f8 102 }