level inducator

View previous topic View next topic Go down

level inducator

Post by jupi on Thu Apr 28, 2016 2:04 pm

Hi,
I just want to see how a level indicator works.
The id of the indicator is "versuch"  (without "").

Please write me/ insert a codeline in the folloeing sketch so it works.
Many thanks for help
JU

#define bluetooth Serial
char cmd[100];
int cmdIndex;

void exeCmd() {
 //if(strcmp(cmd, "some cmd")==0) doSomething();
}

void setup() {
 delay(500); // wait for BlueSMiRF to start
 Serial.begin(9600);    
 bluetooth.begin(9600); // BlueSMiRF default baud is 115200
 cmdIndex = 0;
}

void loop() {
 
 if(bluetooth.available()) {    
   char c = (char)bluetooth.read();
   
   if(c=='\n') {
     cmd[cmdIndex] = 0;
     exeCmd();  // execute the command
     cmdIndex = 0; // reset the cmdIndex
   } else {      
     cmd[cmdIndex] = c;
     if(cmdIndex<99) cmdIndex++;
   }  
 }
  // String st= ("versuch" + "\n");
   bluetooth.print("versuch  0  \n");
   delay(1000);

}

jupi

Posts : 2
Join date : 2016-04-28

View user profile

Back to top Go down

Re: level inducator

Post by Admin on Fri May 06, 2016 2:37 pm

Hi, here is the code:

Code:

char cmd[100];
int cmdIndex;

long t1=0, t2=0;
int levelIndicatorValue=0;

void exeCmd() {
 //if(strcmp(cmd, "some cmd")==0) doSomething();
}

void setup() {
 delay(500); // wait for BlueSMiRF to start
 Serial.begin(9600); // BlueSMiRF default baud is 115200
 cmdIndex = 0;
}


void loop() {
 
 if(Serial.available()) {    
   char c = (char)Serial.read();
  
   if(c=='\n') {
     cmd[cmdIndex] = 0;
     exeCmd();  // execute the command
     cmdIndex = 0; // reset the cmdIndex
   } else {      
     cmd[cmdIndex] = c;
     if(cmdIndex<99) cmdIndex++;
   }  
 }

 t2 = millis();
 if(t2 > t1+50) { // every 50 ms
   t1 = t2;
   Serial.print((String)"versuch " + levelIndicatorValue + "\n"); // 0 to 49
   levelIndicatorValue++;
   if(levelIndicatorValue==50) {
      levelIndicatorValue = 0;
   }
 }

 // DO NOT ADD DELAY HERE
 // (RECEIVING COMMANDS WILL STOP WORKING)
}

Admin
Admin

Posts : 111
Join date : 2016-03-08

View user profile http://roboremo.makeforum.net

Back to top Go down

Re: level inducator

Post by jupi on Sun May 08, 2016 11:34 pm

Thank You

jupi

Posts : 2
Join date : 2016-04-28

View user profile

Back to top Go down

Re: level inducator

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum