SHARE
TWEET

Untitled

a guest Aug 13th, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int xpin = A3;
  2. const int ypin = A2;
  3. const int zpin = A1;
  4.  
  5. int x = 0;
  6. int y = 0;
  7. int z = 0;
  8.  
  9. int lastx = 0;
  10. int lasty = 0;
  11. int lastz = 0;
  12.  
  13. int diffx = 0;
  14. int diffy = 0;
  15. int diffz = 0;
  16.  
  17. int piezo_pin = 11;
  18.  
  19. int flag = 0;
  20.  
  21. int limit = 20;
  22.  
  23. int total = 0;
  24.  
  25. void setup()
  26. {
  27.   Serial.begin(9600);
  28.   //tone(piezo_pin, NOTE_C4, 80);
  29.   //delay(100);
  30.   //tone(piezo_pin, NOTE_G3, 80);
  31. }
  32.  
  33.  
  34. void loop()
  35. {  
  36.  
  37.   if(flag == 0) {
  38.    
  39.   }
  40.  
  41.   if(flag == 1) {
  42.     tone(piezo_pin, NOTE_C4);
  43.   }
  44.   if(flag == 0) {
  45.     noTone(piezo_pin);
  46.   }
  47.  
  48.   x = analogRead(xpin);
  49.   diffx = abs(x - lastx);
  50.   Serial.print(diffx);
  51.   lastx = x;
  52.  
  53.   Serial.print("\t");
  54.  
  55.   //if(diffx > limit) { xalarm(); }
  56.  
  57.   y = analogRead(ypin);
  58.   diffy = abs(y - lasty);
  59.   Serial.print(diffy);
  60.   lasty = y;
  61.  
  62.   Serial.print("\t");
  63.  
  64.   //if(diffy > limit) { yalarm(); }
  65.  
  66.   z = analogRead(zpin);
  67.   diffz = abs(z - lastz);
  68.   Serial.print(diffz);
  69.   lastz = z;
  70.  
  71.   Serial.print("\t");
  72.  
  73.  
  74.   //if(diffz > limit) { zalarm(); }
  75.  
  76.   total = diffx + diffy + diffz;
  77.  
  78.   Serial.print("t: ");
  79.  
  80.   Serial.print(total);
  81.  
  82.   Serial.println();
  83.  
  84.   if(total > limit) {
  85.     flag = 1;
  86.   }
  87.  
  88.   else {
  89.     flag = 0;
  90.   }
  91.  
  92.   delay(100);
  93.  
  94. }
RAW Paste Data
Top