Cricket Simulator

You would think there would be loads of these floating around, but no, people make them the hard way. So here, rescued from my original wordpress site – is my Digistump (Arduino) cricket generator (sound simulator). I figured this out back in 2014 while sitting in the sun in Spain.

If you have nothing better to do, why not take a look. You will need this library to save power in your little cricket. https://github.com/brabl2/narcoleptic

As this is a re-write of the original 2014 article in my old WordPress blog – there could be the odd error, should be easy to spot if so.

#include <Narcoleptic.h> 
int Pin1=0; int Pin2=0; 
void setup() {
pinMode(Pin1,OUTPUT); pinMode(Pin2,OUTPUT); randomSeed(analogRead(3));
analogReference(INTERNAL);
} 

void chirp() {
byte a,b,w,x,y,z;
w=random(20,22);
z=random(195,197);
for (b=5;b;b--} {
 x=1; y=z+random(1,2);
for (a=0; a<125; ++a) {
   digitalWrite(Pin1,HIGH); digitalWrite(Pin2,LOW); delayMicroseconds(x);
   delayMicroseconds(b);
   digitalWrite(Pin1,LOW); digitalWrite(Pin2,HIGH); delayMicroseconds(y);
   delayMicroseconds(b);
   x++; y--;
   if (x==100) y-=50;
  }
  delay(w);
 }
}

void(loop);
{
 int a,b,e,f;
 b=random(3,7); e=random(2000,3000);
 for (a=0;a<b;a++) {
   chirp();
   f=random(120,220);
   Narcoleptic.delay(f);
  }
}