Problem Adding Additional Transducers to Single Set

Hi, I would like to add additional transducers to the set of code that I am doing now, and it needs to be inside the for loop.

So simply to say, when I trigger a command, it needs to go through the loop. A particle would be used and it has to move through a series of transducers. Currently able to move through one pair of transducers only, and I would like to move it through 2 or 3 pairs of transducers minimally.

Seeking for help please.

`#include <pwmWrite.h>
#include <Servo.h>

const int pwmPin[8] = { 13, 14, 15, 16, 17, 18, 19, 22 };
const uint16_t duty = 512; //50% duty
const uint16_t deadtime = 10;
const uint16_t phase[5] = { 0, 256 , 512, 768, 1024}; //0 and 90 degree phase shift. 256=90, 512 = 180.
const uint16_t shift[2] = { 42, 42 };
const uint32_t frequency = 40000;
const byte resolution = 10;
Pwm pwm = Pwm();

void setup() {
Serial.begin(115200);
pwm.pause();

pwm.resume();
pwm.printDebug();
}
// Right side is Channel 14, Left side is Channel 13.

void loop() {
pwm.write(pwmPin[1], duty, frequency, resolution, phase[0]);
pwm.write(pwmPin[5], duty, frequency, resolution, phase[1]);
pwm.write(pwmPin[2], duty, frequency, resolution, phase[1]);
pwm.write(pwmPin[6], duty, frequency, resolution, phase[1]);

while (1) {
char command = Serial.read();
if (command == 'a') {
for (int i = 0; i<=1024; i++) {
pwm.write(pwmPin[1], duty, frequency, resolution, i);
delay(2);
}
}
}
}`

I moved your topic to an appropriate forum category @nsicch960319.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Hello @nsicch960319,

welcome to the arduino-forum.
There are a few things that you can do to speed up finding a solution.
The most important thing is to give a detailed description of the wanted functionality.

I'm pretty sure that you agree and will follow the way how to solve your problem mimimum 200 minutes faster.
This requires to invest 20 minutes of your precious time to read how to speedup solving your problems.

Directly after registering you got presented informations how to speed up solving your problem.
You should really read it.

What is a particle in this case?
Usually a particle is a very very tiny object with a diameter of less than 0,01 mm.

I have no idea how counting up variable "i" from 0 to 1024 moves a "particle" through a pair of transducers.

You should provide links to the libraries that you are using.

It would be very good if you describe in detail how your "device" is working.

Hi, the particle is indeed less than 0.01mm (diameter).

Currently this code allows me to move the particle up and down within one transducer. but i would like to move this particle in a straight line between 4 particles. How do I configure the code in that way?

post this working sketch.

I repeat myself

You are working on an informatic project. And what is most needed in an informatic project is: information.

I have no idea how in summary five 0,01 mm -diameter particles are doing what in your device?

moving vertically against gravity?
or
horizontally ?

make a handdrawn picture of how your transducers are physically placed.

How should I say a single word or write code if you don't even

???

I am asking myself if this thread is just trolling.

To convince me that you are seriously interested in realising this project you should read this welcome message
how to get the best out of this forum
and write a posting that fulfills all the things that are mentioned in this tutorial.

I'm pretty sure that you agree and will follow the way how to solve your problem mimimum 200 minutes faster.
This requires to invest 20 minutes of your precious time to read how to speedup solving your problems.

Directly after registering you got presented informations how to speed up solving your problem.
You should really read it.

best regards Stefan

not clear what you mean by transducers and what you're trying to do.

looks like you're controlling something with a PWM signal. looks like there a eight pins that can be controlled, you initialize four of them and when you receive a command thru the serial interface you drive the phase argument form 1-1024.

  • why isn't there additional code affecting the other devices controlled by PWM?

  • why isnt't there a call to Serial.available() before reading serial input?

  • should there be additional commands, other that 'a'?

  • do you understand that the Arduiono main() calls setup() once and loop() repeatedly? why not call the four pwmWrites() in setup and just check for serial commands in loop() instead of a while (1)?

  • what needs to be done differently to process additional transducers?