Arduino - Page 1
Forum section: electronics / beginners

author: mtc2629
author_rank: Contributor
timestamp: October 07, 2013, 01:23:46 am
content: I just wondering what the code should be using 5 servos and 5 flex sensors can i just copy and paste the code 5 times

author: xrunner
author_rank: Super Contributor
timestamp: October 07, 2013, 01:27:48 am
content: Quote from: mtc2629 on October 07, 2013, 01:23:46 amHard to say without a lot more information about the project.

author: pstrag
author_rank: Newbie
timestamp: October 07, 2013, 04:13:11 am
content: Power of most programming languages is that You can use functions, so You have to write only one"part of code" - function to control servo or flex sensor. In code you made, you have to just use this one function and say which servo you will be talking to at the moment, so you can have many servos connected with not a big increase in program size.Slawek.

author: Greyersting
author_rank: Regular Contributor
timestamp: October 07, 2013, 04:14:26 am
content: Can you post exactly what you are trying to do?

author: MrAureliusR
author_rank: Unknown
timestamp: October 07, 2013, 05:36:14 am
content: Quote from: Greyersting on October 07, 2013, 04:14:26 amHe's trying to get 5 posts to enter the contest

author: Greyersting
author_rank: Regular Contributor
timestamp: October 07, 2013, 05:38:20 am
content: Quote from: MrAureliusR on October 07, 2013, 05:36:14 amWere you referring to me or to him?

author: MrAureliusR
author_rank: Unknown
timestamp: October 07, 2013, 05:39:29 am
content: To the OP...the forums have been flooded with a bunch of stupid questions and one-liners... I really hope Dave DOES check the posts when the randomizer picks a name with less than say 25 posts...

author: jakehiltz
author_rank: Contributor
timestamp: October 07, 2013, 05:06:52 pm
content: I joined for the contest , BUT I refuse to post stupid comments. If this guy is seriously asking if he can just copy and paste the code 5 times he should really read a little bit more about Arduino.On the other hand if this is a serious question you should take a look at what you are trying to do ... If you are just trying to run 5 servo motors it should be as simple as declaring each pin and activating each motor...Your question is so vague its impossible to even know what you want to do...do you know what you want to do?

author: xrunner
author_rank: Super Contributor
timestamp: October 07, 2013, 10:02:01 pm
content: Quote from: mtc2629 on October 07, 2013, 01:23:46 amWell, I'll give another answer.Sure. Go ahead and see what happens.

author: tehmeme
author_rank: Regular Contributor
timestamp: October 07, 2013, 10:14:54 pm
content: Quote from: xrunner on October 07, 2013, 10:02:01 pmIrrespective of the ops intentions, this is probably the best answer yet.Experimentation, the best way to learn. (imo)

author: xstream
author_rank: Newbie
timestamp: October 07, 2013, 11:00:09 pm
content: Until some poor soul has to read that code againNo really copy and paste can be an option but for clean code it should never be a good one. Sometimes you have to c&p and change some things each time (that should also not be necessary for well written code) but if it is truly always the same or only some index variable changes you really want to use a loop (just read any tutorial on Arduinos and loops)

author: Rigby
author_rank: Super Contributor
timestamp: October 07, 2013, 11:38:10 pm
content: Quote from: mtc2629 on October 07, 2013, 01:23:46 amNever a good idea, as it is almost never necessary. If I knew the language better, I'd be able to say definitively that it isn't, but I don't, so I can't.Copypasta contributes heavily to overall code stink.

author: idiotsecant
author_rank: Newbie
timestamp: October 09, 2013, 12:29:31 am
content: You all laugh but my first experience with pseudo-programming was using autohotkey to make a bot to play a video game I liked when I was a teenager ( says something about the videogame if the funnest way to play it is to make your computer play it for you). I had a function that required ~500 iterations of a function, but I didn't really understand FOR loops so I recreated that functionality with some intense copypasta 500 times. Someone on the forums I proudly posted my script on instructed me on the wonders of branching logic