This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 16th, 2013  |  syntax: None  |  size: 1.17 KB  |  views: 41  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. const int analogPin = 0;
  2.  
  3. void setup() {
  4.     Serial.begin(9600);
  5. }
  6.  
  7. void loop() {
  8.     int mn = 1024; // mn only decreases
  9.     int mx = 0;    // mx only increases
  10.  
  11.     // Perform 1000 reads. Update mn and mx for each one.
  12.     for (int i = 0; i < 100; ++i) {
  13.         int val = analogRead(analogPin);
  14.         mn = min(mn, val);
  15.         mx = max(mx, val);
  16.     }
  17.  
  18.     // Send min, max and delta over Serial
  19.     Serial.print("m=");
  20.     Serial.print(mn);
  21.     Serial.print(" M=");
  22.     Serial.print(mx);
  23.     Serial.print(" D=");
  24.     Serial.print(mx-mn);
  25.     Serial.println();
  26. if((mx-mn) > 15) digitalWrite(2, HIGH);
  27. else digitalWrite(2, LOW);
  28.  
  29. if((mx-mn) > 25) digitalWrite(3, HIGH);
  30. else digitalWrite(3, LOW);
  31.  
  32. if((mx-mn) > 40) digitalWrite(4, HIGH);
  33. else digitalWrite(4, LOW);
  34.  
  35. if((mx-mn) > 100) digitalWrite(5, HIGH);
  36. else digitalWrite(5, LOW);
  37.  
  38. if((mx-mn) > 120) digitalWrite(6, HIGH);
  39. else digitalWrite(6, LOW);
  40.  
  41. if((mx-mn) > 200) {digitalWrite(7, HIGH);
  42.   digitalWrite(8, HIGH);
  43.   digitalWrite(9, HIGH);
  44.   digitalWrite(10, HIGH);
  45.   delay(1000);
  46.   digitalWrite(8, LOW);
  47.   digitalWrite(9, LOW);
  48.   digitalWrite(10, LOW);
  49.   digitalWrite(7, LOW);
  50. }
  51.  
  52.  
  53. }
clone this paste RAW Paste Data