Sketch not running in a loop


I am very new to Arduino and I try to let something run with Lego Powerfunctions.

Currently I have two questions:

  1. Can I run a sketch only once and not in a loop? If yes, how can I do that?

  2. Can I run different Sketches by PC with PHP?
    I want PHP to controll the Arduino and tell it which Sketch to run when.

Thanks for your help


1). Put all the code in setup and leave the loop function empty.

2). You can only have one program loaded but that program could be looking for input from your PC to tell it what to do.

  1. How can I do that???

There are examples how to merge sketches. Do a search.

It will not always be possible due to interrupt conflicts, running out of pins or memory and whatever other problems can occur.

2) How can I do that???

That's a really big question. You need to provide a lot more information. If you're a novice programmer then it's going to be a pretty tough project. You have to write code to run on the Arduino and code to run on the PC and choose a communication protocol or write one and write the code on each end to use it. It's more than can be explained in one forum post but it is certainly a topic that comes up enough that it is covered all over the internet. You probably won't find anything exactly like what you want, but you can find enough to learn how these things work.