// NL // Voorbeeld code voor sturing van de Uni-Tx met een arduino bordje rgk 2013 // Dit is geen compleet programma, alleen een voorbeeld van instellen van de SP5055 synthesiser chip // in een arduino omgeving // Het arduino bord moet over een I2C interface beschikken. Let op, niet bij alle arduino's zit dit // op dezelfde pinnen. // LCD is een 4-bits 44780 display aangesloten op een uno bord. // Afstemmen geschiedt met een goedkope gray-code rotary encoder(Van Dijken) // UK // Example of a simple program to control the Uni-Tx with an Arduino board. rgk2016 // Its not a complete program ,just an example how to set the SP5055 synthesiser chip with arduino. // The board should have a I2C interface, the pinning may differ on the various Arduino boards, I used // an UNO board, with standard 4-bits LCD (44780 compatible) // For tuning a low-cost gray-coded rotary encoder is used. // **************** // include the library code: #include #include #include #define EE_defaults 0 #define EE_freq 2 const int Rot_A = 2; const int Rot_B = 3; const int Rot_enter = 4; int rotary; int up; int freq; int freq_old; unsigned long tijd; unsigned char sp5055 = 0x61;// het i2c adres van de SP5055 moet in 7 bits notatie!!! d.i. (normaal>>1) // initialize the library with the numbers of the interface pins //LiquidCrystal lcd(22, 23,24, 25, 26, 27); LiquidCrystal lcd(A0,A1,A2,A3,6,7);//uno rgk void setup() { tijd=0; // set up the LCD's number of columns and rows: lcd.begin(16, 2); Wire.begin(); // Print a message to the LCD. lcd.print(" * Uni-Tx demo *"); lcd.setCursor(0,1); lcd.print(" Freq: MHz"); // eeprom initialisatie bij een lege eeprom if(EEPROM.read(EE_defaults)!=0xAA){ EEPROM.write(EE_defaults,0xAA); EEPROM.put(EE_freq,1248); } // External Interrupt 0 service routine attachInterrupt(digitalPinToInterrupt(Rot_A), read_rot, FALLING); // Hier wordt de waarde ingelezen die de Tx de vorige keer had zodat hij opkomt in de "oude" stand EEPROM.get(EE_freq,freq); freq_old=freq; toon(freq); } void loop() { freq=rot_update(freq,1240,1300); if(freq_old!=freq){// alleen als er iets veranderd is naar de afstem en display routine gaan. set_syn(freq); toon(freq); freq_old=freq; tijd=millis(); } if(millis()-tijd>5000){// pas na 5 sec nieuwe waarde opslaan, niet onnodig in eeprom schrijven. EEPROM.put(EE_freq,freq); tijd=millis(); } } void toon(int freq) { lcd.setCursor(7, 1); lcd.print(freq); } void read_rot()// interrupt_0 afhandeling { rotary = 1; up = digitalRead(Rot_B); // de rotary encoder hangt aan d2 en d3 } int rot_update(int var,int min,int max) // managen van de variabelen die met rotary instelbaar zijn { noInterrupts(); if(rotary) { rotary = 0; if(up) var +=1; else var -=1; } if(var>max) var=min; if(var