Skip to content

Instantly share code, notes, and snippets.

@amirhaleem
Created March 20, 2014 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirhaleem/9670999 to your computer and use it in GitHub Desktop.
Save amirhaleem/9670999 to your computer and use it in GitHub Desktop.
#include <helium.h>
#include <SPI.h>
/* Test only for springer: */
#define SPEAKERPIN 5 // speaker connected to digital pin 9
#define SPEAKERPINOPP 6 // Invert the opposite pin to make the speaker louder
void beep (float noteFrequency, long noteDuration);
HeliumModem *modem;
int count;
u32 loopCtr;
void setup(void)
{
// Configure both speaker pins
pinMode(SPEAKERPIN, OUTPUT); // sets the SPEAKERPIN to be an output
pinMode(SPEAKERPINOPP, OUTPUT); // sets the SPEAKERPIN to be an output
modem = new HeliumModem();
}
void loop (void)
{
DataUnpack *dp = modem->loop();
if (dp)
{
// Process input data
// blink LED
beep(600, 50);
// User MUST delete the dp object:
delete dp;
}
// Send stuff
/* if (loopCtr++ == 50000) */
/* { */
/* DataPack dp(1,1,1,3); */
/* dp.appendU8(33); */
/* dp.appendU16(1000); */
/* dp.appendString((char*)"sharkfed"); */
/* modem->sendPack(&dp); */
/* } */
if (loopCtr++ > 100000)
{
DataPack dp(1,1,1,3);
dp.appendU8(33);
dp.appendU16(1000);
dp.appendString((char*)"sharkfed");
modem->sendPack(&dp);
//ModemStatus *stat;
//beep(900, 40);
char msg[20];
sprintf(msg, "Arduino seq #%d", count++);
modem->sendDebugMsg(msg);
modem->sleep(1);
/* stat = modem->getStatus(); */
loopCtr = 0;
}
}
void beep (float noteFrequency, long noteDuration)
{
int x;
// Convert the frequency to microseconds
float microsecondsPerWave = 1000000/noteFrequency;
// Calculate how many HIGH/LOW cycles there are per millisecond
float millisecondsPerCycle = 1000/(microsecondsPerWave * 2);
// Multiply noteDuration * number or cycles per millisecond
float loopTime = noteDuration * millisecondsPerCycle;
// Play the note for the calculated loopTime.
for (x=0;x<loopTime;x++)
{
digitalWrite(SPEAKERPIN,HIGH);
digitalWrite(SPEAKERPINOPP,LOW);
delayMicroseconds(microsecondsPerWave);
digitalWrite(SPEAKERPIN,LOW);
digitalWrite(SPEAKERPINOPP,HIGH);
delayMicroseconds(microsecondsPerWave);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment