Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // FOR PASSERBY: This code is part of a robot I'm making that will move towards
- // the direction of sound. The code below is mostly interfacing with mics, however,
- // I've added a digitalWrite of HIGH to pin 8 to test my transistor circuit for now.
- int micPin = A0;
- int sum = 0;
- int avg = 1023/2;
- int arduinoLED = 13;
- int motorPin = 8;
- void setup() {
- pinMode(arduinoLED, OUTPUT);
- Serial.begin(9600);
- analogReference(DEFAULT);
- for(int i = 0; i < 500; i++)
- {
- avg = avg + analogRead(micPin);
- avg = avg/2;
- }
- Serial.print("Average value: ");
- Serial.println(avg);
- }
- void loop() {
- digitalWrite(motorPin, HIGH); // TEST PIN HERE
- Serial.println(analogRead(micPin));
- if (analogRead(micPin) > avg*1.04)
- digitalWrite(arduinoLED, HIGH);
- else
- digitalWrite(arduinoLED, LOW);
- //delay(150);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement