Hey, guys, I am pretty new to the Arduino world and I am trying to build a project with a laser pointer and a few servos. I am building this project for personal use and I want to use two servos for controlling of where the laser pointer is pointing, ie. x, y-axis. I would have no problem building this but I am getting stuck on how to code it. Ideally, I would want the laser to turn on at random spots then turn it off while moving to a different spot. Does anyone have any suggestions? Any help would be greatly appreciated. Thank you!
Do you have servos? Can you control them, individuality? Can you control the laser?
Have you tried to write the code? What were the results?
I do not have the servos but I am using Tinkercad so I can simulate this before I get the parts so I can figure out what to do. I have started writing the code and I can get the servo to turn to set angles however not randomized ones. I can also produce random numbers but I do not know how to relate this to turning the servos.
groundFungus:
Do you have servos? Can you control them, individuality? Can you control the laser?Have you tried to write the code? What were the results?
Images of code is not the way to show your work.
Use CTRL T to format your code.
Attach your complete sketch between code tags.
Use the </> icon in the posting menu.
[code]Paste your sketch here[/code]
Before you proceed any further, study and become familiar with BWD Blink Without Delay coding techniques.
Read Robin2’s discussion.
http://forum.arduino.cc/index.php?topic=223286.0
Also, for further reference, you may need to show us images of your work form time to time.
Show us a good schematic of your circuit.
Show us a good image of your wiring.
Give links to components.
Posting images:
https://forum.arduino.cc/index.php?topic=519037.0
I can get the servo to turn to set angles however not randomized ones. I can also produce random numbers but I do not know how to relate this to turning the servos.
byte randomAngle = random(181);
theServo.write(randomAngle);
UKHeliBob:
byte randomAngle = random(181);
theServo.write(randomAngle);
Thank you!
You are welcome, but I felt sure that the problem must be deeper than that as you knew how to do each part.
Note that if you don't need the value of the random angle you can do
theServo.write(random(181));
even then if you really need to know where the servo was commanded to move to you could use theServo.read()