BTW here is my code, a bit long but maybe someone can have a look at it:
//******************************* INITIALIZATION *******************************
//******************************************************************************
//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266_SoftSer.h>
#include <BlynkSimpleShieldEsp8266_SoftSer.h>
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
ESP8266 wifi(EspSerial);
char auth[] = "";
#include <LiquidCrystal.h>
#include <math.h>
#define IN_FWD A0 // analog input for left channel
#define IN_REFL A1 // analog input for right channel
#define T_PEAKHOLD 1000 // msec peak hold time before return
#define T_pepHOLD 500 // msec pep hold time before return
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
byte fill[6]={ 0x20,0x00,0x01,0x02,0x03,0xFF }; // character used to fill (0=empty 5=full)
byte peak[7]={ 0x20,0x00,0x04,0x05,0x06,0x07,0x20 }; // character used to peak indicator
int lmax[5]; // level max memory
int dly[5]; // delay & speed for peak return
long lastT = 0;
long lastT1=0; // update display timer1
long lastT2=0; // update display timer2
long lastTpep = 0; // update PEP display
int anF = 0; // analog read forward power
int anR = 0; // analog read reflected power
int T_REFRESH1; // msec bargraph refresh rate
unsigned long pow_fwd = 0; // power forward (watts)
unsigned long pow_ref = 0; // power reflected (watts)
unsigned int pow_fwd_max = 0; // power forward max (for peak hold)
unsigned int pow_ref_max = 0; // power reflected max (for peak hold)
byte lcdNumCols = 16; // -- number of columns in the LCD
//const int Pin_Backlight = 13;
const int Pin_Mode_Button_Type = 5;
const int Pin_Mode_Button_Band = 4;
//const int Pin_Mode_Button_Unit = 3;
//const int Pin_Mode_Button_Mode = 2;
const int Pin_Mode_Button_Resolution = 1;
int buttonPushCounter_Type = 0;
int buttonPushCounter_Band = 0;
int buttonPushCounter_Unit = 0;
int buttonPushCounter_Mode = 0;
int buttonPushCounter_Resolution = 0;
int buttonState_Type = 0;
int buttonState_Band = 0;
int buttonState_Unit = 0;
int buttonState_Mode = 0;
int buttonState_Resolution = 0;
int lastButtonState_Type = 0;
int lastButtonState_Band = 0;
int lastButtonState_Unit = 0;
int lastButtonState_Mode = 0;
int lastButtonState_Resolution = 0;
float Value = 0.0;
int Analog_Input_Port_FWD = 0;
int Analog_Input_Port_REF = 1;
int Battery_Input_Port = 5;
float Voltage = 0.0;
float VoltageREF = 0.0;
float Power_dBm = 0.0;
float Power_dBm_REF = 0.0;
float Power_mW = 0.0;
float Power_mW_REF=0.0;
float Power_W = 0;
float Power_W_peak=0.0;
float Power_W_REF=0.0;
float SWR = 0;
float SWR_ratio = 0;
int SWRDis = 0;
float SWR_FWD = 0.0;
float SWR_REF = 0.0;
float Battery = 0.0;
float Batt = 0.0;
const float Coupling_Coeff_HF = 0;
/*
const float Coupling_Coeff_HF = 48;
const float Coupling_Coeff_6m = 57.5;
const float Coupling_Coeff_4m = 54.7;
const float Coupling_Coeff_2m = 48.5;
const float Coupling_Coeff_70cm = 39.2;
*/
unsigned long BacklightTime = 0;
byte block[8][8] =
{
{ 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 }, // define character for fill the bar
{ 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 },
{ 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C },
{ 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E },
{ 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }, // define character for peak level
{ 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04 },
{ 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 },
{ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
};
//******************************************************************************
//******************************* SETUP ****************************************
//******************************************************************************
void setup() {
Serial.begin(115200);
// Set ESP8266 baud rate
// 9600 is recommended for Software Serial
EspSerial.begin(9600);
delay(100);
Blynk.begin(auth, wifi, "Freebox-CQ..CQ..CQ", "");
delay(50);
lcd.begin (16, 4);
for ( int i = 0 ; i < 8 ; i++ )
lcd.createChar( i, block[i] );
lcd.clear();
// pinMode(Pin_Backlight, OUTPUT);
lcd.setCursor(0,0);
lcd.print("SWR POWER meter");
lcd.setCursor(0,1);
lcd.print(" by ");
lcd.setCursor(0,2);
lcd.print("");
lcd.setCursor(0,3);
lcd.print("F4VPX-F4AJS V1.5");
delay(1000);
lcd.clear();
//delay (500);
pinMode(Pin_Mode_Button_Type, INPUT);
pinMode(Pin_Mode_Button_Band, INPUT);
//pinMode(Pin_Mode_Button_Unit, INPUT);
//pinMode(Pin_Mode_Button_Mode, INPUT);
//pinMode(Pin_Mode_Button_Resolution, INPUT);
}
//******************************************************************************
//******************************* LOOP *****************************************
//******************************************************************************
void loop() {
//BUTTON 1 MODE ---------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
buttonState_Type = digitalRead(Pin_Mode_Button_Type);
if (buttonState_Type != lastButtonState_Type) {
if (buttonState_Type == HIGH) {
buttonPushCounter_Type++;
}
lcd.clear();
}
lastButtonState_Type = buttonState_Type;
if (buttonPushCounter_Type == 5) {
buttonPushCounter_Type = 0;
lcd.clear();
}
buttonState_Type = digitalRead(Pin_Mode_Button_Type);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState_Type == LOW) {
// turn LED on:
// digitalWrite(Pin_Backlight, HIGH);
BacklightTime = millis ();
}
else if (((millis() - BacklightTime) > 60000)) {
// turn LED off:
// digitalWrite(Pin_Backlight, LOW);
}
//BUTTON 2 W dBm mW ---------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
buttonState_Band = digitalRead(Pin_Mode_Button_Band);
if (buttonState_Band != lastButtonState_Band) {
if (buttonState_Band == HIGH) {
buttonPushCounter_Band = buttonPushCounter_Band + 10;
}
lcd.clear();
}
lastButtonState_Band = buttonState_Band;
if (buttonPushCounter_Band == 30) {
buttonPushCounter_Band = 0;
lcd.clear();
}
buttonState_Band = digitalRead(Pin_Mode_Button_Band);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState_Band == LOW) {
// turn LED on:
//digitalWrite(Pin_Backlight, HIGH);
BacklightTime = millis ();
}
else if (((millis() - BacklightTime) > 60000)) {
// turn LED off:
//digitalWrite(Pin_Backlight, LOW);
}
/*
//BUTTON 3 UNITS, dBm, mW, W ---------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
buttonState_Unit = digitalRead(Pin_Mode_Button_Unit);
if (buttonState_Unit != lastButtonState_Unit) {
if (buttonState_Unit == HIGH) {
buttonPushCounter_Unit = buttonPushCounter_Unit + 100;
}
lcd.clear();
}
lastButtonState_Unit = buttonState_Unit;
if (buttonPushCounter_Unit == 400) {
buttonPushCounter_Unit = 100;
}
buttonState_Unit = digitalRead(Pin_Mode_Button_Unit);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState_Unit == LOW) {
// turn LED on:
digitalWrite(Pin_Backlight, HIGH);
BacklightTime = millis ();
}
else if (((millis() - BacklightTime) > 60000)) {
// turn LED off:
digitalWrite(Pin_Backlight, LOW);
}
*/
unsigned int value = 0;
float a = 0.0;
int i = 0;
switch(buttonPushCounter_Type+buttonPushCounter_Band+buttonPushCounter_Unit)
{
case 0:
Calculation_Power_dBm();
Power_dBm=Power_dBm+Coupling_Coeff_HF;
Conversion_dBm_to_W();
Calculation_SWR();
T_REFRESH1 = 45;
graph_W(T_REFRESH1);
lcd.setCursor(0,1);
lcd.print( "FWD");
lcd.setCursor(8,1);
lcd.print( "W");
lcd.setCursor(0,3);
lcd.print( "REF");
lcd.setCursor(8,3);
lcd.print( "W");
if(pow_fwd == 0 || (pow_ref > pow_fwd ))
{
lcd.setCursor(13,2);
lcd.print("swr");
lcd.setCursor(12,3);
lcd.print("-.--");
}
else{
lcd.setCursor(13,2);
lcd.print( "swr");
lcd.setCursor(12,3);
lcd.print(SWR);
}
lcd.setCursor(4,1);
lcd.print(" ");
lcd.setCursor(4,1);
lcd.print(pow_fwd_max);
lcd.setCursor(4,3);
lcd.print(" ");
lcd.setCursor(4,3);
lcd.print(pow_ref_max);
break;
case 1:
lcd.setCursor(0,1);
lcd.print("PWR ");
lcd.setCursor(4,1);
break;
case 11:
lcd.setCursor(0,1);
lcd.print("PWR ");
lcd.setCursor(4,1);
break;
case 21:
lcd.setCursor(0,1);
lcd.print("PWR ");
lcd.setCursor(4,1);
break;
case 2:
Calculation_Voltage();
Calculation_Voltage_REF();
lcd.setCursor(0,0);
lcd.write("AD8307 Voltage ");
lcd.setCursor(0,1);
lcd.print("Fwd: ");
lcd.print(Voltage,4);
lcd.print(" V");
lcd.setCursor(0,2);
lcd.print("Rev: ");
lcd.print(VoltageREF,4);
lcd.print(" V");
delay(50);
break;
case 12:
Calculation_Voltage();
Calculation_Voltage_REF();
lcd.setCursor(0,0);
lcd.write("AD8307 Voltage ");
lcd.setCursor(0,1);
lcd.print("Fwd: ");
lcd.print(Voltage,4);
lcd.print(" V");
lcd.setCursor(0,2);
lcd.print("Rev: ");
lcd.print(VoltageREF,4);
lcd.print(" V");
delay(50);
break;
case 22:
Calculation_Voltage();
Calculation_Voltage_REF();
lcd.setCursor(0,0);
lcd.write("AD8307 Voltage ");
lcd.setCursor(0,1);
lcd.print("Fwd: ");
lcd.print(Voltage,4);
lcd.print(" V");
lcd.setCursor(0,2);
lcd.print("Rev: ");
lcd.print(VoltageREF,4);
lcd.print(" V");
delay(50);
break;
case 3:
Calculation_Battery();
lcd.setCursor(0,0);
lcd.print("Input Voltage :");
lcd.setCursor(5,1);
lcd.print(Batt,2);
lcd.setCursor(10,1);
lcd.print("V");
delay(50);
break;
case 13:
Calculation_Battery();
lcd.setCursor(0,0);
lcd.print("Input Voltage :");
lcd.setCursor(5,1);
lcd.print(Batt,2);
lcd.setCursor(10,1);
lcd.print("V");
delay(50);
break;
case 23:
Calculation_Battery();
lcd.setCursor(0,0);
lcd.print("Input Voltage :");
lcd.setCursor(5,1);
lcd.print(Batt,2);
lcd.setCursor(10,1);
lcd.print("V");
delay(50);
break;
case 4:
Calculation_SWR();
lcd.setCursor(0,0);
lcd.print("SWR Calc : ");
if (SWR > 3) {
lcd.setCursor(0,1);
lcd.print("SWR > 3 !");
}
else{
lcd.setCursor(0,1);
lcd.print(SWR);
lcd.print(" ");
}
delay(50);
break;
case 14:
Calculation_SWR();
lcd.setCursor(0,0);
lcd.print("SWR Calc : ");
if (SWR > 3) {
lcd.setCursor(0,1);
lcd.print("SWR > 3 !");
}
else{
lcd.setCursor(0,1);
lcd.print(SWR);
lcd.print(" ");
}
delay(50);
break;
case 24:
Calculation_SWR();
lcd.setCursor(0,0);
lcd.print("SWR Calc : ");
if (SWR > 3) {
lcd.setCursor(0,1);
lcd.print("SWR > 3 !");
}
else{
lcd.setCursor(0,1);
lcd.print(SWR);
lcd.print(" ");
}
delay(50);
break;
/*
case 1:// W 25ms
//Serial.println(buttonPushCounter_Type+buttonPushCounter_Band+buttonPushCounter_Unit);
WATT();
T_REFRESH = 25;
showbar(T_REFRESH);
lcd.setCursor(12, 1);
lcd.print("25ms ");
lcd.setCursor(4, 1);
lcd.print(Power_W,0);
lcd.setCursor(8, 1);
lcd.print("W");
break;
*/
/*
case 11:// W 25ms
Calculation_Power_dBm();
Power_dBm=Power_dBm+Coupling_Coeff_HF;
Conversion_dBm_to_W();
lcd.setCursor(12, 1);
lcd.print("25ms");
lcd.setCursor(4, 1);
lcd.print(" ");
lcd.setCursor(4, 1);
lcd.print(Power_W,0);
lcd.setCursor(8, 1);
lcd.print("W ");
break;
case 21:// W 50ms
Calculation_Power_dBm();
Power_dBm=Power_dBm+Coupling_Coeff_HF;
Conversion_dBm_to_W();
T_REFRESH = 25;
showbar(T_REFRESH);
lcd.setCursor(12, 1);
lcd.print("50ms ");
lcd.setCursor(4, 1);
lcd.print(Power_W,0);
lcd.setCursor(8, 1);
lcd.print("W");
break;
case 31:// W 75ms
Calculation_Power_dBm();
Power_dBm=Power_dBm+Coupling_Coeff_HF;
Conversion_dBm_to_W();
T_REFRESH = 25;
showbar(T_REFRESH);
lcd.setCursor(12, 1);
lcd.print("75ms ");
lcd.setCursor(4, 1);
lcd.print(Power_W,0);
lcd.setCursor(8, 1);
lcd.print("W");
break;
case 41:// W 100ms
Calculation_Power_dBm();
Power_dBm=Power_dBm+Coupling_Coeff_HF;
Conversion_dBm_to_W();
T_REFRESH = 25;
showbar(T_REFRESH);
lcd.setCursor(11, 1);
lcd.print("100ms ");
lcd.setCursor(4, 1);
lcd.print(Power_W,0);
lcd.setCursor(8, 1);
lcd.print("W");
break;
case 101:// W 25ms
Calculation_Power_dBm();
Power_dBm=Power_dBm+Coupling_Coeff_HF;
Conversion_dBm_to_W();
T_REFRESH = 25;
showbar(T_REFRESH);
lcd.setCursor(12, 1);
lcd.print("25ms");
lcd.setCursor(4, 1);
lcd.print(Power_W,0);
lcd.setCursor(8, 1);
lcd.print("W");
break;
*/
case 10:// dBm
Calculation_Power_dBm();
Power_dBm=Power_dBm+Coupling_Coeff_HF;
Conversion_dBm_to_W();
Calculation_SWR();
T_REFRESH1 = 45;
graph_dBm(T_REFRESH1);
lcd.setCursor(0,1);
lcd.print( "FWD");
lcd.setCursor(0,3);
lcd.print( "REF");
if(Power_dBm == -75 || (Power_dBm_REF > Power_dBm ))
{
lcd.setCursor(13,2);
lcd.print( "swr");
lcd.setCursor(12,3);
lcd.print("-.--");
}
else{
lcd.setCursor(13,2);
lcd.print( "swr");
lcd.setCursor(12,3);
lcd.print(SWR);
}
//lcd.setCursor(12,1);
//lcd.print("25ms");
lcd.setCursor(9,1);
lcd.print("dBm");
lcd.setCursor(4,1);
lcd.print(" ");
lcd.setCursor(4,1);
lcd.print(Power_dBm,1);
lcd.setCursor(9,3);
lcd.print("dBm");
lcd.setCursor(4,3);
lcd.print(" ");
lcd.setCursor(4,3);
lcd.print(Power_dBm_REF,1);
break;
case 20:// mW
Calculation_Power_dBm();
Power_dBm=Power_dBm+Coupling_Coeff_HF;
Conversion_dBm_to_mW();
Calculation_SWR();
if(Power_mW >= 9999)
{
lcd.setCursor(0,0);
lcd.print( " ");
lcd.setCursor(0,0);
lcd.print( " PWR > 9999mW ");
lcd.setCursor(0,2);
lcd.print( " ");
lcd.setCursor(0,3);
lcd.print( " ");
lcd.setCursor(0,1);
lcd.print( "Pse CHANGE SCALE ");
}
else {
T_REFRESH1 = 45;
graph_mW(T_REFRESH1);
lcd.setCursor(0,1);
lcd.print( " ");
lcd.setCursor(0,1);
lcd.print( "FWD");
lcd.setCursor(0,3);
lcd.print( "REF");
//lcd.setCursor(12,1);
//lcd.print("25ms");
lcd.setCursor(10,1);
lcd.print("mW");
//lcd.setCursor(4,1);
//lcd.print(" ");
lcd.setCursor(4,1);
lcd.print(Power_mW,1);
lcd.setCursor(9,3);
lcd.print("mW");
lcd.setCursor(4,3);
lcd.print(" ");
lcd.setCursor(4,3);
lcd.print(Power_mW_REF,1);
if(pow_fwd == 0 || (pow_ref > pow_fwd ))
{
lcd.setCursor(13,2);
lcd.print( "swr");
lcd.setCursor(12,3);
lcd.print("-.--");
}
else{
lcd.setCursor(13,2);
lcd.print( "swr");
lcd.setCursor(12,3);
lcd.print(SWR);
}
}
break;
/*
case 301:// mW 25ms
//Serial.println(buttonPushCounter_Type+buttonPushCounter_Band+buttonPushCounter_Unit);
T_REFRESH = 25;
showbar(T_REFRESH);
Conversion_W_to_mW();
lcd.setCursor(12, 1);
lcd.print("25ms");
lcd.setCursor(4, 1);
lcd.print(Power_mW,1);
lcd.print(" ");
lcd.setCursor(8, 1);
lcd.print("mW");
break;
case 111:// W 25ms
Calculation_Power_dBm();
Power_dBm=Power_dBm+Coupling_Coeff_HF;
Conversion_dBm_to_W();
T_REFRESH = 25;
showbar(T_REFRESH);
lcd.setCursor(12, 1);
lcd.print("25ms ");
lcd.setCursor(4, 1);
lcd.print(Power_W,0);
lcd.setCursor(8, 1);
lcd.print("W");
break;
case 121:// W 50ms
Calculation_Power_dBm();
Power_dBm=Power_dBm+Coupling_Coeff_HF;
Conversion_dBm_to_W();
T_REFRESH = 50;
showbar(T_REFRESH);
lcd.setCursor(12, 1);
lcd.print("50ms ");
lcd.setCursor(4, 1);
lcd.print(Power_W,0);
lcd.setCursor(8, 1);
lcd.print("W");
break;
case 131:// W 75ms
Calculation_Power_dBm();
Power_dBm=Power_dBm+Coupling_Coeff_HF;
Conversion_dBm_to_W();
T_REFRESH = 75;
showbar(T_REFRESH);
lcd.setCursor(12, 1);
lcd.print("75ms ");
lcd.setCursor(4, 1);
lcd.print(Power_W,0);
lcd.setCursor(8, 1);
lcd.print("W");
break;
case 141:// W 100ms
Calculation_Power_dBm();
Power_dBm=Power_dBm+Coupling_Coeff_HF;
Conversion_dBm_to_W();
T_REFRESH = 100;
showbar(T_REFRESH);
lcd.setCursor(11, 1);
lcd.print("100ms ");
lcd.setCursor(4, 1);
lcd.print(Power_W,0);
lcd.setCursor(8, 1);
lcd.print("W");
break;
case 211:// dBm 25ms
T_REFRESH = 25;
showbar(T_REFRESH);
Conversion_W_to_dBm();
lcd.setCursor(4, 1);
lcd.print(Power_dBm);
lcd.setCursor(8, 1);
lcd.print("dBm");
lcd.setCursor(12, 1);
lcd.print("25ms ");
break;
case 221:// dBm 50ms
T_REFRESH = 50;
showbar(T_REFRESH);
Calculation_Power_dBm();
Power_dBm=Power_dBm+Coupling_Coeff_HF;
lcd.setCursor(4, 1);
lcd.print(Power_dBm);
lcd.setCursor(8, 1);
lcd.print("dBm");
lcd.setCursor(12, 1);
lcd.print("50ms ");
break;
case 231:// dBm 75ms
T_REFRESH = 75;
showbar(T_REFRESH);
Calculation_Power_dBm();
Power_dBm=Power_dBm+Coupling_Coeff_HF;
lcd.setCursor(4, 1);
lcd.print(Power_dBm);
lcd.setCursor(8, 1);
lcd.print("dBm");
lcd.setCursor(12, 1);
lcd.print("75ms ");
break;
case 241:// dBm 100ms
T_REFRESH = 100;
showbar(T_REFRESH);
Calculation_Power_dBm();
Power_dBm=Power_dBm+Coupling_Coeff_HF;
lcd.setCursor(4, 1);
lcd.print(Power_dBm);
lcd.setCursor(8, 1);
lcd.print("dBm");
lcd.setCursor(11, 1);
lcd.print("100ms ");
break;
*/
/*
case 311:// mW 25ms
Calculation_Power_dBm();
Power_dBm=Power_dBm+Coupling_Coeff_HF;
Conversion_dBm_to_mW();
lcd.setCursor(4, 1);
lcd.print(Power_mW,1);
lcd.print(" ");
lcd.setCursor(11, 1);
lcd.print("mW");
lcd.setCursor(12, 2);
lcd.print("25ms");
break;
*/
/*
case 321:// mW 50ms
T_REFRESH = 50;
showbar(T_REFRESH);
Conversion_W_to_mW();
lcd.setCursor(4, 1);
lcd.print(Power_mW,1);
lcd.print(" ");
lcd.setCursor(8, 1);
lcd.print("mW");
lcd.setCursor(12, 1);
lcd.print("50ms ");
break;
case 331:// mW 75ms
T_REFRESH = 75;
showbar(T_REFRESH);
Conversion_W_to_mW();
lcd.setCursor(4, 1);
lcd.print(Power_mW,1);
lcd.print(" ");
lcd.setCursor(8, 1);
lcd.print("mW");
lcd.setCursor(12, 1);
lcd.print("75ms ");
break;
case 341:// mW 100ms
T_REFRESH = 100;
showbar(T_REFRESH);
Conversion_W_to_mW();
lcd.setCursor(4, 1);
lcd.print(Power_mW,1);
lcd.print(" ");
lcd.setCursor(8, 1);
lcd.print("mW");
lcd.setCursor(11, 1);
lcd.print("100ms ");
break;
*/
}
Blynk.run();
}
//******************************************************************************
//******************************* SUB-ROUTINES *********************************
//******************************************************************************
void Calculation_Voltage() {
Value = analogRead(Analog_Input_Port_FWD);
//Serial.print("ANALOG A0 ");
//Serial.println(analogRead(Analog_Input_Port_FWD));
Voltage = (Value * 5.0) / 1024;
//Serial.print("VOLTAGE ");
//Serial.println(Voltage);
}
void Calculation_Voltage_REF() {
Value = analogRead(Analog_Input_Port_REF);
VoltageREF = (Value * 5.0) / 1024;
}
void Calculation_Power_dBm() {
Calculation_Voltage();
Calculation_Voltage_REF();
Power_dBm = (Voltage - 2.355) / 0.025;
Power_dBm_REF = (VoltageREF - 2.355) / 0.025;
//Serial.print("Power_dBm ");
//Serial.println(Power_dBm);
}
void Conversion_dBm_to_mW() {
Power_mW = (pow(10, (Power_dBm / 10)));
Power_mW_REF = (pow(10, (Power_dBm_REF / 10)));
}
void Conversion_dBm_to_W() {
Power_W = (pow(10, (Power_dBm / 10))) / 1000;
Power_W_REF = (pow(10, (Power_dBm_REF / 10))) / 1000;
}
void Calculation_Battery() {
Battery = analogRead(Battery_Input_Port);
Batt = (((Battery * 5.00) / 1024.0));
}
void Calculation_SWR() {
Calculation_Voltage();
Calculation_Voltage_REF();
SWR_FWD = Voltage;
SWR_REF = VoltageREF;
SWR_ratio = pow_fwd_max / pow_ref_max;
SWR = abs ((1 + sqrt(SWR_ratio)) / (1 - sqrt(SWR_ratio))) ;
}
void graph_W (int T_REFRESH1)
{
//if (( millis()<lastT1 ) and (FirstLoop == 0)) return;
//lastT1 = millis() + T_REFRESH1;
pow_fwd = Power_W;
pow_ref = Power_W_REF;
anF = map( pow_fwd,0,2500,0,80 ); // 80 = 16 x 5 colums, full scale 2000w
anR = map( pow_ref,0,300,0,60 ); // 80 = 16 x 5 colums, full scale 125 w
bar( 0,anF,T_REFRESH1 );
barREF( 2,anR,T_REFRESH1 );
// update PEP¨meter ?
if (pow_fwd >= pow_fwd_max) { // we have a peak !
lastTpep = millis();
pow_fwd_max = pow_fwd;
pow_ref_max = pow_ref;
}
if (millis() > (lastTpep + T_pepHOLD)) { // clear the peak after hold time
pow_fwd_max = pow_fwd;
pow_ref_max = pow_ref;
}
}
void graph_mW (int T_REFRESH1)
{
//if (( millis()<lastT1 ) and (FirstLoop == 0)) return;
//lastT1 = millis() + T_REFRESH1;
pow_fwd = Power_mW;
pow_ref = Power_mW_REF;
anF = map( pow_fwd,0,9999,0,80 ); // 80 = 16 x 5 colums, full scale 2000w
anR = map( pow_ref,0,300,0,60 ); // 80 = 16 x 5 colums, full scale 125 w
bar( 0,anF,T_REFRESH1 );
barREF( 2,anR,T_REFRESH1 );
// update PEP¨meter ?
if (pow_fwd >= pow_fwd_max) { // we have a peak !
lastTpep = millis();
pow_fwd_max = pow_fwd;
pow_ref_max = pow_ref;
}
if (millis() > (lastTpep + T_pepHOLD)) { // clear the peak after hold time
pow_fwd_max = pow_fwd;
pow_ref_max = pow_ref;
}
}
void graph_dBm (int T_REFRESH1)
{
//if (( millis()<lastT1 ) and (FirstLoop == 0)) return;
//lastT1 = millis() + T_REFRESH1;
pow_fwd = Power_dBm;
pow_ref = Power_dBm_REF;
anF = map( pow_fwd,-70,70,0,80 ); // 80 = 16 x 5 colums, full scale 2000w
anR = map( pow_ref,-70,50,0,60 ); // 80 = 16 x 5 colums, full scale 125 w
bar(0,anF,T_REFRESH1);
barREF(2,anR,T_REFRESH1);
// update PEP¨meter ?
if (pow_fwd >= pow_fwd_max) { // we have a peak !
lastTpep = millis();
pow_fwd_max = pow_fwd;
pow_ref_max = pow_ref;
}
if (millis() > (lastTpep + T_pepHOLD)) { // clear the peak after hold time
pow_fwd_max = pow_fwd;
pow_ref_max = pow_ref;
}
}
void bar ( int row, int lev,int T_REFRESH1 )
{
//lcd.write( row ? ' ' : ' ' );
lcd.setCursor( 0, row );
for ( int i = 0 ; i < 16 ; i++ )
{
int f = constrain( lev - i * 5, 0, 5 );
int p = constrain( lmax[row] - i * 5, 0, 6 );
if ( f )
lcd.write( fill[ f ] );
else {
lcd.write( peak[ p ] );
}
}
if ( lev > lmax[row] )
{
lmax[row] = lev;
dly[row] = -(T_PEAKHOLD) / T_REFRESH1; // Starting delay value. Negative=peak don't move
}
else
{
if ( dly[row] > 0 )
lmax[row] -= dly[row];
if ( lmax[row] < 0 )
lmax[row] = 0;
else
dly[row]++;
}
}
void barREF ( int row, int lev, int T_REFRESH1)
{
//lcd.write( row ? ' ' : ' ' );
lcd.setCursor( 0, row );
for ( int i = 0 ; i < 11 ; i++ )
{
int f = constrain( lev - i * 5, 0, 5 );
int p = constrain( lmax[row] - i * 5, 0, 6 );
if ( f )
lcd.write( fill[ f ] );
else {
lcd.write( peak[ p ] );
}
}
if ( lev > lmax[row] )
{
lmax[row] = lev;
dly[row] = -(T_PEAKHOLD) / T_REFRESH1; // Starting delay value. Negative=peak don't move
}
else
{
if ( dly[row] > 0 )
lmax[row] -= dly[row];
if ( lmax[row] < 0 )
lmax[row] = 0;
else
dly[row]++;
}
}