The Shop > Electronics & IC Programing |
Bi-colour LED Blinker - simple PIC project |
(1/1) |
raynerd:
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: ---#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); } } --- End code --- Alternative shown in the video with a nice looking delay that speeds up: --- Code: ---#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); } } } } } --- End code --- |
AdeV:
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 |
raynerd:
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 |
Navigation |
Message Index |