I did some major updates to the code.
Temperature and voltage is sent binary with 4-bits each. Dot = 0, Dash = 1. This equates to 0000 = 8 volts, 1111 = 15 volts and 0000 = -10c and 1111 = +30c.
Hibernation is now the normal state, each cycle is 8 seconds long(the longest the code seams to offer), after 8 seconds the Arduino wakes up, and checks if enough sleep cycles has passed(112 cycles for 15 minutes) and if the voltage is above 11v. If not, a new period of 15m sleep is initiated.
Each transmission takes about 10s at 15wpm speed.
#include <LowPower.h>
int len = 80; //set speed to 15 wpm
int sleeps = 0;
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
}
//
void loop()
{
int voltage = analogRead(A7); //init voltage ADC
//Serial.println(voltage);
if ((voltage > 382) && (sleeps > 2)) //if voltage is below 11v hybernate
{
Serial.println("sending beacon");
sendbeacon();
sleeps = 0;
}
else
{
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
sleeps++;
}
}
int dot()
{
digitalWrite(13, HIGH); //send short beep
delay(len);
digitalWrite(13, LOW); //send short beep
delay(len);
}
int dash()
{
digitalWrite(13, HIGH); //send short beep
delay(len*3);
digitalWrite(13, LOW); //send short beep
delay(len);
}
int sendbeacon()
{
int beeps = 0;
dash();
dot();
dot();
dot();
delay(len*3);
dash();
dash();
delay(len*3);
dash();
dot();
dot();
dash();
delay(len*7);
dot();
dash();
dash();
dash();
dash();
delay(len*7);
int voltage = analogRead(A7); //init voltage ADC
int myNum = (voltage - 288)/16; // 8v = 0000, 15v = 1111
int zeros = String(myNum,BIN).length();
//below is convertion to binary string from decimal integer for voltage
String myStr;
for (int i=0; i<zeros; i++)
{
myStr = myStr + "0";
}
myStr = myStr + String(myNum,BIN);
for(int i=4;i<8;i++)
{
if(myStr[i] == '1')
{
digitalWrite(13, HIGH); //send long beep = 1
delay(len*3);
digitalWrite(13, LOW);
delay(len);
}
else
{
digitalWrite(13, HIGH); //send short beep = 0
delay(len);
digitalWrite(13, LOW);
delay(len);
}
delay(len*3);
}
delay(len*7);
//Send temperature
int temp = analogRead(A6); //init voltage ADC
myNum = 17 - (temp - 124); // 0 = -10 and 16 = +30
zeros = String(myNum,BIN).length();
//below is convertion to binary string from decimal integer
for (int i=0; i<zeros; i++)
{
myStr = myStr + "0";
}
myStr = myStr + String(myNum,BIN);
for(int i=4;i<8;i++)
{
if(myStr[i] == '1')
{
digitalWrite(13, HIGH); //send long beep = 1
delay(len*3);
digitalWrite(13, LOW);
delay(len);
}
else
{
digitalWrite(13, HIGH); //send short beep = 0
delay(len);
digitalWrite(13, LOW);
delay(len);
}
delay(len*3);
}
}