1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
| #include <Servo.h>
#include <Arduino.h>
#include <TM1637Display.h>
#define DCSBIOS_IRQ_SERIAL
#include <DcsBios.h>
// Module connection pins (pines de conexion para la pantalla 7-segment )
#define CLK 2
#define DIO 3
//Variables
unsigned int band, signal, rawFreq;
double freq;
#define TEST_DELAY 2000
// Configuramos display con los pines anteriormente definidos
TM1637Display display(CLK, DIO);
// Funcion actualizar frecuencia en pantalla
void refreshScreen() {
display.showNumberDec(freq,false);
}
// Aqui calcula los valores de las frecuencias en cada rango
void calculateFreq() {
float b;
const float maxValue = 65535;
switch (band) {
case 0: { //190-400 kHz (~210kHz)
//A = desired freq
//B = freq based on adfCockpitFrequencyRaw
//(A>200) A = B - ((B * -0.04408) + 18.31) //Creds Paul Marsh
b = ((float(rawFreq) / maxValue) * 210) + 190;
freq = b - ((b * -0.04408) + 18.31);
break;
}
case 1: { //400-850 kHz (~450kHz)
b = ((float(rawFreq) / maxValue) * 450) + 400;
if (b < 451) {
//A = B + ((B * -0.44837) + 177.08)
//freq = b + ((b * -0.44837) + 181.58);
freq = b + ((b * -0.44837) + 177.08);
} else {
//A = B + ((B * 0.11291) - 100.61)
//freq = b + ((b * 0.11291) - 96.11);
freq = b + ((b * 0.11291) - 100.61);
}
break;
}
case 2: { //850-1800 kHz (~950kHz)
//A = B - ((B * -0.04532) + 91.54)
b = ((float(rawFreq) / maxValue) * 950) + 850;
freq = b - ((b * -0.04532) + 91.54);
break;
}
}
}
//Si cambia la banda de frecuencias,recalcula y actualiza valor pantalla
void onAdfBandChange(unsigned int newValue) {
band = newValue;
calculateFreq();
refreshScreen();
}
DcsBios::IntegerBuffer adfBandBuffer(0x14fc, 0x00c0, 6, onAdfBandChange);
//Si cambia la posicion de la rueda de frecuencias, recalcula y actualiza valor pantalla
void onAdfFreqChange(unsigned int newValue) {
rawFreq = newValue;
calculateFreq();
refreshScreen();
}
DcsBios::IntegerBuffer adfFreqBuffer(0x1426, 0xffff, 0, onAdfFreqChange);
/////////////////////////////////////////////////////////////////////////
//default -3200,+3200 menor valor menos movimiento por reten */
// ADF TUNE
DcsBios::RotaryEncoder adfTune("ADF_TUNE", "-1600", "+1600", 5, 4);
//ADF Mode OFF / ADF / ANT / LOOP
const byte adfModePins[7] = { 6, 7, 8, 9};
DcsBios::SwitchMultiPos adfMode("ADF_MODE", adfModePins, 7);
//Signal Level con Servo en pin 10 (PWM pin)
DcsBios::ServoOutput adfSignal(0x1428,10, 1800, 840);
//DcsBios::ServoOutput adfSignal(0x1428,12, 1920, 544); // tope derecha servo apagado ok
//Switch3pos para3 bandas ADF
DcsBios::Switch3Pos adfBand("ADF_BAND", 11, 12);
// ADF LOOP Left / Right
DcsBios::RotaryEncoder adfLoopLr("ADF_LOOP_LR", "DEC", "INC", 14, 15);
// BFO Switch
DcsBios::Switch2Pos adfBfoSw("ADF_BFO_SW",16);
//ADF Gain , volumen
DcsBios::PotentiometerEWMA<5, 128, 5> adfGain("ADF_GAIN", A3);
///////////////////////////////////////////////////////////////////////
// SETUP
void setup() {
// Clear the display:
display.clear();
delay(1000);
DcsBios::setup();
freq = 0;
signal = 0;
}
/////////////////////////////////////////
// LOOP
void loop() {
DcsBios::loop();
// Set the brightness to 5 (0=dimmest 7=brightest)
// Si no configuras brillo no funciona?
display.setBrightness(1);
} |
Partager