Go Down

Topic: 16x4 "pixel" display (Read 1 time) previous topic - next topic

median

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: [Select]

#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!

Divyanshu

I'll let you know if it works on my LCD, coz mine is a bit weird. :P
|I love Technology|

median

Added three more effects:
Code: [Select]

#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);
 }
}

Federico

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

median

Quote
A picture?


How about a video in crappy quality? http://www.youtube.com/watch?v=93y3u6JOI08

Ognjetina

very crappy video but its cool  :D

novice


Divyanshu

|I love Technology|

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy