Switch statt multiple loops?


hallo,
ich schreibe grad einer steuerung für mein zimmer mit relaisschaltungen, sensoren, usw. das problem ist, wie kann ich quasi gleichzeitig die gui und den rest ausführen? erstmal gegooglet und auf diese seite gestoßen(http://arduino.cc/en/tutorial/multipleblinks). soweit ich das verstanden habe, muss man delays einbauen, damit auch sichergestellt wird, dass alle schleifen auch wirklich laufen.
dann ein paar stunden später beim müsli machen komme ich auf die idee stattdessen switch-befehle zu verwenden, wie in dem beispiel unten. meine frage nun, haltet ihr davon? gibt es irgendwelche no-goes, die ich begangen habe? ich bin leider nicht der c-profi.

mit multiple loops(scheduler.h)
code: [select]
#include utouch
#include scheduler

int x, y;
utouch touch(6,5,4,3,2);

void setup(){}


void loop(){  
    senddata();
    while(!serial.available()){
      delay(10);
    }
    char c = serial.getdata();
}

void loop2(){
    receivedata();
    while(!touch.dataavailable()){
      delay(10);
    }
    x= utouch.getx();
    y= utouch.gety();
 
}

void senddata(){}
void receivedata(){}


mit switch
code: [select]
#include utouch

int loop1=0;
int loop2=0;
int x, y;
utouch touch(6,5,4,3,2);

void setup(){}


void loop(){
 
 switch(loop1){
  case 0:
    senddata();
    loop1++;
  case 1:
    while(!serial.available()){
     break;
    }
   loop1++;
  case 2:
    char c = serial.available();
    loop1=0;
    break;
  deafult:
    loop2=0;
 }
 
 switch(loop2){
    case 0:
    receivedata();
    loop2++;
  case 1:
    while(!touch.dataavailable()){
     break;
    }
   loop2++;
  case 2:
    x= utouch.getx();
    y= utouch.gety();
    loop2=0;
    break;
  deafult:
    loop2=0;
 }
}

void senddata(){}
void receivedata(){}

delay = böse  ]:d

ich habe noch nicht rumrissen, worum es dir tatsächlich geht. kannste das nochmal verdeutlichen?


Arduino Forum > International > Deutsch (Moderator: uwefed) > Switch statt multiple loops?


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support