Author Topic: Bi-colour LED Blinker - simple PIC project  (Read 6860 times)

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Bi-colour LED Blinker - simple PIC project
« on: February 10, 2010, 02:24:56 PM »
Just something I`ve been doing at work, a very simple project but it makes a nice introduction to coding! It is actually just two pins at logic 1 independently and then together so on the development board it is simply two leds flashing but if you put it with a bi-colour led (maplin sell these as tri-colour but they are actually only two colours R&G, true tri-colour is RGB) it looks quite nice.

I`m sure you`ll get the idea after a few seconds!   :lol:



Simple flashing:

Code: [Select]
#define red GPIO.b0
#define green GPIO.b1
int i=500;
char cnt;
void init()
{
ANSEL  = 0;              // Configure AN pins as digital
CMCON  = 7;              // Turn off the comparators
TRISIO = 0;              // configure pins of GPIO as output
GPIO = 0x00;
}

void main()
{
init ();

   while (1)
   {
          red = 1;
          green=0;
          delay_ms(200);
          red = 0;
          green = 1;
          delay_ms(200);
          red = 1;
          delay_ms(200);
   }
}

Alternative shown in the video with a nice looking delay that speeds up:

Code: [Select]
#define red GPIO.b0
#define green GPIO.b1
int i=500;
char cnt;
void init()
{
ANSEL  = 0;              // Configure AN pins as digital
CMCON  = 7;              // Turn off the comparators
TRISIO = 0;              // configure pins of GPIO as output
GPIO = 0x00;
}

void main()
{
init ();

   while (1)
   {
   i = i-40;
       if (i <= 0)
       i = 500;
       else
        {
          red = 1;
          green=0;
          Vdelay_ms(i);
          red = 0;
          green = 1;
          Vdelay_ms(i);
          red = 1;
          Vdelay_ms(i);
             if (i <200)
             {
              red = 1;
              green=0;
              Vdelay_ms(i);
              red = 0;
              green = 1;
              Vdelay_ms(i);
              red = 1;
              Vdelay_ms(i);
              }
                  if (i<100)
                  {
                  for (cnt=0; cnt<80; cnt++)
                  {
                  red = 1;
                  green=0;
                  Vdelay_ms(i);
                  red = 0;
                  green = 1;
                  Vdelay_ms(i);
                  red = 1;
                  Vdelay_ms(i);
                  }
                  }
        }
   }
}


Offline AdeV

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2434
  • Country: gb
Re: Bi-colour LED Blinker - simple PIC project
« Reply #1 on: February 10, 2010, 05:00:26 PM »
Getting that sort of thing working is great, isn't it? Almost as satisfying as turning out a really well made piece on a machine...

I recently bought an Arduino experimenters kit from these chaps: http://www.oomlout.co.uk/ It cost 50 quid, but it came with the all important processor board, and a whole bunch of LEDs, resistors, a servo  :borg:, motor, temp sensor, yada yada. Brilliant fun, and the programming language is still C-based, so if you can get a handle on that, you're away.

As a programmer by trade (albeit not in C), I managed to knock up a keypad-operated security system in about 1/2 day, from a standing start, using a servo to operate a yale-style lock. The only problem is, the servo won't pull the comedy lock handle far enough to actually open the door - but that's just an excuse to do more machining work  :D
Cheers!
Ade.
--
Location: Wallasey, Merseyside. A long way from anywhere.
Occasionally: Zhengzhou, China. An even longer way from anywhere...

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: Bi-colour LED Blinker - simple PIC project
« Reply #2 on: February 10, 2010, 06:35:26 PM »
Yea, it really is. I actually teach and take my development board in with me to amuse me during lunch. Quite a few of the students have shown an interest and come back almost in a little club so we made this yesterday as our first project. I`ve actually made a few little programs now, a binary clock, x-axis controller, GLCD snakes...I`m getting much better but I started off not having any experience same with machining. It is all a nice learning curve!

Chris