Pages: [1]   Go Down
Author Topic: Fake Radar for Costume  (Read 878 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...


Second video, with changes that he requested.


Here's the code with comments.
Code:
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
  }
}
« Last Edit: June 11, 2012, 08:22:18 pm by NickGuyver » Logged

Offline Offline
Sr. Member
****
Karma: 1
Posts: 252
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think that you have to add blips in there!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I suggested it but he declined... he may change his mind later though.   smiley-grin
Logged

Pages: [1]   Go Up
Jump to: