uas_arduino

Serial Event Driven - Fixed

Apr 26th, 2013
32
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int maxChars = 1024;
  2. int stringPosition = 0;
  3. char myString[maxChars];
  4. int counter = 0;
  5.  
  6. void serialEvent(){
  7.   stringPosition = 0;
  8.   while(Serial.available()){
  9.     char data = (char)Serial.read();
  10.     myString[stringPosition++] = data;
  11.   }
  12.   myString[stringPosition] = '\0';
  13.  
  14.   Serial.println(counter);
  15. }
  16.  
  17. void setup(){
  18.   Serial.begin(115200);
  19. }
  20.  
  21. int divider = 0;
  22.  
  23. void loop(){
  24.   if(divider++ % 100 == 0){
  25.     counter++;
  26.   }
  27. }
RAW Paste Data