MilesP
Published

SilencePhone

A megaphone that makes loud annoying sounds when protestors are getting too loud.

BeginnerShowcase (no instructions)26
SilencePhone

Story

Read more

Schematics

Stages of Development

Code

Protest Obj Code

Arduino
#include <Adafruit_CircuitPlayground.h>

float value;
int color[] =  {255, 0, 0};

void setup() {
  Serial.begin(9600);
  CircuitPlayground.begin();
  pinMode(A2, INPUT_PULLUP);
  
}

void loop() {
  // Take 10 milliseconds of sound data to calculate
  value = CircuitPlayground.mic.soundPressureLevel(10);

  Serial.print("Sound Sensor SPL: ");
  Serial.println(value);

  if(!digitalRead(A2))
  {
    CheckVal();
  }
  
  delay(90);
}

void ColorPixels(int r, int g, int b)
{
  color[0] = r;
   color[1] = g;
   color[2] = b;
  for(int i = 0; i < 10; i++)
  {
     CircuitPlayground.setPixelColor(i, color[0],   color[1],   color[2]);
  }
}

void CheckVal()
{
  if(value < 60)
  {
    CircuitPlayground.clearPixels();
  }
  else if (value  < 70)
  {
    ColorPixels(0, 255, 0);
  }
  else if(value < 80)
  {
    ColorPixels(205, 255, 0);
  }
  else if(value < 90)
  {
    ColorPixels(255, 0, 0);
    SoundMaker(250, 250);
  }
   else if(value < 90)
  {
    ColorPixels(255, 0, 0);
    SoundMaker(100, 10);
  }
}

void SoundMaker(int freq, int noteDuration)
{
  CircuitPlayground.playTone(freq, noteDuration);
}

Credits

MilesP
3 projects • 0 followers

Comments