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

Dependents:   SPK-DVIMXR SPK-DMXer

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers spk_oled_screenByteMaker--processing.h Source File

spk_oled_screenByteMaker--processing.h

00001 // OLED display using SSD1305 driver
00002 // A library by *spark audio-visual
00003 
00004 /* Copyright (c) 2011 Toby Harris, MIT License
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
00007  * and associated documentation files (the "Software"), to deal in the Software without restriction, 
00008  * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
00009  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
00010  * furnished to do so, subject to the following conditions:
00011  *
00012  * The above copyright notice and this permission notice shall be included in all copies or 
00013  * substantial portions of the Software.
00014  *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
00016  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
00017  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
00018  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
00019  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00020  */
00021 
00022 int w = 132;
00023 int h = 64;
00024 int scaleFactor = 10;
00025 
00026 PImage imgPixel;
00027 color white = color(255, 255, 255, 255);
00028 color black = color(0, 0, 0, 255);
00029 
00030 void setup()
00031 {
00032   size(w*scaleFactor, h*scaleFactor);
00033   imgPixel = loadImage("spk_dvimxr_screen.png");
00034 
00035   noSmooth();
00036 }
00037 
00038 void draw()
00039 {
00040   background(0);
00041   image(imgPixel, 0, 0, w*scaleFactor, h*scaleFactor);
00042 }
00043 
00044 void mouseDragged() 
00045 {
00046   int x = mouseX/scaleFactor;
00047   int y = mouseY/scaleFactor;
00048 
00049   imgPixel.set(x, y, white);
00050 }
00051 
00052 void mousePressed()
00053 {
00054   int x = mouseX/scaleFactor;
00055   int y = mouseY/scaleFactor;
00056 
00057   if (imgPixel.get(x, y) == white)
00058   {
00059     imgPixel.set(x, y, black);
00060   }
00061   else
00062   {
00063     imgPixel.set(x, y, white);
00064   }
00065 }
00066 
00067 void keyPressed()
00068 {
00069   println("{");
00070   for (int page = 0; page < 8; page++)
00071   {
00072     for (int i = 0; i < w; i++)
00073     {
00074       byte theByte = 0;
00075       for (int j = 0; j < 8; j++)
00076       {
00077        if (imgPixel.get(i, (page*8)+j) == white)
00078        {
00079           theByte += pow(2, j); 
00080        }
00081       }
00082       print("0x" + hex(theByte, 2));
00083       print(", ");
00084     }
00085     println();
00086   }
00087   println("}");
00088 }