SPKDisplay - A mbed display class and processing imaging tools for 128x64 OLEDs using the SSD1305 driver, connected via SPI.
Dependents: SPK-DVIMXR SPK-DMXer
spk_oled_fontByteMaker--processing.h@3:ade83210ecf6, 2012-08-02 (annotated)
- Committer:
- tobyspark
- Date:
- Thu Aug 02 13:26:18 2012 +0000
- Revision:
- 3:ade83210ecf6
- Parent:
- 2:8187d69071f8
- Child:
- 5:0d518115e76c
MIT License as per MBED guideline
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tobyspark | 2:8187d69071f8 | 1 | // OLED display using SSD1305 driver |
tobyspark | 3:ade83210ecf6 | 2 | // A library by *spark audio-visual |
tobyspark | 3:ade83210ecf6 | 3 | |
tobyspark | 3:ade83210ecf6 | 4 | /* Copyright (c) 2011 Toby Harris, MIT License |
tobyspark | 3:ade83210ecf6 | 5 | * |
tobyspark | 3:ade83210ecf6 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
tobyspark | 3:ade83210ecf6 | 7 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
tobyspark | 3:ade83210ecf6 | 8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
tobyspark | 3:ade83210ecf6 | 9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
tobyspark | 3:ade83210ecf6 | 10 | * furnished to do so, subject to the following conditions: |
tobyspark | 3:ade83210ecf6 | 11 | * |
tobyspark | 3:ade83210ecf6 | 12 | * The above copyright notice and this permission notice shall be included in all copies or |
tobyspark | 3:ade83210ecf6 | 13 | * substantial portions of the Software. |
tobyspark | 3:ade83210ecf6 | 14 | * |
tobyspark | 3:ade83210ecf6 | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
tobyspark | 3:ade83210ecf6 | 16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
tobyspark | 3:ade83210ecf6 | 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
tobyspark | 3:ade83210ecf6 | 18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
tobyspark | 3:ade83210ecf6 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
tobyspark | 3:ade83210ecf6 | 20 | */ |
tobyspark | 2:8187d69071f8 | 21 | |
tobyspark | 2:8187d69071f8 | 22 | int w = 132; |
tobyspark | 2:8187d69071f8 | 23 | int h = 64; |
tobyspark | 2:8187d69071f8 | 24 | int scaleFactor = 5; |
tobyspark | 2:8187d69071f8 | 25 | |
tobyspark | 2:8187d69071f8 | 26 | PImage imgPixel; |
tobyspark | 2:8187d69071f8 | 27 | color white = color(255, 255, 255, 255); |
tobyspark | 2:8187d69071f8 | 28 | color black = color(0, 0, 0, 255); |
tobyspark | 2:8187d69071f8 | 29 | |
tobyspark | 2:8187d69071f8 | 30 | void setup() |
tobyspark | 2:8187d69071f8 | 31 | { |
tobyspark | 2:8187d69071f8 | 32 | imgPixel = loadImage("spk_dvimxr_font.png"); |
tobyspark | 2:8187d69071f8 | 33 | w = imgPixel.width; |
tobyspark | 2:8187d69071f8 | 34 | h = imgPixel.height; |
tobyspark | 2:8187d69071f8 | 35 | |
tobyspark | 2:8187d69071f8 | 36 | size(w*scaleFactor, h*scaleFactor); |
tobyspark | 2:8187d69071f8 | 37 | |
tobyspark | 2:8187d69071f8 | 38 | noSmooth(); |
tobyspark | 2:8187d69071f8 | 39 | } |
tobyspark | 2:8187d69071f8 | 40 | |
tobyspark | 2:8187d69071f8 | 41 | void draw() |
tobyspark | 2:8187d69071f8 | 42 | { |
tobyspark | 2:8187d69071f8 | 43 | background(0); |
tobyspark | 2:8187d69071f8 | 44 | image(imgPixel, 0, 0, w*scaleFactor, h*scaleFactor); |
tobyspark | 2:8187d69071f8 | 45 | } |
tobyspark | 2:8187d69071f8 | 46 | |
tobyspark | 2:8187d69071f8 | 47 | void mouseDragged() |
tobyspark | 2:8187d69071f8 | 48 | { |
tobyspark | 2:8187d69071f8 | 49 | int x = mouseX/scaleFactor; |
tobyspark | 2:8187d69071f8 | 50 | int y = mouseY/scaleFactor; |
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 | void mousePressed() |
tobyspark | 2:8187d69071f8 | 56 | { |
tobyspark | 2:8187d69071f8 | 57 | int x = mouseX/scaleFactor; |
tobyspark | 2:8187d69071f8 | 58 | int y = mouseY/scaleFactor; |
tobyspark | 2:8187d69071f8 | 59 | |
tobyspark | 2:8187d69071f8 | 60 | if (imgPixel.get(x, y) == white) |
tobyspark | 2:8187d69071f8 | 61 | { |
tobyspark | 2:8187d69071f8 | 62 | imgPixel.set(x, y, black); |
tobyspark | 2:8187d69071f8 | 63 | } |
tobyspark | 2:8187d69071f8 | 64 | else |
tobyspark | 2:8187d69071f8 | 65 | { |
tobyspark | 2:8187d69071f8 | 66 | imgPixel.set(x, y, white); |
tobyspark | 2:8187d69071f8 | 67 | } |
tobyspark | 2:8187d69071f8 | 68 | } |
tobyspark | 2:8187d69071f8 | 69 | |
tobyspark | 2:8187d69071f8 | 70 | void keyPressed() |
tobyspark | 2:8187d69071f8 | 71 | { |
tobyspark | 2:8187d69071f8 | 72 | int startID = 33; |
tobyspark | 2:8187d69071f8 | 73 | int stopID = 126; |
tobyspark | 2:8187d69071f8 | 74 | |
tobyspark | 2:8187d69071f8 | 75 | for (int charID = startID; charID <= stopID; charID++) |
tobyspark | 2:8187d69071f8 | 76 | { |
tobyspark | 2:8187d69071f8 | 77 | boolean blank = false; |
tobyspark | 2:8187d69071f8 | 78 | String output = ""; |
tobyspark | 2:8187d69071f8 | 79 | int counter = 0; |
tobyspark | 2:8187d69071f8 | 80 | while (blank == false) |
tobyspark | 2:8187d69071f8 | 81 | { |
tobyspark | 2:8187d69071f8 | 82 | int x = (charID-startID)*8 + counter; |
tobyspark | 2:8187d69071f8 | 83 | |
tobyspark | 2:8187d69071f8 | 84 | byte theByte = 0; |
tobyspark | 2:8187d69071f8 | 85 | for (int b = 0; b < 8; b++) |
tobyspark | 2:8187d69071f8 | 86 | { |
tobyspark | 2:8187d69071f8 | 87 | if (imgPixel.get(x, b) == white) |
tobyspark | 2:8187d69071f8 | 88 | { |
tobyspark | 2:8187d69071f8 | 89 | theByte += pow(2, b); |
tobyspark | 2:8187d69071f8 | 90 | } |
tobyspark | 2:8187d69071f8 | 91 | } |
tobyspark | 2:8187d69071f8 | 92 | |
tobyspark | 2:8187d69071f8 | 93 | if (theByte > 0) |
tobyspark | 2:8187d69071f8 | 94 | { |
tobyspark | 2:8187d69071f8 | 95 | if (output.length() > 0) output = output + ", "; |
tobyspark | 2:8187d69071f8 | 96 | output = output + "0x" + hex(theByte, 2); |
tobyspark | 2:8187d69071f8 | 97 | } |
tobyspark | 2:8187d69071f8 | 98 | else |
tobyspark | 2:8187d69071f8 | 99 | { |
tobyspark | 2:8187d69071f8 | 100 | blank = true; |
tobyspark | 2:8187d69071f8 | 101 | println("const uint8_t char" + charID + "[] = {" + counter + ", " + output + "};"); |
tobyspark | 2:8187d69071f8 | 102 | } |
tobyspark | 2:8187d69071f8 | 103 | |
tobyspark | 2:8187d69071f8 | 104 | counter++; |
tobyspark | 2:8187d69071f8 | 105 | } |
tobyspark | 2:8187d69071f8 | 106 | } |
tobyspark | 2:8187d69071f8 | 107 | println(); |
tobyspark | 2:8187d69071f8 | 108 | println("const int characterBytesStartChar = " + startID + ";"); |
tobyspark | 2:8187d69071f8 | 109 | println("const int characterBytesEndChar = " + stopID + ";"); |
tobyspark | 2:8187d69071f8 | 110 | print("const uint8_t* characterBytes[] = {"); |
tobyspark | 2:8187d69071f8 | 111 | for (int charID = startID; charID <= stopID; charID++) |
tobyspark | 2:8187d69071f8 | 112 | { |
tobyspark | 2:8187d69071f8 | 113 | print("char" + charID + ", "); |
tobyspark | 2:8187d69071f8 | 114 | } |
tobyspark | 2:8187d69071f8 | 115 | println("};"); |
tobyspark | 2:8187d69071f8 | 116 | } |