Arduino multiprocessing with millis cycle

Arduino Corso

When you make a code in Arduino you must make a loop cicle. If you want control different functions, different “Objects”, you can use delay process or similar. But there is a practical solution. The millis cycle.

When Arduino goes ON, the clock times inside the microcontroller goes to run. He count from 0 to 4,294,967,295 (the maximum value for unsigned long). You can store this value in unsigned long variable, and use this value for controlling different kind of object, something like a multiprocessing.

This is really good also for Cayenne APP. With Cayenne you can make a your personal IoT project. You can control by your iOS or Android device, different kind of sensors or switches in your home, at work, in your camper, or in your car. You can see, anywhere you are on the planet earth, when your washing machine have finished the washing cycle. You can connect to the site, you can download today the app, and begin to make your app. There is a community of enthusiast, that can give to you a precious help.

This is the code of multiprocessing

/* 30 October 2016
*  Creative Common Licence
*  Giovanni Gentile

unsigned long tempo = 0;
long scarto = 0;
int msg = 0;

void setup() {

void loop() {
tempo = millis()-scarto;
Serial.println(” second”);
if (tempo >= 10000 && msg == 0){
Serial.println(“It has passed 10 seconds”);
msg ++;
if (tempo >= 30000 && msg == 1){
Serial.println(“It has passed 30 seconds”);
msg ++;
if (tempo >= 50000 && msg == 2){
Serial.println(“It has passed 50 seconds”);
msg ++;
if (tempo >= 60000){
scarto = millis();
msg = 0;
Serial.println(“It has passed 1 minute – R E S E T”);

Nov 9, 2016 | Posted by in Arduino, Blog | 0 comments

Add Your Comment

Your email address will not be published.

Questo sito usa Akismet per ridurre lo spam. Scopri come i tuoi dati vengono elaborati.

Premium Wordpress Themes by UFO Themes