Author Topic: need to control blinking lights with microcontroller  (Read 1017 times)

0 Members and 1 Guest are viewing this topic.

Offline rahulpwnsTopic starter

  • Jr. Member
  • **
  • Posts: 28
  • Helpful? 0
need to control blinking lights with microcontroller
« on: September 26, 2011, 04:28:29 PM »
i am working on a project where i have a main microcontroller (arduino mega 1280) controlling a robot.
in this project, i have two led lights that i wan to blink when the robot turns.
these will function as turn signals. so, when the main microcontroller tells the robot to turn left (for example), i want the left led to blink.
so...if the robot turns left, the left led blinks while the robot is turning. if the robot turns right, the right led blinks while the robot is turning.
what is a cheap (~$5.00) microcontroller (full kit) that can handle this?

Offline joe61

  • Supreme Robot
  • *****
  • Posts: 417
  • Helpful? 16
Re: need to control blinking lights with microcontroller
« Reply #1 on: September 26, 2011, 06:02:03 PM »
Are you saying you have a 1280? That has 86 I/O pins, you must be doing a lot if you need  a secondary processor to blink LEDs.

Could you expand on what you want a bit more?

Edit: Just realized you said arduino mega. That's a 2560, but still has 86 I/O pins.

Joe
« Last Edit: September 26, 2011, 06:05:53 PM by joe61 »

Offline rahulpwnsTopic starter

  • Jr. Member
  • **
  • Posts: 28
  • Helpful? 0
Re: need to control blinking lights with microcontroller
« Reply #2 on: September 26, 2011, 10:24:01 PM »
i'm probably taking up close to half of those pins.
how could i run two simultaneous processes on the mega 1280?

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: need to control blinking lights with microcontroller
« Reply #3 on: September 26, 2011, 10:58:57 PM »
how could i run two simultaneous processes on the mega 1280?
Don't you read the answers you get?
I'll repeat... You don't need it to happen at the exact same picosecond!
Windows on a PC with a single core cannot run two things at once, it just switches between each process, giving them a time slice each at a fast rate, convincing you that things happens concurrently.
Simultaneous processing isn't needed to flash a LED.
You only need one core.

I'f you find it that hard to do, add a LED flasher build from a 555 or similar and just toggle a pin to enable it when you turn. It's a waste of circuitry, but might be easier for you to handle :)

Besides, turns signals are used on cars to tell the other traffic about an intetntion to deviate from going straight, to avoid accidents. There's no reason for turns flashers on a robot.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline newInRobotics

  • Supreme Robot
  • *****
  • Posts: 1,015
  • Helpful? 48
  • N.I.R.
Re: need to control blinking lights with microcontroller
« Reply #4 on: September 27, 2011, 12:27:27 AM »
how could i run two simultaneous processes on the mega 1280?

You can (to some extent at least) even though it is not mandatory in Your application. You have to use interrupts and timers for that. Simple task such as flashing LED at required frequency can be done, as mentioned before, using interrupt and timer - leaving main processing resources unused (or used for other tasks). So, if You have process running in Your main while(1) loop and an interrupt driven - timer regulated LED flasher as the same time, they are working in parallel and almost independent from one another (don't confuse this with interrupt routines that interrupts (pauses) main while(1) loop to execute some other tasks; such interrupt cannot work in parallel with main loop).

Have a look at ATmega1280 datasheet, under Interrupts section; and also check out Newbie's Guide to AVR Timers tutorial.
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian W

Offline rahulpwnsTopic starter

  • Jr. Member
  • **
  • Posts: 28
  • Helpful? 0
Re: need to control blinking lights with microcontroller
« Reply #5 on: September 28, 2011, 05:56:38 PM »
so can someone explain or refer a site to me how these delays work?
if give the instruction to blink an led every 1 second, will the arduino not give the instruction to accelerate the motor?
from what i understand, two cores are required to do that.

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,920
  • Helpful? 97
Re: need to control blinking lights with microcontroller
« Reply #6 on: September 28, 2011, 07:01:07 PM »
There are many, many coding examples on having a arduino do 'multitasking'. Do dig around on the web to find them.

While I don't use an arduino but PIC's, I can have the processor do several tasks. I have posted sample code I use on one of my robots. The code does:
1- Measures the time of each wheel encoder tick.
2- Calculates if the wheel speed is too fast or too slow and adjust the motor's PWM duty every 4th PWM pulse.
3- Reads the bump sensors and sets a state to stop.
4- Reads the Sharp IR distance sensor (ADC reading) and sets a state for objects to avoid.
5- Gathers internal variables, converts these the ASCII and sends then out a serial port (RF module to the PC for diagnostics). The serial port is interrupt driven from data in a ring buffer.
6- Receives serial data (from interrupt) to a ring buffer.
7- Interpret input serial data as commands.
8- Reads a compass heading through I2C .
9- Then the MAIN processing loop puts together the various inputs and sets putput states (stop, turn right, turn left, etc)

All of these processes occur (it seems) simultaneous but it fact occur one processor clock cycle at a time. 

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: need to control blinking lights with microcontroller
« Reply #7 on: September 28, 2011, 09:25:42 PM »
Hi,

so can someone explain or refer a site to me how these delays work?

Besides Google, there's the Arduino web site and the large archive of Arduino compatible projects (both of which you would have found, if you had spent even a few minute on Google).

Here's another site that you might find helpful.


if give the instruction to blink an led every 1 second, will the arduino not give the instruction to accelerate the motor?

The Arduino (or rather the AVR running it) and all other microcontrollers are dumb as door nails and they have zero initiative, so will only do what you tell it to - as long as you tell it the right way of course ;)

Assume 3 variables - lets call them A, B and C (to remove you from the thought of left, right and LED flashing).
Say A is 50, B is 25 and C is 42.
Now here comes the exam question...
If you issue a command to change C to 99, what will the value of A and B become?

Besides, you don't give an instruction to blink an LED once a second. You program an algorithm/routine to set a pin either high or low at the times that fits the pattern you want.

If you use a a 4MHz clock, shifting a port pin high or low will take 250ns!


from what i understand, two cores are required to do that.

From what I have repeatedly told you, a single core is more than plenty.
Why ask if you don't believe the answers you get?
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline newInRobotics

  • Supreme Robot
  • *****
  • Posts: 1,015
  • Helpful? 48
  • N.I.R.
Re: need to control blinking lights with microcontroller
« Reply #8 on: September 29, 2011, 12:40:35 AM »
so can someone explain or refer a site to me how these delays work?
I did.

if give the instruction to blink an led every 1 second, will the arduino not give the instruction to accelerate the motor?
No it won't, unless You comand it to do so.

from what i understand, two cores are required to do that.
From what You understand, to post a forum message requires at least 1000 cores in Your desktop PC ;D
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian W

Offline joe61

  • Supreme Robot
  • *****
  • Posts: 417
  • Helpful? 16
Re: need to control blinking lights with microcontroller
« Reply #9 on: September 29, 2011, 05:21:50 AM »
so can someone explain or refer a site to me how these delays work?
if give the instruction to blink an led every 1 second, will the arduino not give the instruction to accelerate the motor?
from what i understand, two cores are required to do that.

You should read up on timers. The AVR timers are very powerful and can be programmed to do things automatically at regular intervals - things like blinking an LED. When you turn the robot start off such a timer and let it blink the LED for you. When you're done turning, turn off the timer.

I think you would do well to read the data sheet for your processor - or at least scan it to get an idea of what it can do. Also, go to the Arduino web site and read the documentation for the programming libraries they offer.

Until you learn what you have to work with, it's going to be pretty hard to figure out what to do.

Joe

 


Get Your Ad Here

data_list