Society of Robots - Robot Forum
Software => Software => Topic started by: Zolrag on February 05, 2009, 03:12:01 PM
-
Hi,
I'm trying to use an opto switch to control the movements of my robot. I use a microcontroler ATmega640.
I'm noob in robotic.
I'd like to write a code similar to this:
include libraries
start of the main function
initialisation of variables //which variables do I need for this operation?
initialisation of the opto switch // how to initialise the opto switch? opening the corresponding port on the µcontroler? what is the code?
while(1) (infinite loop)
if (detection from the opto switch) //what is the function needed to detect something with this kind of sensors??
stop motor
delay for a while
restart the motor
end
end
Could you write me a proper code for this application?
thanks a lot
alex
-
you're basically asking us to write the code for you. it would be better if someone wrote the code and walked you through it, so to speak. explain the code.
-
I totally agree with you but nobody I know is able to explain me this so maybe you can do it here....?
-
Actually I don't really need all the code I just want a function for the detection from the opto swich (something similar to the IR sharp function from the library of avr)
and I need to know how to open the corresponding port to start the opto switch.....
that's all... is it possible to explain me how to do that please?
thank
alex
-
oh sorry, i misunderstood ;D i have never built a robot so have never programmed so i can't help. sorry!! :(
-
It's ok don't worry ;) I can program in C++ but it's the first time I built a robot....
-
cool. put some pics on when you've finished ;)
-
All right I'll do that ;D if I manage to make the sensors work :P
-
Could you provide us a link to the opto switch? We need to know how to get the right data from it. If it's just an analog voltage, you can do
int optoswitchreading = a2dConvert10bit(<<insert adc port # here>>);
-
Could you provide us a link to the opto switch? We need to know how to get the right data from it. If it's just an analog voltage, you can do
int optoswitchreading = a2dConvert10bit(<<insert adc port # here>>);
Yes, datasheets are your friend.
-
I still don't have the datasheet because it's a project with the university so I have nothing at home and I still don't know what are the details of the sensors but I'll send it as soon as I get the information...
Thanks anyway Razor
-
Apparently our opto switches are numerical so you don't need to convert the voltage but I still don't understand how to use it...
We also have micro switches which are actually real switches so it should return 1 if it's switch on and 0 if not (for example) but I don't get how the microcontroler can know when the switch is switched on....What is the function that check the state of the switch???
It must be really easy but I'm getting crazy here....
thx
alex
ps: sorry for all the "switch" ;D
-
Need help and code for the ATmega640 you say?
Have you seen my Axon?
http://www.societyofrobots.com/axon