Welcome to Laser Pointer Forums - discuss green laser pointers, blue laser pointers, and all types of lasers



Freetronics 128x128 OLED Display

Things

New member
Joined
May 1, 2007
Messages
7,535
Points
0
Just doing a bit of mucking around :D



The examples it comes with are OK - but I wanted an Arduino version of MSpaint, so 2 hours of coding later, here we go :D



Very basic functionality, keys 1-9 select colour, mouse wheel changes brush size, and rightclick clears the display, but it's fun to mess around with :D

Here's the code if anyone else has one & wants to give it a shot. It could probably be easily adapted to any other module or graphic LCD too.

Arduino code:
Code:
#include <SPI.h>
#include <SD.h>
#include <FTOLED.h>
const byte pin_cs = 7;
const byte pin_dc = 2;
const byte pin_reset = 3;
String serial_data[4];  // String for incoming serial data
int varcounter = 0;  // For storing serial to array
Colour drawCol;
OLED oled(pin_cs, pin_dc, pin_reset);

void setup()
{
  Serial.begin(115200);
  oled.begin();
}

void loop() {
if (Serial.available() > 0){
  int nnn;
  delay(10);
  while (Serial.available() > 0) {
    char c = Serial.read();
     if (c == 'c'){
      oled.clearScreen();
      serial_data[2] = "1";
    }
    if (c == ',') {
      varcounter++;
    }
    if (c != ',' && c != '.'){
    serial_data[varcounter] += c;
    }
    if (c == '.'){
       for (int i = 0; i<4; i++)
       serial_data[i] = "";
       varcounter = 0;
    }
  }
  switch (serial_data[2].toInt()){
    case 1:
      drawCol = BLACK;
      break;
    case 2:
      drawCol = WHITE;
      break;
    case 3:
      drawCol = RED;
      break;
    case 4:
      drawCol = GREEN;
      break;
    case 5:
      drawCol = BLUE;
      break;
    case 6:
      drawCol = YELLOW;
      break;
    case 7:
      drawCol = CYAN;
      break;
    case 8:
      drawCol = MAGENTA;
      break;
    case 9:
      drawCol = LIGHTBLUE;
      break;
  }      

  oled.drawFilledCircle(serial_data[0].toInt(),map(serial_data[1].toInt(),0,127,127,0),serial_data[3].toInt(),drawCol);
  }
}

Processing code (only works in the x86 version):
Code:
 import processing.serial.*;
 Serial port;
 color drawcol = color(255,255,255);
 char colKey = '2';
 float wheel = 1.0;
 
 void setup() {
 size(168, 128);
 frameRate(140);
 background(0,0,0);
 println("Available serial ports:");
 println(Serial.list());

 port = new Serial(this, "COM12", 115200);  

 }
 
 void draw() {
 stroke(255);
 line(128,0,128,128);
   if (keyPressed){
     colKey = key;
      switch(key){
   case '1':
     drawcol = color(0,0,0);
     break;
   case '2':
     drawcol = color(255,255,255);
     break;
   case '3':
     drawcol = color(255,0,0);
     break;
   case '4':
     drawcol = color(0,255,0);
     break;
   case '5':
     drawcol = color(0,0,255);
     break;
   case '6':
     drawcol = color(255,255,0);
     break;
   case '7':
     drawcol = color(0,255,255);
     break;
   case '8':
     drawcol = color(216,191,216);
     break;
   case '9':
     drawcol = color(175,238,238);
     break;
 } 
}
 
if (mousePressed == true){
  if (mouseButton == RIGHT){
    port.write("c");
    background(0,0,0);
  } else{
 port.write("." + constrain(mouseX,0,127) + "," + constrain(mouseY,0,127) + "," + colKey + "," + int(wheel));
 noStroke();
 fill(drawcol);
 ellipse(constrain(mouseX,0,127),constrain(mouseY,0,127),int(wheel) * 2,int(wheel) * 2);
    }
  }
  noStroke();
  fill(0);
  rect(129,0,39,128);
  fill(drawcol);
  ellipse(148,20,int(wheel) * 2,int(wheel) * 2);
}
 void mouseWheel(MouseEvent event) {
  wheel = constrain(wheel + event.getAmount(),1,12);
  println(int(wheel));
}
 
Last edited:



NKO29

Active member
Joined
Jun 6, 2013
Messages
870
Points
28
O-LED means Organic-LED doesnt it? But anyways it looks really attractive lol :) I really need to start programming again, i've almost forgotten ALL of what i learnt :(
 

Things

New member
Joined
May 1, 2007
Messages
7,535
Points
0
Yeah, it's a display made up of LED's basically, thus no backlight, and the colours are a lot more vibrant than LCD.

Part of the reason I did this was I hadn't programmed in ages either, had the urge to write code :D
 

NKO29

Active member
Joined
Jun 6, 2013
Messages
870
Points
28
Yeah, I heard O-LED had amazing capabilities :) This would be a great addon to a DIY LPM :) I'm sure you could hook up an ophir sensor to Arduino and make a lovely little LPM box.
+REP :friend: Or not... I need to "spread the love"
 
Last edited:

Things

New member
Joined
May 1, 2007
Messages
7,535
Points
0
Yup, would be very simple to do. The graphing example in my first image is actually one that comes with the library :D
 




Top