SHARE
TWEET

Untitled

a guest Jul 30th, 2013 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // FOR PASSERBY: This code is part of a robot I'm making that will move towards
  2. // the direction of sound. The code below is mostly interfacing with mics, however,
  3. // I've added a digitalWrite of HIGH to pin 8 to test my transistor circuit for now.
  4.  
  5. int micPin = A0;
  6. int sum = 0;
  7. int avg = 1023/2;
  8. int arduinoLED = 13;
  9. int motorPin = 8;
  10.  
  11. void setup() {
  12.   pinMode(arduinoLED, OUTPUT);
  13.   Serial.begin(9600);
  14.   analogReference(DEFAULT);
  15.   for(int i = 0; i < 500; i++)
  16.   {
  17.     avg = avg + analogRead(micPin);
  18.     avg = avg/2;
  19.   }
  20.   Serial.print("Average value: ");
  21.   Serial.println(avg);  
  22. }
  23.  
  24. void loop() {
  25.   digitalWrite(motorPin, HIGH);                         // TEST PIN HERE
  26.   Serial.println(analogRead(micPin));
  27.   if (analogRead(micPin) > avg*1.04)
  28.     digitalWrite(arduinoLED, HIGH);
  29.   else
  30.     digitalWrite(arduinoLED, LOW);
  31.  
  32.  
  33.   //delay(150);
  34.  
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top