Skip to content

Instantly share code, notes, and snippets.

@SebastiaanDeJonge
Created June 6, 2021 19:14
Show Gist options
  • Save SebastiaanDeJonge/b5c8d9656aaaadcef8567180c5906538 to your computer and use it in GitHub Desktop.
Save SebastiaanDeJonge/b5c8d9656aaaadcef8567180c5906538 to your computer and use it in GitHub Desktop.
arduino-super-annoyer.ino
/**
* This little projects creates random sounds through the piezo speaker. The range
* (in Hz) can be defined at the top of the code (frequencyLowerBound,
* frequencyUpperBound). The interval/duration of each tone is determined by the
* current state of the potentiometer. As the potentiometer is turned open the tone
* slows done.
*
* Requirements:
* - Arduino Nano/Uno
* - Solderless breadboard
* - Jumper wires
* - 4x LED of your favorite color
* - 4x 220 Ohm resistors
* - 100 Ohm resistor
* - Piezo speaker
* - Potentiometer
*
* Sorry, I don't have the schematics for this one anymore :)
*/
int ledWhite = 10;
int ledRed = 11;
int ledYellow = 12;
int ledBlue = 13;
int piezoPin = 9;
int potPin = 2;
int interval = 0;
int frequencyLowerBound = 100;
int frequencyUpperBound = 400;
void setup() {
pinMode(ledWhite, OUTPUT);
pinMode(ledRed, OUTPUT);
pinMode(ledYellow, OUTPUT);
pinMode(ledBlue, OUTPUT);
}
void loop() {
interval = analogRead(potPin);
if (interval > 1) {
killLeds();
tone(piezoPin, random(frequencyLowerBound, frequencyUpperBound), interval);
digitalWrite(random(10,14), HIGH);
delay(interval);
} else {
killLeds();
}
}
void killLeds()
{
digitalWrite(ledWhite, LOW);
digitalWrite(ledRed, LOW);
digitalWrite(ledYellow, LOW);
digitalWrite(ledBlue, LOW);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment