//01052022 /************************************************************************************************** * Software für den NF-Wobbler-V1 von DF8ZR --> hat noch Mängel in der Anzeige beim Cursorbetrieb * V1; ist mit Tasten für die Dekaden * * Die Software hat event. noch versteckte Bugs. In meinem Alter lässt die Konzentartionsfähigkeit nach und ich werde diese * Bugs nach und nach suchen und beseitigen. Auch sind einige überflüssige Codes notiert. Sie stören aber nicht. Mir kam es zuletzt darauf an, * die wesentliche Funktionen zu stabilisieren. Nach zwei Wochen intensiver Programmierarbeit brauchte ich mal eine Pause * und nahm mir die Hardware vor. Die meiste Arbeit macht die Dokumentation. Aber die muss sein, denn sonst findet man sich nach einigen * Wochen nicht mehr zurecht. Ich habe mich bemüht, viele Kommentare anzubringen. * * Der Arduino Nano hat begrenzte Fähigkeiten. Wer mehr will, muss einen anderen Prozessoer einsetzen. * Es sind Teile aus dem Netz kopiert. Ich kann mich jedoch an die Urheber nicht mehr erinnern. Bitte um Nachsicht und gehe davon aus, dass man * die Verwendung duldet. * Die Routine für den Dehgeber ist noch nicht ideal. Man muss zu oft mehrere Steps drehen, bis was passiert. Werde ggf. nachbessern. * * BG 22.03.2022 * * : * * Use this library freely * * Hardware connections : * W_CLK -> D13 arduino UNO/NANO, D52 MEGA * FQ_UD -> any pin except 10 and 12 UNO/NANO, 50 and 53 MEGA; hier D7 * DATA/D7 -> D11 arduino UNO/NANO, D51 MEGA; hier PIN D8 * RESET -> any pin except 10 and 12 UNO/NANO, 50 and 53 */ #include "SPI.h" #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #include //#include //nicht verwendet //#include // mögliche Verwendung der Bibliothek //#define FREQ_INIT 1000 //Enter your initial frequency at startup, ex: 7000000 = 7MHz, //10000000 = 10MHz, 840000 = 840kHz. //#define tunestep A0 //Change the pin used by encoder push button #define CursorR A2 #define CursorL A1 unsigned long freqold, fstep; //unsigned long freq = FREQ_INIT; unsigned long time_now = 0; //millis display active unsigned long t1; //Encoder meinEncoder(2,3); // An dieser Stelle wird ein neues Encoder Projekt erstellt. // For the Adafruit shield, these are the default. #define TFT_DC 9 #define TFT_CS 10 #define AD9850_CLOCK 125000000 // Module crystal frequency. Tweak here for accuracy. #define CLK 5 //#define W_CLK 5//8 ohne AD9850 // AD9850 Module pins. #define FQ_UD 7 #define DATA 8//6 #define RESET 6//5 //braucht der AD9850 #define pulseHigh(pin) {digitalWrite(pin, HIGH); digitalWrite(pin, LOW); }//????? #define buisyLED 12 //Anzeige für sweepen //Rotary r = Rotary(2, 3);//24.03. //byte encoder = 1;//1 //byte stp; // Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); //Interrupt const int SetTaster = 2; // Der Taster wurde an Pin 2 angeschlossen volatile int SetStatus = 0 ; // Variable die den Status des Taster ausliest, wird der sog. "Vektor" 0 zugewiesen volatile bool gotInterrupt = false; int n=0; String ampl =""; int amplx; int amply; float ywert; int ywertalt=0; int ydiff=0; //int richtung = 0; int analogPin = A4; int tms; int steptime = 0; int steptimealt = 0; int setbeginn= 0; int cl; int cr; int startz =0;//Taste fstart int stopz = 0;//Taste fstop int timez = 0; double fstart, fstop, f, falt, fstartalt, fstopalt; double frequency; double frequenz; float fdelta, fdiff; int stepPointer = 0; unsigned long incr = 0; int f1c = 0; int f1cgesp = 0; int f2cgesp = 0; int z =0; int sichtbar = 0; int zalt; static int calt = -1;//,notalt = 1;//Interrupt Encoder int E =0; int Z = 0; int H = 0; int T = 0; //int zahlalt; //Options- und Zustandsmarker: int back = 0;//nach einem Zurücksetzen der digits int startaktiv = 0; int stopaktiv = 0; int timesetaktiv = 0; int menueaktiv = 0; int handaktiv = 0; int sweepaktiv =0; int haktion = 0;//hand aktion int cursoraktiv = 0; int sweepoffaktiv = 0; int resetaktiv = 0; int setaktiv = 0; int stellenaktiv = 0; int testsweep = 0; int testzeile = 0; int hanzeige = 0; int punkte; int tdelta; //int t1; //int i =0; int u =0; int vala1; int vala2; int vala3; int vala6; int vala7; int crR = 0;//für einmaligen Durchlauf bei CR int crL = 0;//für einmaligen Durchlauf bei CL int negativ = 0; int zaehler; int minus = 0; int cRalt;//vorhergehende Positionen der Cursor int cLalt; int aktion = 0; int rechts = 0; int links = 0; int posalt, pos = 0; int cRaktiv =0; int cLaktiv =0; int band = 0; int grundlinie = 0; int farbe = 0; int cL = 0; int cR = 0; int einmal = 0; int nstep = 250; //int tms; int forbreak = 0;//für break aus der for-Schleife int inPin = 4; int raus = 1; int cursorschrift = 0;//obere Anzeigezeile im Cursorbetrieb int c; int st1 = 0; int st2 = 0; int y = 0; int yy = 0; int ya; int yx =0; int x2; int x1; int y1; int y2; int xalt; int xalt1; int xalt2; //----------------------------------------------------------- hier für den Drehgeber volatile unsigned char cv=0; static unsigned char cc; void geber(void) { //static unsigned char c;//cc if (setaktiv == 0){//nur wenn die set-Taste gedrückt ist switch(cc=digitalRead(2) | digitalRead(3)<<1) {//Ergebnis von (3) = 2, wenn es 1 ist case 0: if(cv==1) { minus = 1; zaehler++; } else if(cv==2) { minus = 0; zaehler--; } break; case 1: case 2: if(cv==3) cv=cc; break; case 3: cv=cc; } } } // hier alter Code für das Setzen der Frequenz; machte aber probleme mit der Konstanz des Pegels! /* // frequenz = f;// * 4.1731; beim DDS // transfers a byte, a bit at a time, LSB first to the 9850 via serial DATA line void tfr_byte(byte data) { for (int i = 0; i < 8; i++, data >>= 1) { digitalWrite(DATA, data & 0x01); // pulseHigh(W_CLK); //after each bit sent, CLK is pulsed high pulseHigh(CLK);//für Einfachzugriff } } void sendFrequency(double frequency) { frequency = frequency * 4.1731; int32_t freq1 = frequency * 4294967295/AD9850_CLOCK; // note 125 MHz clock on 9850 for (int b = 0; b < 4; b++, freq1 >>= 8) { tfr_byte(freq1 & 0xFF); } tfr_byte(0x000); // Final control byte, all 0 for 9850 chip pulseHigh(FQ_UD); // Done! Should see output } */ //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx void setup() { AD9850_Init(); AD9850_Reset(); //Encoder mit Interrupt! pinMode(2, INPUT_PULLUP); pinMode(3, INPUT_PULLUP); pinMode(inPin, INPUT); // pinMode(4, INPUT);//für break = set Abfrage in der For-Schleife(sweepen, testlauf) attachInterrupt(0, geber, CHANGE); attachInterrupt(1, geber, CHANGE); Serial.begin(9600); pinMode(A4, INPUT);// ywert einlesen bei tft.begin(); tft.fillScreen(ILI9341_BLACK); // x y von oben! tft.setCursor(100, 10); tft.setTextColor(ILI9341_WHITE); tft.setTextSize(2); uint8_t rotation=1;//3//Ausrichtung auf dem Display tft.setRotation(rotation); tft.println("NF-Wobbler");//Menue, Überschrift = Startbild amplx=30; //PIN 2 ist für set = Interrupt //pinMode(W_CLK, OUTPUT);//Original pinMode(CLK, OUTPUT); //für Einfachzugriff pinMode(FQ_UD, OUTPUT); pinMode(RESET, OUTPUT); pinMode(DATA, OUTPUT); // Initialise the AD9850 module. pulseHigh(RESET);//RST // pulseHigh(W_CLK);//Original pulseHigh(CLK);//für Einfachzugriff pulseHigh(FQ_UD); // FQ this pulse enables serial mode - Datasheet page 12 figure 10 pinMode(A0, INPUT_PULLUP); pinMode(CursorR, INPUT_PULLUP); pinMode(CursorL, INPUT_PULLUP); pinMode(A3, INPUT_PULLUP); pinMode(A5, INPUT_PULLUP); pinMode(A6, INPUT_PULLUP); pinMode(A7, INPUT_PULLUP); pinMode(buisyLED, OUTPUT);//buisy LED digitalWrite(buisyLED,LOW);//LED dunkel pinMode(SetTaster, INPUT); // Hier wird der Taster als INPUT definiert marker();//alle Marker deaktivieren menueaktiv = 1; menue(); menueaktiv = 0; //kommt nach der Anzeige MENUE hierher zurück und geht weiter nach loop //wartet jetzt auf die Eingaben fstart, fstop und steptime //danach auf die Aktivierung der Funktionen //valatest(); delay(2000); exit(0);//Abfrage der Taster auf Kurzschluss }//ENDE setup //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //Beginn Loop //################################################################################################################ //#######################################################################//####################################### void loop(void) { vala3 = analogRead(A3);//Tasten-Spannungen einlesen vala6 = analogRead(A6); vala7 = analogRead(A7); if(zaehler!=calt) { calt=zaehler; } //Die Tasten CR und CL dienen nur der Bewegung des Cursors vala2 = analogRead(CursorR); //Einlesen der analogen Spannung an A2 if(vala2 < 500) { // CR 3 delay(100); if ((haktion == 1) or (cursoraktiv == 1)){ rechts = 1; // für positiven Lauf links = 0; // pos = pos + 1; hanzeige = 1; if(handaktiv == 1) { stellenaktiv = 0; } einmal = 1; } xalt2 = pos; } vala1 = analogRead(CursorL); //Einlesen der analogen Spannung an A1 if(vala1 < 500) { // CL 3 delay(100); if ((haktion == 1) or (cursoraktiv == 1)){ links = 1; rechts = 0;// für negativen Lauf <-- hanzeige = 1; if(handaktiv == 1) { stellenaktiv = 0; //cursoraktiv = 0;ok(); ok();ok(); } einmal = 1; } xalt1 = pos; } //Aufnahme für Startfrequenz an D5 //A7/1 if ((vala7 < 600) and (vala7 > 400)) { //sweep = 507mV Taste fstart wurde gedrückt //delay(300); //tft.fillScreen(ILI9341_BLACK);//1.5.22 marker(); startaktiv = 1; zaehler = calt = 0; // einmalig zum fstart 4 vorufstart();//-> 22 //ufstart(); //-> 8 cursoraktiv = 0; hanzeige = 0; }//ENDE fstart ------------------------------------------------------------------------------------- ufstart 4 if ((startaktiv == 1) && (zaehler!=calt)) ufstart();// solange nach ----> ufstart 38 //----------------------------------------------------------------------------------------------------- //Aufnahme für Stopfrequenz setzen an A7 if (vala7 < 100) { // ist dann ca. 0mV bei Tastendruck auf fstop fstop 5 //delay(300); //tft.fillScreen(ILI9341_BLACK);//1.5.22 marker(); setaktiv = 0; stopaktiv = 1; stellenaktiv = 1; forbreak = 0; //menueaktiv = 1; zaehler = calt = 0; vorufstop();// -> 26 cursoraktiv = 0;hanzeige = 0; }//ENDE fstop------------------------------------------------------------------------------------------ // if (stopaktiv ==1) ufstop(); if ((stopaktiv == 1)&& (zaehler!=calt)) ufstop();//-----------> ufstop 39 //----------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------- // Tasten abfragen //----------------------------------------------------------------------------------------------------- // A6 //..................................................................................................... if (vala6 < 100){// hand wurde gedrückt delay(300); //ok();valatest();delay(1000); exit(0); digitalWrite(12, LOW);// buisy - LED tft.fillScreen(ILI9341_BLACK); kreuz();// -> 36 fText();// -> 32 pos = 22; marker(); haktion = 1; handaktiv = 1; } //---------------------------------------------------------------------------------------------> hand 6 if (handaktiv = 1) hand(); //---------> CR --> hand ------> 21 //---------------------------------------------------------------------------------------------------- // DEKADEN 7 //............................................................................................ A3 ///strichcut; // if ((vala3 < 100)) { // 0mV TAUSEND T gedrückt T = 1; H = 0; Z = 0; E = 0; ///strichcut; if(cursoraktiv == 0) stellenaktiv = 1; if (cursoraktiv == 1){ cL = 0; cR = 0; cursoraktiv = 0; stellenaktiv = 0; tft.setTextColor(ILI9341_BLACK);//zunächst die alten Schriftzuege loeschen tft.setCursor(74, 2);//3 tft.print(f1cgesp); f1cgesp = f1c; //die Taste T wird für das Speichern der Cursorfrequenzen eingesetzt tft.setCursor(56, 2);//3 tft.print(f1c); bandbr();//dort wird cursoraktiv wieder = 1 cL = 1;//linker cursor geblockt cR = 0; delay(300); } stellen();//->27 if((startaktiv == 1) or (stopaktiv == 1) or (timesetaktiv == 1)) { haktion = 0;//1.5.22 stellen();// -> 27 tft.setTextSize(2); //hier für die Anzeigen für den Cursorbetrieb tft.setTextColor(ILI9341_BLACK);//zunächst die alten Schriftzuege loeschen //f1cgesp = 0; f2cgesp = 0; tft.setCursor(74, 3); tft.print(falt); tft.print(f1cgesp); tft.setCursor(215, 2); tft.print(f2cgesp); tft.setCursor(30, 3); tft.print("f1: "); tft.setCursor(170, 2);//3 tft.print("f2: "); } } if ((vala3 < 600) and (vala3 > 400)) { //519 mV HUNDERT H T = 0; H = 1; Z = 0; E = 0; if(cursoraktiv == 0) stellenaktiv = 1; stellen();// -> 27 } // if ((vala3 < 800) and (vala3 > 600)) { //688 mV ZEHNER Z T = 0; H = 0; Z = 1; E = 0; if(cursoraktiv == 0) stellenaktiv = 1; stellen();// -> 27 } if ((vala3 > 700)and (vala3 < 790)) { //772 mV EINER E T = 0; H = 0; Z = 0; E = 1; if(cursoraktiv == 0) stellenaktiv = 1; if(menueaktiv == 1){ tft.setTextColor(ILI9341_BLACK);//zunächst die alten Schriftzuege loeschen tft.setCursor(215, 2);//3 tft.print(f2cgesp); tft.setCursor(215, 2);//3 //der augenblickliche Wert f2, der im zweiten Tastendruck mit der E-Taste gespeichert wird f2cgesp = f1c; tft.setTextColor(ILI9341_RED); tft.print(f1c); bandbr(); delay(300); cL = 0;//linker cursor geblockt cR = 1; stellenaktiv = 0; // menueaktiv = 0; }//1.5.22 if((startaktiv == 1) or (stopaktiv == 1) or (timesetaktiv == 1)) { stellen();// -> 27 tft.setTextSize(2); //hier für die Anzeigen für den Cursorbetrieb tft.setTextColor(ILI9341_BLACK);//zunächst die alten Schriftzuege loeschen //f1cgesp = 0; f2cgesp = 0; tft.setCursor(74, 3);// tft.print(f1cgesp); tft.setCursor(215, 2); tft.print(f2cgesp); tft.setCursor(30, 2); tft.print("f1: "); tft.setCursor(170, 2); tft.print("f2: "); } }//ENDE E - DEKADE //--------------------------------------------------------------------------------------------------- //cursoraktiv ------------------------------------------------------------------------------ testlauf 8 if ((vala6 <750) and (vala6 > 550)) { //test 675mV Taste test wurde gedrückt A6 delay(300); menueaktiv = 0; setaktiv = 0; handaktiv = haktion = 0; cursoraktiv = 0; hanzeige = 0; digitalWrite(buisyLED, LOW);// buisy - LED einmal =1;//Testlauf forbreak = 0; stopaktiv = 0; setaktiv = 0; //fstart = 0; // fstop = 29000; testsweep = 1;//Testlauf vorsweep(); // -> 25 Kreuz und Beschriftung malen sweepaktiv = 1; //Auslösen eines Sweeplaufs }//ENDE cursoraktiv -------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------- //hier cursor aktivieren: //if (testsweep == 1)fcursoraktiv(); //----------> 18 //-------------------------------------------------------------------------------------------------------- // vorsweep 9 // A6 //Auslösung sweepen durch sweepaktiv = 1 if ((vala6 < 600) and (vala6 > 400)) { //sweep = 507mV Taste sweep wurde gedrückt delay(300); menueaktiv = 0; setaktiv = 0; testsweep = 0; handaktiv = haktion = 0; forbreak = 0; stopaktiv = 0; testsweep = 0; einmal = 0; sweepaktiv = 1; vorsweep(); // -> 25 Kreuz und Beschriftung malen } //die folgende Schleife wird nach Durchlauf der Loop erneut gestartet, denn sweepaktiv== 1 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: sweepen 10 //fdelta = (fstop - fstart)/250;//double -> Rundungsfehler möglich, aber irrelevant // fdiff = fstop - fstart; fdiff = fstop - fstart; fdelta = fdiff/250.0;//fdelta und fdiff sind float! farbe = 1;//GREEN für "malen()" beginn: if (((sweepaktiv == 1) && ( forbreak == 0)) or (testsweep == 1)) {//sweepaktiv muss gesetzt sein pos = 22; //14.4.22 //for-Schleife for(n=0; n<251; n++){ //nmax bestimmt die Länge; hier: 250 +1 //frequency = fstart + (fdelta * n); frequency = (fstart + (fdelta * (pos - 20)));//neue Frequenz berechnen wie bei hand //frequency = (fstart + ((pos - 20) * fdelta)); //AD9850_Frequenz(frequency); AD9850_Frequenz(frequency);//12-4-22 delay(10);//Mindestzeit für das Setzen der Frequenz(DDS) ywert = analogRead(A4); delay(steptime); //benutzerdefiniert frequenz = frequency; pos = pos +1; malen();// -> 30 if(n > 250) n = 0; raus = digitalRead(inPin);//------------------------------------------------------------------------ Taste set 11 if (raus == 0){ //break sweepen! forbreak = 1; n = 251; break; } }//ENDE der for-Schleife pos = 22;//20; //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: if (testsweep == 1)//stoppt nach einem cursoraktiv im Testlauf { testsweep = 0; sweepaktiv = 0; pos = 22; einmal = 1;//einmal gesweept forbreak =1;//damit nicht beim folgenden Durchlauf(Loop) gelöscht wird sweepaktiv = 0; handaktiv = 0;//12.4.22 setbetrieb();// -> 29 Startparameter für Cursorbetrieb setzen } if ((forbreak == 1) && (sweepaktiv == 1 )) { raus = 1; setbetrieb();// -> 29 Startparameter für Cursorbetrieb setzen } if (testsweep == 1)//stoppt nach einem cursoraktiv im Testlauf { testsweep = 0; sweepaktiv = 0; pos = 22; einmal = 1;//einmal gesweept forbreak =1;//damit nicht beim folgenden Durchlauf(Loop) gelöscht wird sweepaktiv = 0; handaktiv = 0;//12.4.22 setbetrieb();//setbetrieb -> 29 // geht von dort nach setvorlauf() 17 // von da nach fcursor() 19 } if((forbreak == 0) && ( einmal == 0)){ // //delay(100);//Pause für "sichtbaren Rücksprung des Strahles" tft.fillScreen(ILI9341_BLACK); // kreuz(); fText(); //fcursor(); sweepaktiv = 1; forbreak = 0; goto beginn; } //zurück nach sweepen 10 wegen Loop-Betrieb } //ENDE sweepen------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------------- if ( (vala6 < 780) and (vala6 > 720)){// Taste freset wurde gedrückt A6/3 freset digitalWrite(buisyLED, LOW);// busy - LED marker(); handaktiv = 0; fstart = 0; fstop = 0; fstopalt = 0; fstartalt = 0; f1cgesp = 0; f2cgesp = 0; f1c=0; steptime = 0; T = 0; H = 0; Z = 0; E = 1; stellenaktiv = 0; menueaktiv = 1; cursoraktiv = 0; haktion = 0; stellen();//1.5.22 hanzeigedelete(); cursorloeschen(); tft.fillScreen(ILI9341_BLACK); einmal = 0; } //------------------------------------------------------------------------------------------------ freset 12 if( menueaktiv == 1) { menue();//37 hier wird nur die Beschriftung gesetzt menueaktiv = 0; } //------------------------------------------------------------------------------------------------ //Aufnahme für steptime setzen an A5 TASTE A5 steptime 13 //................................................................................................ if (analogRead(A5) < 300) { //Taste steptime wurde gedrückt delay(300); //tft.fillScreen(ILI9341_BLACK);//1.5.22 setaktiv = 0; timesetaktiv = 1; menueaktiv = 1; vorsteptime();// -> 24 } //----------------------------------------------------------------------------------------------------- if ((timesetaktiv == 1 )&& (zaehler!=calt))utimeset();// -> 40 utimeset 14 //----------------------------------------------------------------------------------------------------- // ------------------------------------------------------ cursor ------------------------------------ Taste // //----------------------------------------------------------------------------------------------------- if (cursoraktiv == 1) cursorLinie(rechts, links);// -> 20 --------------------> cursorbetrieb //----------------------------------------------------------------------------------------------------- // hier der Klick auf den ENCODER-SWITCH => Hardware-RESET --------- //RESET 15 // RESET------------------------------------------------------------------------------------- RESET //Auslesen des Tasters an Pin 2 des Encoders if ( sweepaktiv == 0) digitalWrite(buisyLED, LOW);// buisy - LED = dunkel if(setaktiv == 1 ) { //sweepaktiv = 0; handaktiv = 0; haktion = 0; cursoraktiv = 1; digitalWrite(buisyLED, LOW);//dunkel setaktiv = 0; } if ((digitalRead(inPin) == LOW)){ setbetrieb();//setbetrieb setaktiv = 1; } if (haktion ==1) cursorschrift = 0; }//ENDE loop //####################################################################################################################### //####################################################################################################################### //####################################################################################################################### void cursorloeschen(){ // if (grundlinie == 1){//erstmaliger Durchlauf! // malen();// -> 30 x1 = xalt;//letzte Position x2 = x1; y1 = 40; y2 = 272; tft.drawLine(x1, y1, x2, y2, ILI9341_BLACK);//alte Linie wird schwarz übermalt //farbe = 0;//BLACK x1 = xalt1;//letzte Position x2 = x1; y1 = 40; y2 = 272; tft.drawLine(x1, y1, x2, y2, ILI9341_BLACK); x1 = xalt2;//letzte Position x2 = x1; y1 = 40; y2 = 272; tft.drawLine(x1, y1, x2, y2, ILI9341_BLACK); x1 = 22; x2 = x1; tft.drawLine(x1, y1, x2, y2, ILI9341_BLACK); //grundlinie = 0; // }//Grundlinen der Cursor gelöscht } void IntStop(){ // ------------------------------------------------------------------------------ InStop 16 marker(); cursoraktiv = 1;//= Setbetrieb mit Speicherung der Frequenzen stellenaktiv = 0; setaktiv = 0; sweepaktiv = 0; setaktiv = 0; forbreak = 0; cursoraktiv = 1; setbeginn == 1; n = 251; raus = 1; setvorlauf();// -> 17 } //ENDE IntStop ------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------- setvorlauf 17 void setvorlauf(){ tft.setTextColor(ILI9341_BLACK);//zunächst die alten Schriftzuege loeschen tft.setCursor(74, 3); tft.print(f1cgesp); tft.setCursor(215, 3); tft.print(f2cgesp); f1c = 0; f1cgesp = f2cgesp = 0; if (fstop > fstart){ ;//and (menueaktiv == 0)){ //Schrifen aus Menue löschen tft.setTextSize(2); //war zuvor GREEN tft.setTextColor(ILI9341_BLACK); tft.setCursor(30, 30); tft.println(fstart, 0); //war zuvor RED tft.setCursor(200, 30); tft.println(fstop, 0); //war zuvor Yellow tft.setCursor(240, 30); tft.println(" Hz"); tft.setCursor(170, 3); tft.print("f2: "); tft.setTextColor(ILI9341_GREEN); tft.setCursor(30, 3);//8, 3 tft.print("f1: "); //hier wird erstmalig die Anzeige für "f1: "sichtbar pos = 22; //linker Stand des Cursors, mit CR starten if ( haktion == 0){//darf nicht im Handbetrieb geloescht werden //loeschen der mittigen Frequenzanzeige der Funktion: hand void hanzeigedelete(); tft.setTextColor(ILI9341_BLACK);//alten Schriftzug loeschen tft.setCursor(150, 3);//80, 20 tft.println(falt, 0); } grundlinie = 1; //für erstmaligen sweep eine senkrechte Linie übermalen cursoraktiv = 1; fcursor();// -> 19 if ((handaktiv == 1) or (sweepaktiv == 1)){ //sweepaktiv = 1 von testlauf fdiff = fstop - fstart; //Differenzfrequenz //drawmark = 1; //damit jetzt die Anzahl der x-Punkte berechnen // x ist 250 Punkte lang punkte = fdiff / 250; startaktiv = 0; stopaktiv = 0; timesetaktiv = 0; handaktiv = 0; pos = 22;//Start für die Wobbelkurve } cLaktiv = 1;//es ist für die Cursorlinie nur GREEN aktiv! Siehe bei "malen" handaktiv = 0; haktion =0;//sperren hand Frequenzanzeige, darf nicht mehr sichtbar sein //Anzeige der laufenden Frequenz tft.setTextColor(ILI9341_BLACK);//alten Schriftzug löschen tft.setCursor(150, 3); if(cursoraktiv != 1) tft.println(falt, 0);//f = falt tft.setTextColor(ILI9341_BLACK);//alten Schriftzug löschen tft.setCursor(150, 3); if(cursoraktiv != 1)tft.println(falt, 0); // fcursoraktiv();// -> 18 } }//ENDE setvorlauf //----------------------------------------------------------------------------------------------- void fcursoraktiv(){ //-------------------------------------------------------------------------- fcursoraktiv 18 hanzeige = 0; if (handaktiv == 0){// => sweepen resetaktiv = 0; cursoraktiv = 1; } }//ENDE fcursoraktiv --------------------------------------------------------------------------- void fcursor(){// -------------------------------------------------------------------------- fcursor 19 if((rechts == 1) or (links == 1)){ if ((cursoraktiv == 1) && (handaktiv == 0)) { //ok(); tft.setTextSize(2); //Schrifthöhe für den Cursorbetrieb tft.setTextColor(ILI9341_BLACK);//zunächst die alten Schriftzuege loeschen tft.setCursor(74, 2);//52,3 tft.print(f1cgesp); tft.setCursor(215, 2); tft.print(f2cgesp); tft.setTextColor(ILI9341_GREEN);// tft.setCursor(74, 2);//52,3 tft.print(f1c); tft.setTextColor(ILI9341_GREEN);//gelegentlich geht die Schriftfarbe verloren !? cL = 1; //linker Cursor ist aktiv } testsweep = 0;//12.4.22 handaktiv = 0;//12.4.22 haktion = 0;//12.4.22 cursorLinie(rechts,links);// -> 20 }//rechts/links ENDE }//ENDE fcursor -------------------------------------------------------------------------------- //.............................................................................................. void cursorLinie(int rechts, int links){//------------------------------------------------------ cursorLinie 20 handaktiv = 0; fdiff = fstop - fstart; fdelta = fdiff/250.0;//fdelta und fdiff sind float! if (einmal ==1){ if ((cursoraktiv == 1) && (menueaktiv == 0)){ //int x1, y1, x2, y2;//sind global ! //w = tft.width(), // h = tft.height(); //es geht immer von unten nach oben y1 = 30; y2 = 40;//12.4.22 if (grundlinie == 1){//erstmaliger Durchlauf! x1 = x2 = 272;//vorhergehende Position tft.drawLine(x1, y1, x2, y2, ILI9341_BLACK);//alte Linie wird schwarz übermalt farbe = 1; x1 = x2 = 22;//vorhergehende Position tft.drawLine(x1, y1, x2, y2, ILI9341_BLACK);//alte Linie wird schwarz übermalt farbe = 1; grundlinie = 0; posalt = 22;//zusatz eingebracht????? }//Grundlinen der Cursor gelöscht //fdelta = (fstop - fstart) / 250.0; // links = 1 --> nach links //rechts = 1 --> nach rechts // cRaktiv --> ist der rechte cursor; der ist immer RED // cLaktiv --> ist der linke cursor; der ist immer GREEN //Serial.print(cRaktiv); //Tasten T oder E bestimmen den Cursor cRaktiv oder cLaktiv, CR und CL die Richtung rechts oder links if (rechts == 1){ // -> nach rechts //Serial.print("rechts = "); Serial.print(rechts);Serial.print(" "); pos = posalt + 1;//neue Position rechts if(posalt < 22) pos = 22; if (pos > 270) pos = 270; //alte Linie löschen x1 = x2 = posalt;//vorhergehende Position, da bei CR posalt + 1 = posneu ist tft.drawLine(x1, y1, x2, y2, ILI9341_BLACK); farbe = 1; //Serial.print(pos);//GREEN nach Cursormalen wieder hergestellt //jetzt die aktuelle Position = neue position rechts //neue Linie malen x1 = x2 = pos;//posalt + 1 if (sweepaktiv == 0)//nachträglich 19.3.22 tft.drawLine(x1, y1, x2, y2, ILI9341_ORANGE); //die Frequenzen für die obige Anzeige f1: und f2: ermitteln f1c = fstart + (fdelta * (pos - 20)); posalt = pos; }// CR rechts ENDE---------------------------------------------------------------- if ( links == 1) { // <-- nach links pos = posalt - 1; if(posalt <= 22) pos = 22; if (pos >= 270) pos = 270; //alte Linie löschen x1 = x2 = posalt; tft.drawLine(x1, y1, x2, y2, ILI9341_BLACK); //pos= pos + 2;//radius der Punkte = 2! farbe = 1;//GREEN // pos = pos - 2;//vorher 2 //jetzt die aktuelle Position; sie ist schon -2 zurück //if (pos < 20 ) grenzen(); x1 = x2 = pos;//neue position links if (sweepaktiv == 0) tft.drawLine(x1, y1, x2, y2, ILI9341_CYAN); //pos = x1; tft.setTextColor(ILI9341_GREEN);// f1c = fstart + (fdelta * (pos - 20)); delay(10); //19.3.22 wegen langsamer Bewegung, wie bei rechts posalt = pos; } //diagnose(); //delay(2000); }//einmal ENDE rechts = 0; links = 0; posalt = pos; einmal = 0; }//cursoraktiv ENDE }// ENDE-- cursorlinie -------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------- hand 21 void hand(){ stellenaktiv = 0; testsweep = 0; if (pos <= 22) pos = 22;//zählt hier anders als bei cursorLinien if (pos >= 270) pos = 270; //fdelta = (fstop - fstart)/250.0;//double -> Rundungsfehler möglich, aber irrelevant fdiff = fstop - fstart; fdelta = fdiff/250.0;//fdelta und fdiff sind float! if ((haktion == 1) && (cursoraktiv == 0)){ if (links == 1){ // <-- -------------------------------------------------------- nach links //L1 : alten Punkt loeschen //________________________________ tft.setTextColor(ILI9341_BLACK); if(posalt < 19) posalt = 20; tft.setCursor(posalt,ywertalt);//Position und Wert des vorhergehenden Punktes if (pos < 19 ) pos = 20 ;//Grenzunterschreitung farbe = 0;//farbe schwarz ywert = ywertalt;//wird für malen()gebraucht malen();//alten Punkt mit Schwarz "überschreiben" = //gelöscht // L2: alte Frequenzanzeige loeschen //___________________________________ if(hanzeige == 1){//nur im Handbetrieb //jetzt die alte Frequenz(anzeige) tft.setTextColor(ILI9341_BLACK);//alten Schriftzug löschen tft.setCursor(150, 3); if(cursoraktiv != 1) tft.print(falt, 0);//alter Schriftzug } // L3: neuen Punkt malen //___________________________________ pos = posalt - 1;//neue Position if(pos <= 22) pos = 22; posalt = pos;//neue posalt-Position frequency = (fstart + ((pos - 20) * fdelta)); //fdelta =(fstop - fstart)/(270 - 20); fdelta = fdiff / 250; f = frequency;//= neue Frequenz //falt = f;//neuer falt-Wert am der linken Position if(einmal == 1) AD9850_Frequenz(frequency);// AD9850_Frequenz(frequenz); //Frequenz in DDS setzen delay(10); // Mindest-Setzzeit > 4ms! //Serial.print("links neu = "); Serial.print(frequency, 0);Serial.print(" "); Serial.print("pos = "); Serial.println(pos); pos--;//einen Punkt nach links auf die neue alte Position if((pos >= 20) and (pos < 271)){ farbe = 1;// 1 = gruen ywert = analogRead(A4); malen();// -> 30 } // L4: neueFrequenz anzeigen //___________________________________ // f = frequency - fdelta ;//13.04.22 if (f >= fstart) falt = f; //neuer falt-Wert if(f <= fstart) falt = fstart; if (hanzeige == 1){ //jetzt die erniedrigte Frequenz anzeigen tft.setTextColor(ILI9341_YELLOW);//alten Schriftzug schreiben, weil f = falt wird tft.setCursor(150, 3); tft.print(f, 0); } //if(cursoraktiv != 1) tft.print(falt, 0);//f = falt am noch besetzten Punkt, dann nach links stellenaktiv = 0; einmal = 0; }//ENDE links //------------------------------------------------------------------------------------------ --> rechts if (rechts == 1){ //1 = --> vorwärtz //R1 : neuen Punkt malen //________________________________ pos = pos + 1; if (pos >= 270) pos= 270;// + pos; 13-04-22 frequency = (fstart + (fdelta * (pos - 20)));//neue Frequenz berechnen f = frequency; //neue Frequenz if(einmal == 1) AD9850_Frequenz(frequency); //AD9850_Frequenz(frequenz); delay(10); farbe = 1;//gruen ywert = analogRead(A4); malen();// -> 30 //R2 : alte Frequenzanzeige loeschen //________________________________ if(hanzeige = 1){ //die mitlaufende Anzeiege wird bei Position x=120 gemacht tft.setTextColor(ILI9341_BLACK);//alten Schriftzug löschen tft.setCursor(150, 3); if(cursoraktiv != 1)tft.print(falt, 0); tft.setTextColor(ILI9341_YELLOW);//neuer Schriftzug tft.setCursor(150, 3); tft.print(f, 0); } einmal = 0; falt = f; }//rechts ENDE posalt = pos; ywertalt = ywert; //richtung = 0;// neutral, keine ENCODERBEWEGUNG haktion = 1;// vorher 0 zurück nach Loop hanzeige = 0;//nach dem Stopp des Cursors rechts = 0; links = 0; }//--------haktion ENDE }//ENDE hand------------------------------------------------------------------------------------------ void vorufstart(){ //--------------------------------------------------------------------------------- vorufstart 22 startaktiv = 1; crR = 0; crL = 0; cRaktiv = 0; cLaktiv = 0; z = 0; zaehler = 0; negativ = 0; handaktiv = 0; if (handaktiv == 1){ handaktiv = 0; tft.fillScreen(ILI9341_BLACK); menue();// ------------------------------------------------> 37 } }//ENDE vorufstart------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------- freset 23 void freset(){//Werte retten und Anzeige löschen fstartalt = fstart; fstopalt = fstop; steptimealt = steptime; tft.fillScreen(ILI9341_BLACK); sweepoffaktiv = 0; //alte Werte wieder holen fstart = fstartalt; fstop = fstopalt, steptime = steptimealt; if (startaktiv == 1){ tft.setTextColor(ILI9341_BLACK);//alten Schriftzug löschen tft.setCursor(160, 90); tft.println(fstart, 0); fstart=1; fstartalt=0; E = 1; Z=0; H=0; T=0; haktion = 0; if(handaktiv == 0){ tft.setTextColor(ILI9341_GREEN);//alten Schriftzug tft.setCursor(160, 90); tft.println(fstart, 0); minus = 0; /// strichcut(); ufstart();//38 /// strichcut(); }} if (stopaktiv == 1){ tft.setTextColor(ILI9341_BLACK);//alten Schriftzug löschen tft.setCursor(160, 130); tft.println(fstop, 0); fstop=1; fstopalt=0; E = 1; Z=0; H=0; T=0; if(handaktiv == 0){ tft.setTextColor(ILI9341_GREEN);//alten Schriftzug tft.setCursor(160, 130); tft.println(fstop, 0); minus = 0; /// strichcut(); ufstop();// -> 39 /// strichcut(); }} if (timesetaktiv == 1){ tft.setTextColor(ILI9341_BLACK);//alten Schriftzug löschen tft.setCursor(160, 180); tft.println(steptime);// ist int!! steptime=0; steptimealt=0; E = 1; Z=0; H=0; T=0; if(handaktiv == 0){ tft.setTextColor(ILI9341_GREEN);//alten Schriftzug tft.setCursor(160, 180); tft.println(steptime, 0); minus = 0; /// strichcut(); utimeset();// -> 40 /// strichcut(); }} //alte Werete wieder holen fstart = fstartalt; fstop = fstopalt, steptime = steptimealt; haktion = 0;//für hand cursoraktiv = 0; sweepaktiv = 0; handaktiv = 0; haktion = 0; stellen(); cursoraktiv = 0; menueaktiv = 1; sichtbar = 1; menue();// -> 37 resetaktiv = 1; }//ENDE freset-------------------------------------------------------------------------------- void vorsteptime(){//------------------------------------------------------------------------- vorsteptime 24 startaktiv = 0; stopaktiv = 0; timesetaktiv = 1; z = 0; negativ = 0; if (stopaktiv == 1){ handaktiv = 0; menueaktiv = 1; tft.fillScreen(ILI9341_BLACK); menue();// -> 37 sichtbar = 1; } }//ENDE vorsteptime------------------------------------------------------------------------- void vorsweep(){ //------------------------------------------------------------------------- vorsweep 25 tft.fillScreen(ILI9341_BLACK); // Schirm löschen // testsweep = 0; kreuz();// -> 36 sweepaktiv = 1; cursoraktiv = 1; }//ENDEvorsweep---------------------------------------------------------------------------- void vorufstop(){ //----------------------------------------------------------------------- vorfstop 26 marker(); stopaktiv = 1; sichtbar = 1; crR = 0; crL = 0; cRaktiv = 0; cLaktiv = 0; z = 0; zaehler = 0; negativ = 0; if (handaktiv == 1){ handaktiv = 0; tft.fillScreen(ILI9341_BLACK); menue();// --> 37 } }//ENDE vorufstop -------------------------------------------------------------------------- void stellen(){ //------------------------------------------------- stellen ---------------- stellen 27 //hier die T H Z E loeschen und setzen //if ((stellenaktiv == 1) && (haktion == 0) && (cursoraktiv == 0)){ //if(sweepoffaktiv == 0){ tft.setTextSize(1); tft.setTextColor(ILI9341_BLACK);//alten Schriftzug mit BLack ueberschreiben tft.setCursor(150, 220);//das sind die Positionen tft.print("T H Z E"); tft.print(" "); //tft.print("- - - -"); tft.setTextColor(ILI9341_WHITE);//alten Schriftzug bis auf E weiss anzeigen tft.setCursor(150, 220);//das sind die Positionen //tft.print("- - - -"); tft.print("T H Z E"); if ((E == 0)and (Z == 0) and (H == 0) and (T == 1)) { tft.setTextColor(ILI9341_WHITE);//alten Schriftzug tft.setCursor(150, 220); //tft.print("- - - -"); tft.setCursor(150, 220); tft.setTextColor(ILI9341_MAGENTA);//alten Schriftzug tft.setCursor(150, 220); //tft.print("- - - -"); tft.print("T "); } if ((E == 0)and (Z == 0) and (H == 1) and (T == 0)){ tft.setTextColor(ILI9341_WHITE);//alten Schriftzug tft.setCursor(150, 220); //tft.print("- - - -"); tft.setCursor(150, 220); tft.setTextColor(ILI9341_MAGENTA);//alten Schriftzug //tft.print("- - - -"); tft.print(" H "); } if ((E == 0)and (Z == 1) and (H == 0) and (T == 0)) { tft.setTextColor(ILI9341_WHITE);//alten Schriftzug //tft.print("- - - -"); tft.setCursor(150, 220); tft.setTextColor(ILI9341_MAGENTA);//alten Schriftzug //tft.print("- - - -"); tft.print(" Z "); } if ((E == 1)and (Z == 0) and (H == 0) and (T == 0)){ tft.setTextColor(ILI9341_WHITE);//alten Schriftzug bis auf E weiss anzeigen tft.setCursor(160, 220);//das sind die Positionen tft.setCursor(150, 220); tft.setTextColor(ILI9341_MAGENTA);//alten Schriftzug //tft.print("- - - -"); tft.print(" E"); } tft.setTextSize(2); //} //} }//ENDE stellen -------------------------------------------------------------- void bandbr(){//-------------------------------------------------------------- bandbr 28 //alte Anzeige loeschen tft.setTextColor(ILI9341_BLACK); tft.setCursor(74, 3); tft.print(f1cgesp); tft.setCursor(215, 3); tft.print(f2cgesp); tft.setCursor(100, 226); tft.print("B = "); tft.print(band); tft.setTextColor(ILI9341_GREEN); tft.setCursor(30, 3); tft.print("f1: "); tft.setCursor(74, 3); tft.println(f1cgesp); tft.setTextColor(ILI9341_RED); tft.setCursor(170, 3); tft.print("f2: "); tft.setCursor(215, 3); tft.print(f2cgesp); tft.setTextColor(ILI9341_GREEN); if ( f2cgesp - f1cgesp > 0){ band = f2cgesp - f1cgesp; tft.setTextColor(ILI9341_YELLOW); tft.setCursor(100, 226); tft.print("B = "); tft.print(band); } cursoraktiv = 1; }//ENDE bandbr --------------------------------------------------------------------------------- void setbetrieb(){// _-------------------------------------------------------------------------- setbetrieb 29 stopaktiv = 0; startaktiv = 0; sweepaktiv = 0;// für beenden von sweep haktion = 0; timesetaktiv = 0; resetaktiv = 0; menueaktiv = 0; testsweep = 0; forbreak = 0; einmal = 1; void hanzeigedelete(); digitalWrite(buisyLED, LOW);//LED dunkel cursoraktiv = 1;//= Setbetrieb mit Speicherung der Frequenzen setvorlauf(); //-> 17 } //---------------------------------------------------------------------------------------------- malen 30 void malen(){ //200 Punkte = y-werte //60 dB sollen 5 V sein; geteilt durch 5 = 1000 mV //1V = 60 dB = 200 y-Punkte // die obere Grenze ist y = 40 = 60dB //die untere Grenze ist 220; daher die Differnez = 220-40 = 180 //= 6 x 10 dB(linear) // 2 V wären demnach 30dB = 40 + wert if (pos > 270) pos= 270; if (pos < 22) pos= 22; if(ywert < 10) ywert = 5;//VORSICHT!!!!!! //amply = 220 - ywert;//ywert hier wird zu int amply amply = 220 - ywert;//bei 220 ist die Grundlinie; -y geht nach oben bis zum Maximalpegel;y von 220 bis 30 //amply ist der y-Wert für amplPunkt(); //pos für x //farbe = 1; amplPunkt();// -> 33 ywertalt = ywert; if (pos > 270) pos= 270; if (pos < 22) pos= 22; if ((sweepaktiv == 1)&&(forbreak == 0))digitalWrite(buisyLED, HIGH); if (handaktiv == 1) sweepaktiv = 0;//25.03. }//ENDE malen -------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- unsigned long xyLinien(uint16_t color) { // unsigned long start, t; //int x1, y1, x2, y2; y1 = 30; y2 = 220; x1 = x2 = 20; tft.drawLine(x1, y1, x2, y2, color);//y-Achse // xyLinien 31 x1 = 20; y1 = y2 = 220; x2 = 280; tft.drawLine(x1, y1, x2, y2, color);//x-Achse } //ENDE------------------------------------------------------------------------------------------------ //---------------------------------------------------------------------------------------------------- fText 32 void fText(){ // das Kreuz beschriften tft.setTextColor(ILI9341_WHITE); tft.setTextSize(1); tft.setCursor(20, 225); tft.println(fstart, 0); tft.setCursor(1, 18); tft.print("-dBm"); tft.setCursor(250, 225); tft.print(fstop, 0); tft.print(" Hz"); //___________Beschriftung dB tft.setCursor(1, 50); tft.print("20"); tft.setCursor(1, 90); tft.print("30"); tft.setCursor(1, 130); tft.print("40"); tft.setCursor(1, 170); tft.print("50"); tft.setCursor(1, 210); tft.print("60"); //------------------------------------------------------------------ //jetzt die Skala //bei 270 -240 = 30 ist 0 dB; alle 40 y-Werte soll -10 dB sein //daher xyLinien(uint16_t ILI9341_YELLOW) int x1, y1, x2, y2; y1 = y2 = 35; x1 =15; x2 = 18; tft.drawLine(x1, y1, x2, y2, ILI9341_YELLOW);//0 dBm y1 = y2 = 44;//-20 dB tft.drawLine(x1, y1, x2, y2, ILI9341_YELLOW);// y1 = y2 = 84;//-30 dB tft.drawLine(x1, y1, x2, y2, ILI9341_YELLOW);// y1 = y2 = 124;// -40 dB tft.drawLine(x1, y1, x2, y2, ILI9341_YELLOW);// y1 = y2 = 164;// -50 dB tft.drawLine(x1, y1, x2, y2, ILI9341_YELLOW);// y1 = y2 = 204;// -60 dB tft.drawLine(x1, y1, x2, y2, ILI9341_YELLOW);// // y1 = y2 = 238; //tft.drawLine(x1, y1, x2, y2, ILI9341_YELLOW);// //----------------------------------------------------------------- tft.setTextSize(2); pos = 22; } //ENDE------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------- amplPunkt 33 void amplPunkt() { //hier werden die Punkte gemalt uint8_t radius=2; //uint16_t color= ILI9341_GREEN; int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2; // if (pos > 270) pos= 270; if (pos < 22) pos= 22; x = pos;//y = amply if(cursoraktiv == 1) x = pos; y= amply; if(farbe ==1) tft.fillCircle(x, y, radius,ILI9341_GREEN );//Punkt malen if(farbe ==0) tft.fillCircle(x, y, radius,ILI9341_BLACK );//Punkt löschen } //ENDE-------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- sweepoff 34 void sweepoff(){ tft.setTextColor(ILI9341_BLACK); tft.setCursor(110, 3); tft.print("sweep off"); if (sweepoffaktiv ==1){ tft.setTextColor(ILI9341_MAGENTA); tft.setCursor(110, 3); tft.print("sweep off"); } }//ENDE sweepoff------------------------------------------------------------------------------------ void AD9850_Init(){ // Ausgänge definieren // AD9850_init pinMode(RESET, OUTPUT); // alles Ausgänge pinMode(FQ_UD, OUTPUT); //pinMode(W_CLK , OUTPUT);//Original pinMode(CLK, OUTPUT);//sonst für Einfachzugriff pinMode(DATA, OUTPUT); digitalWrite(RESET, 0); // alles auf 0 digitalWrite(FQ_UD, 0); //digitalWrite(W_CLK, 0);//Original digitalWrite(CLK, 0);//für Einfachzugriff definiert digitalWrite(DATA, 0); } void AD9850_Reset(){ // DDS zuruecksetzen pulseHigh(RESET); //Reset Signal // pulseHigh(W_CLK); //Clock Signal pulseHigh(CLK); pulseHigh(FQ_UD); //Frequenz Update Signal } void AD9850_Frequenz(double frequenz){ // Die Frequenz übertragen und DDS starten //Serial.print("F = "); Serial.println(frequenz, 0); long int y; // AD9850 //frequenz=frequenz/1000000*5294967295/125; //fuer einen 125 MHz Quarz //frequenz=frequenz * 4.1731;//4.6026507Korrekturfaktor in diesem Programm //frequenz=frequenz * 1.13; frequenz=frequenz/1000000*5294967295/125; //für ein 125 MHz Quarz frequenz=frequenz * 4.1731;//4.6026507Korrekturfaktor in diesem Programm //frequenz=frequenz * 1.13; y=frequenz; AD9850_SendData(y); // w4 - Frequenzdaten LSB übertragen AD9850_SendData(y>>8); // w3 AD9850_SendData(y>>16); // w2 AD9850_SendData(y>>24); // w1 - Frequenzdaten MSB AD9850_SendData(0x00); // w0 - 0x00 keine Phase pulseHigh(FQ_UD); // Die neue Frequenz ausgeben } void AD9850_SendData(unsigned char c) { int i; for(i=0; i<8; i++) { digitalWrite(DATA, (c>>i)&0x01); pulseHigh(CLK); } } //----------------------------------------------------------------------------------------------- grenzen 35 void grenzen(){ if (pos < 22){ pos = 22; grundlinie = 1; cursoraktiv = 1; } if (pos > 269){ pos = 270; grundlinie = 1; cursoraktiv = 1; } }//ENDE grenzen------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- kreuz 36 void kreuz(){ //Koordinaten zeichnen xyLinien(ILI9341_YELLOW);//Koordinaten-Linien //Beschriftung der Koordinaten drucken ampl = "dB"; stellenaktiv = 0;//28.03. fText();// -> 32 }//ENDE kreuz --------------------------------------------------------------------------------------- //---------------------------------Anzeigen setzen--------------------------------------------------- menue 37 void menue(){ if(menueaktiv == 1){ tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2); tft.setCursor(75, 40); tft.println("Einstellungen"); tft.setCursor(30, 90); tft.println("fstart:"); tft.setCursor(30, 130); tft.println("fstop:"); // tft.setCursor(30, 180); tft.println("steptime:"); tft.setTextColor(ILI9341_GREEN); tft.setCursor(260,90); tft.println("Hz"); tft.setTextColor(ILI9341_RED); tft.setCursor(260,130); tft.println("Hz"); tft.setTextColor(ILI9341_WHITE); tft.setCursor(260,180); tft.println("ms"); } }//ENDE menue ------------------------------------------------------------------------ //-----------------------------------------------------------ufstart ----------------- ufstart 38 void ufstart(){ sichtbar = 1; if (negativ == 1) { sichtbar = 0; ///strichcut(); } //Serial.println(zaehler); tft.setTextSize(2); if (sichtbar == 1) { tft.setTextColor(ILI9341_BLACK);//alten Schriftzug loeschen tft.setCursor(160,90); tft.println(fstart, 0); if (fstart <=0){ E = 1; fstart = 0; } if ( E == 1 ) { if (calt > zaehler){ //minus fstart = fstartalt - 1; minus = 0; } else {fstart = fstartalt + 1; } } if ( Z == 1 ) { if (calt > zaehler){ //minus fstart = fstartalt - 10; } else {fstart = fstartalt + 10; } } if ( H == 1 ) { if (calt > zaehler){ //minus fstart = fstartalt - 100; minus = 0; } else {fstart = fstartalt + 100; } } if ( T == 1 ) { if (calt > zaehler){ //minus fstart = fstartalt - 1000; minus = 0; } else {fstart = fstartalt + 1000; } } calt = zaehler;//26.03. minus = 0; //Grenzüberschreitung: if (fstart > 29000){ fstart = 29000; //minus = 0; tft.setTextColor(ILI9341_BLACK); tft.setCursor(160,90); tft.println(fstart, 0); /// strichcut(); } //neuen Wert in Farbe drucken tft.setTextColor(ILI9341_GREEN); tft.setCursor(160,90); if (fstart >= 0){ tft.println(fstart, 0); } minus = 0; }//ENDE sichtbar? //} if (fstart < 0)fstart = 0; if (fstart < 0){ fstart =0; tft.setTextColor(ILI9341_BLACK); tft.setCursor(160,90); tft.println(fstart, 0); negativ = 1; T = 0; H = 0; Z = 0; E = 1; /// strichcut(); } fstartalt = fstart; minus = 0;//auf positiv setzen sichtbar = 0; menueaktiv = 1;//1.5.22 }// ENDE ufstart-------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- ufstop 39 void ufstop(){ // sichtbar = 1; if (negativ == 1) { sichtbar = 0; ///strichcut(); } if (fstop > 0) back = 0; tft.setTextSize(2); if (sichtbar == 1) { tft.setTextColor(ILI9341_BLACK);//alten Schriftzug löschen tft.setCursor(160,130); tft.println(fstop, 0); if (fstop <=0){ E = 1; fstop = 0; } if ( E == 1 ) { if (calt > zaehler){ //minus fstop = fstopalt - 1; minus = 0; } else {fstop = fstopalt + 1; } } if ( Z == 1 ) { if (calt > zaehler){ //minus fstop = fstopalt - 10; } else {fstop = fstopalt + 10; } } if ( H == 1 ) { if (calt > zaehler){ //minus fstop = fstopalt - 100; minus = 0; } else {fstop = fstopalt + 100; } } if ( T == 1 ) { if (calt > zaehler){ //minus fstop = fstopalt - 1000; minus = 0; } else {fstop = fstopalt + 1000; } } if (fstop > 29000){ fstop = 29000; E = 1; minus = 0; tft.setTextColor(ILI9341_BLACK); tft.setCursor(160,130); tft.println(fstop, 0); /// strichcut(); in der alten Version! } //neuen Wert in Farbe drucken tft.setTextColor(ILI9341_RED); tft.setCursor(160,130); if (fstop >= 0){ tft.println(fstop, 0); } minus = 0; } //ENDE sichtbar == 1 if (fstop < 0){ fstop =0; tft.setTextColor(ILI9341_BLACK); tft.setCursor(160,130); tft.println(fstop, 0); negativ = 1; T = 0; H = 0; Z = 0; E = 1; /// strichcut(); } fstopalt = fstop; minus = 0;//auf positiv setzen sichtbar = 0; }//ENDE ufstop ------------------------------------------------------------------------------- void utimeset(){// --------------------------------------------------------------------------- utimeset 40 sichtbar = 1; if (sichtbar == 1) { tft.setTextColor(ILI9341_BLACK);//alten Schriftzug löschen tft.setCursor(160, 180); tft.println(steptimealt, DEC); if (steptime <=0) E = 1; if ( E == 1 ) { if (calt > zaehler){ //minus steptime = steptimealt - 1; minus = 0; } else {steptime = steptimealt + 1; } } if ( Z == 1 ) { if (calt > zaehler){ //minus steptime = steptimealt - 10; minus = 0; } else{ steptime = steptime + 10; } } if ( H == 1 ) { if (calt > zaehler){ //minus steptime = steptimealt - 100; minus = 0; } else steptime = steptimealt + 100; } if ( T == 1 ) { if (calt > zaehler){ //minus steptime = steptimealt - 1000; minus = 0; } else steptime = steptimealt + 1000; } if (steptime > 1000) { steptime = 1000; // striche(); } steptimealt = steptime; //neuen Wert in Farbe drucken tft.setTextColor(ILI9341_WHITE); tft.setCursor(160,180); tft.println(steptime, DEC); minus = 0; // }//endet sichtbar if (steptime < 0){ // Serial.println("OK"); tft.setTextColor(ILI9341_BLACK); tft.setCursor(160,180); tft.println(steptime, DEC); negativ = 1; T = 0; H = 0; Z = 0; E = 1; steptime =0; /// strichcut(); } minus = 0; sichtbar = 0; }//ENDE timeset------------------------------------------------------------------------------------------ void marker(){ setaktiv = 0; menueaktiv = 0; stopaktiv = 0; startaktiv = 0; haktion = 0; handaktiv = 0; menueaktiv = 0; timesetaktiv = 0; testsweep = 0; cursoraktiv = 0; sweepaktiv = 0; forbreak = 0; einmal = 0; } void hanzeigedelete(){ tft.setTextColor(ILI9341_BLACK);//alten Schriftzug loeschen tft.setCursor(150, 3); tft.println(falt, 0);//f = falt hanzeige = 0; //diagnose();delay(1000);exit(0); } void diagnose(){ //------------------------------------------------------------------------------- diagnose 41 Serial.print("startaktiv = "); Serial.print(startaktiv);Serial.println(""); Serial.print("stopaktiv = "); Serial.print(stopaktiv);Serial.println(""); //Serial.print("timesetaktiv = "); Serial.print(timesetaktiv);Serial.println(""); Serial.print("menueaktiv = "); Serial.print(menueaktiv);Serial.println(""); Serial.print("cursoraktiv = "); Serial.println(cursoraktiv);Serial.println(""); Serial.print("testsweep = "); Serial.println(testsweep);Serial.println(""); Serial.print("sweepaktiv = "); Serial.print(sweepaktiv);Serial.println(""); Serial.print("forbreak = "); Serial.print(forbreak);Serial.println(""); Serial.print("stellenaktiv = "); Serial.println(stellenaktiv);Serial.println(""); Serial.print("handaktiv = "); Serial.print(handaktiv);Serial.println(""); Serial.print("haktion = "); Serial.print(haktion);Serial.println(""); Serial.print("hanzeige = "); Serial.print(hanzeige);Serial.println(""); //Serial.print("sweepoffaktiv = "); Serial.print(sweepoffaktiv);Serial.println(""); //Serial.print("resetaktiv = "); Serial.print(resetaktiv);Serial.println(""); Serial.print("setaktiv = "); Serial.print(setaktiv);Serial.println(""); Serial.print("einmal = "); Serial.print(einmal);Serial.println(""); Serial.print("sichtbar = "); Serial.print(sichtbar);Serial.println(""); Serial.print("rechts = "); Serial.print(rechts);Serial.println(""); Serial.print("links = "); Serial.print(links);Serial.println(""); //Serial.print("grundlinie = "); Serial.print(grundlinie);Serial.println(""); //Serial.print("fstart = "); Serial.println(fstart); //Serial.print("fstop = "); Serial.println(fstop); //Serial.print("steptime = "); Serial.println(steptime); Serial.print("f1c = "); Serial.println(f1c); //Serial.print("f2c = "); Serial.println(f2c); //Serial.print("negativ = "); Serial.println(negativ);Serial.println(""); Serial.print("minus = "); Serial.println(minus);Serial.println(""); //Serial.print("E = "); Serial.print(E);Serial.println(""); //Serial.print("Z = "); Serial.print(Z);Serial.println(""); //Serial.print("H = "); Serial.print(H);Serial.println(""); //Serial.print("T = "); Serial.print(T);Serial.println(""); //Serial.print("frequenz = "); Serial.print(frequenz);Serial.println(""); //Serial.print("falt = "); Serial.print(falt);Serial.println(""); //Serial.print("fstopalt = "); Serial.print(fstopalt);Serial.println(""); //Serial.print("f = "); Serial.print(f);Serial.println(""); Serial.print("z = "); Serial.print(z);Serial.println(""); Serial.print("zaehler = "); Serial.print(zaehler);Serial.println(""); Serial.print("zalt = "); Serial.print(zalt);Serial.println(""); Serial.print("handanzeige = "); Serial.print(falt);Serial.println(""); delay(1000); } void stopp(){ diagnose(); delay(2000); exit(0); } void vala(){ Serial.print("vala3 = "); Serial.println (vala3); Serial.print("vala6 = "); Serial.println (vala6); Serial.print("vala7 = "); Serial.println (vala7); delay(2000); exit(0); } void ok(){ Serial.println("OK"); } void valatest(){ vala3 = analogRead(A3); vala6 = analogRead(A6); vala7 = analogRead(A7); vala1 = analogRead(A1); vala2 = analogRead(A2); int valD4 = digitalRead(inPin); Serial.print("vala3/A3 = ");Serial.print(vala3);Serial.print(" ");Serial.println("T, H, Z, E"); Serial.print("vala6/A6 = ");Serial.print(vala6);Serial.print(" ");Serial.println("hand, sweep,test, reset"); Serial.print("vala7/A7 = ");Serial.print(vala7);Serial.print(" ");Serial.println("fstop, fstart,hand, NC"); Serial.print("valA1 = ");Serial.print(vala1);Serial.print(" ");Serial.println("CL"); Serial.print("valA2 = ");Serial.print(vala2);Serial.print(" ");Serial.println("CR"); Serial.print("valD4 = ");Serial.print(valD4);Serial.print(" ");Serial.println("set"); } //void scannen(){ /* st1 = millis(); for(c=0; c<1001; c++){ yx =analogRead(A4); if(yx >= ya ) { ywert=yx; }else{ ywert=ya; } st2 = millis(); ya= ywert; } */ // Serial.print(st1);//= 9133 ms // Serial.print(" ");Serial.print(st2);Serial.print(" "); // Serial.println(ywert);//= 9133 ms // delay(300); exit(0); //12ms für 100 samples! 61ms für 500 samples //} /* // transfers a byte, a bit at a time, LSB first to the 9850 via serial DATA line void tfr_byte(byte data) { for (int i = 0; i < 8; i++, data >>= 1) { digitalWrite(DATA, data & 0x01); delay(1); pulseHigh(CLK); } } void sendFrequency(double frequency) { int32_t freq1 = frequency * 4294967295/125000000; // note 125 MHz clock on 9850 for (int b = 0; b < 4; b++, freq1 >>= 8) { tfr_byte(freq1 & 0xFF); delay(1); } tfr_byte(0x000); // Final control byte, all 0 for 9850 chip pulseHigh(FQ); delay(1);// } */ //zunächst der Drehknopf für die Eingabe der Werte(Zahlen 0 bis 29000) // macht bei Druck auf den Knopf auch den Harware-RESET //alte Version ohne Interrupt. Hat aber Probleme mit der Loop-Zeit /* //rotary BEGINN ------------------------------------------------------------ rotary 1 pin1 = digitalRead(4);//2 D2 für Pin S1 am Encoder pin4 if ((pin1 == 1 ) && (pin1Alt == 0 )) { //HIGH, LOW richtung = 0; if (digitalRead(5) == HIGH) { //HIGH Pin S2 am Encoder pin5 zaehler++; minus = 0; richtung = 2; } else { zaehler--; minus = 1; richtung = 1; } if (zaehler < 0){ zaehler = 0; negativ = 1; } z = zaehler; sichtbar = 1;// = Veränderung am ENCODER //delay(10); // Serial.println(minus); } pin1Alt = pin1; //--------------------------------------------------------------------------------------------- */ //eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee