possible to do this at one time?

So I have a question that is tangentially related to this new sticky topic about running multiple functions at the same time :cold_sweat:

Using a Arduino Mega, could I ` 1. take a potentionmeter reading on Analog Pin 0, and use that to send PWM signal to an RGB LED on PWM out pins 2-4 2. Take a different pot reading on A1 and use that to send PWM signal to an RGB LED on PWM out pins 5-7 3. Take a multiple different button readings on A2 - A7 at the same time and use those to send different RGB levels out to PWM pins 8-10?

keeping in mind that button presses could be happening AT THE SAME time as pots being turned.... :~

Thank you so much!! :D

I did a rough speed test recently that shows loop() in a very simple program whizzes through at 150k times per second.

Even doing analogReads on all 6 analog pins it was going at 1500 times a second. So there's no doubt that it's running fast enough for it to seem these things are all happening simultaneously. It would need to be the world's fastest button press to get missed.

I did a rough speed test recently that shows loop() in a very simple program whizzes through at 150k times per second.

Ah jeez, (Louise) , and you're not going to share your code ? I feel left out..... XD

ahh coool! that is superrrrrr helpful info for meee!

Now on to figuring out how to write this code....stay tuned for probably more silly questions...

raschemmel: Ah jeez, (Louise) , and you're not going to share your code ? I feel left out..... XD

I was going to, but you said the other day in a thread that you're a hardware guy and software confuses you :P You might juuuust be able to fathom the below, though:

//speed test
//How many times thru loop() in one second?
//This code on a Uno, gave these results:
//    150k with the analogReads commented out
//    1500 with the analogReads in.
//YMMV.

long startTime;
long runTime;
long counter=0;
int analogReading;

void setup()
{
  startTime = millis();
  Serial.begin(9600);
  Serial.print("Start ");
  Serial.println(millis());
}

void loop()
{
  runTime = millis()- startTime;
  counter++;
  
  //have the below block in or out to see their effect
  /*
  analogReading= analogRead(0);
  analogReading= analogRead(1);
  analogReading= analogRead(2);
  analogReading= analogRead(3);
  analogReading= analogRead(4);
  analogReading= analogRead(5);
  */

  if (runTime >= 1000)
  {
    Serial.print("Looped ");
    Serial.print(counter);
    Serial.print(" times in ");
    Serial.print(runTime);
    while(1){
    };
  }

}

zumdar: .stay tuned for probably more silly questions...

Yeah- best that you try it yourself first, then ask for help if / when needed.

JimboZA: I did a rough speed test recently that shows loop() in a very simple program whizzes through at 150k times per second.

Even doing analogReads on all 6 analog pins it was going at 1500 times a second.

Those tests were on a Uno, btw.

I was going to, but you said the other day in a thread that you're a hardware guy and software confuses you

You wound me...... XD

I'll try to wrap my feeble brain around your code..... XD

Now on to figuring out how to write this code....stay tuned for probably more silly questions...

We have a "NO SILLY QUESTIONS !" policy in effect on the forum.

Is this:

startTime = millis();
  Serial.begin(9600);
  Serial.print("Start ");
  Serial.println(millis());

supposed to be this:

startTime = millis();
  Serial.begin(9600);
  Serial.print("Start ");
  Serial.println(startTime);

or are they considered to be one and the same due to the close runtime proximity ?