Go Down

Topic: Fake Radar for Costume (Read 916 times) previous topic - next topic

NickGuyver

Jun 12, 2012, 03:20 am Last Edit: Jun 12, 2012, 03:22 am by NickGuyver Reason: 1
This was a project for a friend who wanted a fake radar for his costume. It uses the SparkFun "Huge" LCD (T6936 controller), graphic LCD backpack, and Arduino Uno R3. This is my first Arduino project and first LCD project, so if you have any input let me know.

First video...
http://www.youtube.com/watch?v=VAR64-TauaI&feature=relmfu

Second video, with changes that he requested.
http://www.youtube.com/watch?v=7SJFg6c5lPU&feature=plcp

Here's the code with comments.
Code: [Select]
byte c = 0, x1 = 0, x2 = 0, z = 0;

void StartDim()
{
 long randLong = 0;
 byte randByte = 0;
 
 for (int r = 0; r < 50; r = r + 1)
 {
   randLong = random(0, 100);
   randByte = byte(randLong);
   
   Serial.write(0x7c);
   Serial.write(0x02);
   Serial.write(randByte);
   
   delay(50);
 }
 
 Serial.write(0x7c);
 Serial.write(0x02);
 Serial.write(0x64);//Set backlight back to 100
}
void DrawGrid()
{  
 for (byte dgx = 0; dgx < 159; dgx = dgx + 16)//Draw x grid line
 {
   Serial.write(0x7c);
   Serial.write(0xc);
   Serial.write(dgx);//x
   Serial.write(z);//y0
   Serial.write(dgx);//x
   Serial.write(0x7f);//y127
   Serial.write(0x1);//draw
 }
 
 Serial.write(0x7c);
 Serial.write(0xc);
 Serial.write(0x9f);//x
 Serial.write(z);//y0
 Serial.write(0x9f);//x
 Serial.write(0x7f);//y127
 Serial.write(0x1);//draw  

 for (byte dgy = 0; dgy < 127; dgy = dgy + 16)//Draw y grid line
 {
   Serial.write(0x7c);
   Serial.write(0xc);
   Serial.write(z);//x0
   Serial.write(dgy);//y
   Serial.write(0x9f);//x159
   Serial.write(dgy);//y
   Serial.write(0x1);//draw
 }
 
 Serial.write(0x7c);
 Serial.write(0xc);
 Serial.write(z);//x0
 Serial.write(0x7f);//y
 Serial.write(0x9f);//x159
 Serial.write(0x7f);//y
 Serial.write(0x1);//draw
}

void DrawLines()
{
 //Draw 1
 Serial.write(0x7c);
 Serial.write(0xc);

 if (c == 0)
   Serial.write(x1++);//x0
 else
   Serial.write(x1--);//x159

 Serial.write(z);//y0

 if (c == 0)
   Serial.write(x2++);//x0
 else
   Serial.write(x2--);//x159

 Serial.write(0x7f);//y127
 Serial.write(0x1);//draw

 //Draw 2
 Serial.write(0x7c);
 Serial.write(0xc);
 Serial.write(x1);//x1
 Serial.write(z);//y0
 Serial.write(x2);//x1
 Serial.write(0x7f);//y127
 Serial.write(0x1);//draw
}

void EraseLines()
{
 int glt = 0, modx1 = 0, modx2 = 0;
 
 modx1 = x1 % 16;
 modx2 = x2 % 16;

 if (glt != modx1)//Do not erase x axis grid lines
 {
   //Erase 1
   Serial.write(0x7c);
   Serial.write(0xc);

   if (c == 0)
     Serial.write(--x1);//x0
   else
     Serial.write(++x1);//x159

   Serial.write(z);//y0

   if (c == 0)
     Serial.write(--x2);//x0
   else
     Serial.write(++x2);//x159

   Serial.write(0x7f);//y127
   Serial.write(z);//erase

   for (byte dgy = 0; dgy < 127; dgy = dgy + 16)//Draw y grid dots that were erased
   {
     Serial.write(0x7c);
     Serial.write(0x10);
     Serial.write(x1);//x0
     Serial.write(dgy);//y
     Serial.write(0x1);//draw
   }
   
   //Draw 127
   Serial.write(0x7c);
   Serial.write(0x10);
   Serial.write(x2);//x0
   Serial.write(0x7f);//y
   Serial.write(0x1);//draw
 }
 
 //Draw 0
 Serial.write(0x7c);
 Serial.write(0xc);
 Serial.write(z);//x159
 Serial.write(z);//y0
 Serial.write(z);//x159
 Serial.write(0x7f);//y127
 Serial.write(0x1);//draw
 
 //Draw 159
 Serial.write(0x7c);
 Serial.write(0xc);
 Serial.write(0x9f);//x159
 Serial.write(z);//y0
 Serial.write(0x9f);//x159
 Serial.write(0x7f);//y127
 Serial.write(0x1);//draw

 if (glt != modx2)//Do not erase x axis grid lines
 {
   //Erase 2
   Serial.write(0x7c);
   Serial.write(0xc);

   if (c ==0)
     Serial.write(++x1);//x1
   else
     Serial.write(--x1);//x158

   Serial.write(z);//y0

   if (c == 0)
     Serial.write(++x2);//x1
   else
     Serial.write(--x2);//x158

   Serial.write(0x7f);//y127
   Serial.write(z);//erase

   for (byte dgy = 0; dgy < 127; dgy = dgy + 16)//Draw y grid dots that were erased
   {
     Serial.write(0x7c);
     Serial.write(0x10);
     Serial.write(x2);//x0
     Serial.write(dgy);//y
     Serial.write(0x1);//draw
   }
     
   //Draw 127
   Serial.write(0x7c);
   Serial.write(0x10);
   Serial.write(x2);//x0
   Serial.write(0x7f);//y
   Serial.write(0x1);//draw
 }
 
 //Draw 0
 Serial.write(0x7c);
 Serial.write(0xc);
 Serial.write(z);//x159
 Serial.write(z);//y0
 Serial.write(z);//x159
 Serial.write(0x7f);//y127
 Serial.write(0x1);//draw
 
 //Draw 159
 Serial.write(0x7c);
 Serial.write(0xc);
 Serial.write(0x9f);//x159
 Serial.write(z);//y0
 Serial.write(0x9f);//x159
 Serial.write(0x7f);//y127
 Serial.write(0x1);//draw
}

void setup()
{
 Serial.begin(115200);
 
 StartDim();//Random Dimmer Startup
 DrawGrid();//Draw background grid

 delay(2000);
}

void loop()
{
 if (c == 0)
 {
   DrawLines();

   //Delay: 100 = Too Fast for LCD Refresh Rate, 200 = Too Slow to Watch
   delay(140);

   EraseLines();

   if (x1 == 159)//See if end of screen
     c = 1;//Set backwards
 }

 else
 {
   DrawLines();

   delay(140);

   EraseLines();

   if (x1 == 0)//See if end of screen
     c = 0;//set forwards
 }
}

RobDrizzle

I think that you have to add blips in there!

NickGuyver

I suggested it but he declined... he may change his mind later though.   :D

Go Up