I want ask if the mbot or arduino can run two prcesses at the same time.
I have tried the following code:
#include <MeMCore.h>
MeRGBLed led;
MeDCMotor motor1(M1); //Motor1 is Left Motor
MeDCMotor motor2(M2); //Motor2 is Right Motor
bool ledOn = false;
int interval = 500; //inteval at which to blink
long previousTime = 0; //will store last time LED was updated
void setup() {
led.setpin(13);
}
void loop() {
// get current time every loop
long currentTime = millis();
/* //check if difference between last blink and currenttime is bigger than interval
if(currentTime- previousTime >= interval )
{
//check if LED is already on
if(ledOn == false)
{
led.setColor(255,255,255);
led.show();
ledOn = true;
}
else{
led.setColor(0,0,0);
led.show();
ledOn = false;
}
// save the last time you blinked the LED
previousTime = currentTime;
}*/
motor1.run(-150); //Motor1 (Left) forward is -negative
motor2.run(150); //Motor2 (Right) forward is +positive
}
This code should always check the time bettween the last blinking.
But I have also tried the following code
#include <MeMCore.h>
MeRGBLed led;
MeDCMotor motor1(M1); //Motor1 is Left Motor
MeDCMotor motor2(M2); //Motor2 is Right Motor
bool ledOn = false;
int interval = 500; //inteval at which to blink
long previousTime = 0; //will store last time LED was updated
void setup() {
led.setpin(13);
}
void loop() {
// get current time every loop
led.setColor(255,255,255);
led.show();
delay(500);
led.setColor(0,0,0);
led.show();
delay(500);
motor1.run(-150); //Motor1 (Left) forward is -negative
motor2.run(150); //Motor2 (Right) forward is +positive
}
And I couldn’t notice a different.
Thanks for an answer and explanation of the difference of these two examples and if the first is necessary.
kindly regards