Here is my full slightly neater code.
I only want an sms when "stereo" and "smsmute==low"
At the moment it is ignoring the "stereo" bit.
Thanks
// libraries
#include <GSM.h>
#include <LiquidCrystal.h>
// //#include <Si4703_Breakout.h>
#include <Wire.h>
#include <TEA5767.h>
// from https://github.com/andykarpov/TEA5767
#include <Button.h>
// from http://arduino-info.wikispaces.com/HAL-LibrariesUpdates
// PIN Number
#define PINNUMBER ""
/////////////////////////////// GSM //////////////////////
// initialize the library instance
GSM gsmAccess; // include a 'true' parameter to enable debugging
GSM_SMS sms;
GSMVoiceCall vcs;
// Array to hold the number for the incoming call
char numtel[20];
////////////////////////////// TEA5767 /////////////////////
TEA5767 Radio;
double old_frequency;
double frequency;
int search_mode = 0;
int search_direction;
unsigned long last_pressed;
///////////////////////////// LCD //////////////////////////
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 9, 8);
// This section descibes button connection.
const int buttonPin = A0;
const int upbuttPin = A2;
const int downbuttPin = A3;
const int selectPin = A1;
const int smsmutePin = 6;
///////////freq map//////////////////////
float Freq[][5] ={
{
99.5, 89.9 , 91.4, 104.7, 93.6 }
,//Aberdare
{
98.3 , 88.7, 90.9, 93.1, 103.5 }
,//Abergavenny
{
99.5 , 89.9, 92.1, 94.3, 101.7 }
,//Wenvoe
{
98.6 , 89.0, 91.2, 93.4, 104.3 }
,//Abertillery
{
98.1 , 88.5, 90.7, 92.9, 104.0 }
,//Blaenavon
{
98.5 , 88.9, 91.1, 104.7, 93.3 }
,//Brecon
{
98.0 , 88.4, 90.6, 104.6, 92.8 }
,//Carmel
{
89.5 , 91.7, 93.9, 96.4, 0 }
,//kvh
{
89.5 , 91.7, 93.9, 96.4, 0 }
,//kvh
{
89.5 , 91.7, 93.9, 96.4, 0 }
,//kvh
{
89.5 , 91.7, 93.9, 96.4, 0 }
,//kvh
{
89.5 , 91.7, 93.9, 96.4, 0 }
,//kvh
};
const int NUM_FREQS = sizeof Freq[0]/sizeof Freq[0][0];
// variables will change:
int buttonState = 0;
int upbuttState = 0;
int downbuttState = 0;
int selectbuttState = 0;
int smsmuteState = 0;
int select = 0;
float channel;
// Save data variables
String IMEI = "";
// serial monitor result messages
String errortext = "ERROR";
///////////////////////// NAME INDEX ////////////////////////////////
char * Names[] = {
"Aberdare ", "Abergavenny ", "Wenvoe", "Abertillery", "Blaenavon", "Brecon", "Carmel" };
const int NAME_COUNT = sizeof Names / sizeof Names[0];
int NameIndex = 0;
void setup()
{
{
Wire.begin();
Radio.init();
//Radio.set_frequency(99.5);
}
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
pinMode(upbuttPin, INPUT);
pinMode(downbuttPin, INPUT);
pinMode(selectPin, INPUT);
pinMode(smsmutePin, INPUT);
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("Receive Voice Call");
/////////////////////// LCD BOOT turn on display? ////////////////////
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("FM Rover by DM");
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("--Please Wait--");
lcd.setCursor(0, 1);
lcd.print("-GSM Connecting-");
//////////////////////// START GSM networks scanner/////////////////////////
// scannerNetworks.begin();
// connection state
boolean notConnected = true;
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while(notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
{
notConnected = false;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" GSM Connected");
delay(5000);
lcd.clear();
}
else
{
Serial.println("Not connected !");
lcd.setCursor(0, 1);
lcd.clear();
lcd.print("NO GSM !");
delay(1000);
}
}
vcs.hangCall();
Serial.println("Waiting for a call");
///////////////// SELECT SITE NAME //////////////////////
while(select==0){
// read the state of the pushbutton value:
upbuttState = digitalRead(upbuttPin);
downbuttState = digitalRead(downbuttPin);
selectbuttState = digitalRead(selectPin);
// if it is, the upbuttState is HIGH:
if (upbuttState == HIGH) {
// increment name
NameIndex = (NameIndex+1)%NAME_COUNT;
} // Wrap around
//if it is, the upbuttState is HIGH:
if (downbuttState == HIGH) {
// increment name
NameIndex = (NameIndex-1)%NAME_COUNT;
if (NameIndex < 0) {
NameIndex=NAME_COUNT-1;
}
} // Wrap around
if (selectbuttState == HIGH){
select=1;
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print("> ");
lcd.setCursor(2,0);
lcd.print (Names[NameIndex]);
lcd.setCursor(0,1);
lcd.print("Select Location ");
delay(500);
lcd.clear();
}
}
void loop()
{
{
{
unsigned char buf[5];
int stereo;
int signal_level;
double current_freq;
unsigned long current_millis = millis();
for(int i=0; i<NUM_FREQS; i++) {
channel=Freq[NameIndex][i];
Radio.set_frequency(channel);
lcd.setCursor(0, 0);
smsmuteState = digitalRead(smsmutePin);
lcd.setCursor(0, 1);
lcd.print(Names[NameIndex]);
delay(10000);
if (Radio.read_status(buf) == 1) {
current_freq = floor (Radio.frequency_available (buf) / 100000 + .5) / 10;
stereo = Radio.stereo(buf);
signal_level = Radio.signal_level(buf);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(current_freq);
lcd.setCursor(6,0);
lcd.print("MHz");
lcd.setCursor(13,0);
if (stereo) lcd.print(" ST ");
else lcd.print(" MO");
lcd.setCursor(10,0);
lcd.print(signal_level * 100 / 16);
lcd.setCursor(12,0);
lcd.print("%");
//}
delay(1000);
if((stereo)&&(smsmuteState == HIGH))
{
}
else
lcd.clear();
lcd.setCursor(0,1);
lcd.print("");
if (smsmuteState == LOW)
{
sms.beginSMS("phone number");
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("----- FAULT ------");
delay(1000);
lcd.clear();
lcd.print("SMS SENDING");
sms.print("\xFEgmail.com ");
sms.print(Names[NameIndex]);
sms.print(" ");
sms.print(channel);
sms.print(" SHUT DOWN");
sms.endSMS();
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("SMS SENT OK");
delay(5000);
lcd.clear();
}
if (smsmuteState == HIGH)
lcd.setCursor(14, 1);
lcd.print("M!");
delay(5000);
lcd.clear();
}
}
}
}
}