Pages: [1]   Go Down
Author Topic: 16x4 "pixel" display  (Read 1462 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've wanted to make a little cool effect on my 16x2 character display for a little music project I've been planning. So I made this little sketch and I wanted to share.

I tried to make the code comprehensible but please tell me if not.

Each character is two "pixels".

Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);

float w=0;
int xWidth = 16;
int yWidth = 4;

//y first, x second
byte dis[4][16] = {
  {B1,B0,B0,B0,B1,B0,B1,B0,B0,B0,B0,B0,B0,B0,B0,B0  },
  {B0,B0,B1,B0,B1,B0,B1,B0,B0,B0,B0,B0,B0,B0,B0,B0  },
  {B0,B0,B1,B0,B0,B0,B1,B0,B0,B0,B0,B0,B0,B0,B0,B0  },
  {B1,B0,B0,B0,B1,B0,B1,B0,B0,B0,B0,B0,B0,B0,B0,B0  },
};

static byte top[8] = {B11111,B11111,B11111,B11111,B00000,B00000,B00000,B00000};
static byte bot[8] = {B00000,B00000,B00000,B00000,B11111,B11111,B11111,B11111};
static byte ful[8] = {B11111,B11111,B11111,B11111,B11111,B11111,B11111,B11111};

void setup() {
  lcd.createChar(0,top);
  lcd.createChar(1,bot);
  lcd.createChar(2,ful);
  lcd.begin(xWidth,yWidth/2);
  updateDisplay();
}

void loop() {
  fillDisplay(0);
  for(int x=0;x<xWidth;x++) {
    paint(x,2+2*cos(radians(w*(x+1))),1);
  }
  updateDisplay();
  w+=1;
}

void fillDisplay(int c) {//0=white, 1=black, 2=invert
  for (int x=0;x<=xWidth;x++) {
    for (int y=0;y<=yWidth;y++) {
      if(c==2){dis[y][x]^=B1;}else{dis[y][x]=(c==1)?B1:B0;}
    }
  }
}

void paint(int x,int y,int c) {
  x=round(x);
  y=round(y);
  if (x<17&&x>-1&&y>-1&&y<5) {
    if(c==2){dis[y][x]^=B1;}else{dis[y][x]=(c==0)?B0:B1;}
  }
}
void updateDisplay() {
  lcd.setCursor(0,0);
  int r;
  for (int i=0;i<=xWidth;i++) {
    r=0;
    r+=(dis[0][i]==B1)?1:0;
    r+=(dis[1][i]==B1)?2:0;
    lcd.write((r==0)?254:r-1);
  }
  lcd.setCursor(0,1);
  for (int i=0;i<=xWidth;i++) {
    r=0;
    r+=(dis[2][i]==B1)?1:0;
    r+=(dis[3][i]==B1)?2:0;
    lcd.write((r==0)?254:r-1);
  }
}

Haven't tested the code on other displays but should hopefully work.

Have a nice new year!
Logged

India
Offline Offline
Full Member
***
Karma: 1
Posts: 131
The Tech Gamer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'll let you know if it works on my LCD, coz mine is a bit weird. smiley-razz
Logged

|I love Technology|

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Added three more effects:
Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);

float w=0;
float u=0;
float t=0;
int xWidth = 16;
int yWidth = 4;

//y first, x second
byte dis[4][16] = {
  {B1,B0,B0,B0,B1,B0,B1,B0,B0,B0,B0,B0,B0,B0,B0,B0    },
  {B0,B0,B1,B0,B1,B0,B1,B0,B0,B0,B0,B0,B0,B0,B0,B0    },
  {B0,B0,B1,B0,B0,B0,B1,B0,B0,B0,B0,B0,B0,B0,B0,B0    },
  {B1,B0,B0,B0,B1,B0,B1,B0,B0,B0,B0,B0,B0,B0,B0,B0    },
};

static byte top[8] = {B11111,B11111,B11111,B11111,B00000,B00000,B00000,B00000};
static byte bot[8] = {B00000,B00000,B00000,B00000,B11111,B11111,B11111,B11111};
static byte ful[8] = {B11111,B11111,B11111,B11111,B11111,B11111,B11111,B11111};

void setup() {
  lcd.createChar(0,top);
  lcd.createChar(1,bot);
  lcd.createChar(2,ful);
  lcd.begin(xWidth,yWidth/2);
  updateDisplay();
}

void loop() {
  while(w<500) {
    fillDisplay(0);
    for(int x=0;x<xWidth;x++) {
      paint(x,2+2*cos(radians(w*(x+1))),1);
    }
    updateDisplay();
    w+=0.5;
  }
  w=0;
  while(w<50) {
    fillDisplay(0);
    for (int x=0;x<xWidth;x++) {
      for (int y=0;y<yWidth;y++) {
        u=255*cos(x)+255*sin(radians(w*y));//would look better on bigger display;Tested in Processing
        u=(u>16)?1:0;
        paint(x,y,u);
      }
    }
    updateDisplay();
    w+=0.1;
  }
  w=0;u=0;t=0;
  while(t<520) {
    w=40*cos(millis()/480)+70*cos(millis());
    u+=(w-u)/50;
    fillDisplay(0);
    for (int x=0;x<xWidth;x++) {
      paint(x,2+2*cos(radians(((1+x)*u)+millis()/20)),1);
    }
    t+=0.4;
    updateDisplay();
  }
  w=0;u=0;
  while(w<750) {
    fillDisplay(0);
    for (int x=0;x<xWidth;x++) {
      for (int y=0;y<yWidth;y++) {
        u=x^y;
        u=(u<8+8*cos(radians(w)))?1:0;
        paint(x,y,u);
      }
    }
    updateDisplay();
    w+=1.4;
  }
  w=0;u=0;
}

void fillDisplay(int c) {//0=white, 1=black, 2=invert
  for (int x=0;x<=xWidth;x++) {
    for (int y=0;y<=yWidth;y++) {
      if(c==2){
        dis[y][x]^=B1;
      }
      else{
        dis[y][x]=(c==1)?B1:B0;
      }
    }
  }
}

void paint(int x,int y,int c) {
  x=round(x);
  y=round(y);
  if (x<17&&x>-1&&y>-1&&y<5) {
    if(c==2){
      dis[y][x]^=B1;
    }
    else{
      dis[y][x]=(c==0)?B0:B1;
    }
  }
}
void updateDisplay() {
  lcd.setCursor(0,0);
  int r;
  for (int i=0;i<=xWidth;i++) {
    r=0;
    r+=(dis[0][i]==B1)?1:0;
    r+=(dis[1][i]==B1)?2:0;
    lcd.write((r==0)?254:r-1);
  }
  lcd.setCursor(0,1);
  for (int i=0;i<=xWidth;i++) {
    r=0;
    r+=(dis[2][i]==B1)?1:0;
    r+=(dis[3][i]==B1)?2:0;
    lcd.write((r==0)?254:r-1);
  }
}
Logged

Milano, Italy
Offline Offline
Faraday Member
**
Karma: 11
Posts: 3091
Sideralis Arduino!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

A picture?
Logged

Federico - Sideralis
Arduino &C: http://www.sideralis.org
Foto: http://blackman.amicofigo.com

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
A picture?

How about a video in crappy quality?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

very crappy video but its cool  smiley-grin
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 200
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice effort indeed.
Logged

India
Offline Offline
Full Member
***
Karma: 1
Posts: 131
The Tech Gamer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Really Cool!  8-)
Logged

|I love Technology|

Pages: [1]   Go Up
Jump to: