Забавные аудио поделкиAlberto Bietti кон

Arduino ( Freeduino )
Забавные аудио поделки
Alberto Bietti конструирует забавные аудио поделки. Вот одна из них — Arduino Theremin (терменвокс Ардуино).

А теперь вернёмся к Alberto Bietti. Вот его Arduino Theremin:


Схема:






Сам код программы как видим все просто:


int pingPin = 7;

int buzzPin = 10;

int btnPin = 1;

int val;

 

void setup()

{

  pinMode(buzzPin, OUTPUT);  //set speaker pin to output

  pinMode(btnPin, INPUT);    //set pushbutton pin to input

}

 

int getPing()

{

  //send a 10us pulse to wake up the sonar

  pinMode(pingPin, OUTPUT);

  digitalWrite(pingPin, HIGH);

  delayMicroseconds(10);

  digitalWrite(pingPin, LOW);

  

  //get the raw value from the sonar, corresponding to the

  //actual time of travel of the ultrasound waves

  pinMode(pingPin, INPUT);

  return pulseIn(pingPin, HIGH);  //return this value

}

 

void loop()

{

  if (digitalRead(btnPin) == HIGH)  //only play when the button is pressed

  {

    val = getPing() / 5;  //you can tune the pitch by dividing by a different number

    

    //generate the pulse

    digitalWrite(buzzPin, HIGH);

    delayMicroseconds(val);

    digitalWrite(buzzPin, LOW);

    delayMicroseconds(val);

  }

}



Вот это как работает:
loop 10.05.2009 в 02.09 комментарии 0 0

комментарии(0)

Комментировать

Для добавления комментария авторизируйтесь.
Последние комментарии:
© 2012 pobot.ru