Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
7c7d0e95db | ||
|
833bf317c7 |
|
@ -15,3 +15,5 @@ framework = arduino
|
||||||
lib_deps =
|
lib_deps =
|
||||||
etherkit/Etherkit Si5351@^2.1.4
|
etherkit/Etherkit Si5351@^2.1.4
|
||||||
paulstoffregen/Encoder@^1.4.4
|
paulstoffregen/Encoder@^1.4.4
|
||||||
|
adafruit/Adafruit GFX Library@^1.11.9
|
||||||
|
adafruit/Adafruit SSD1306@^2.5.9
|
||||||
|
|
98
src/main.cpp
98
src/main.cpp
|
@ -11,8 +11,18 @@
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
//#include <LiquidCrystal.h>
|
//#include <LiquidCrystal.h>
|
||||||
#include <si5351.h>
|
#include <si5351.h>
|
||||||
|
#include <Adafruit_GFX.h>
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
|
|
||||||
|
|
||||||
|
//----------- OLED ------------------
|
||||||
|
#define SCREEN_WIDTH 128 // OLED display width, in pixels
|
||||||
|
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
|
||||||
|
|
||||||
|
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
|
||||||
|
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
|
||||||
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||||
|
|
||||||
//----------- Variables & Declarations ---------------
|
//----------- Variables & Declarations ---------------
|
||||||
/*
|
/*
|
||||||
* The current and desired LISTENING FREQUENCY, which is not always the frequency being output by the Si5351.
|
* The current and desired LISTENING FREQUENCY, which is not always the frequency being output by the Si5351.
|
||||||
|
@ -121,7 +131,7 @@ const long MAX_FREQ = 150000000;
|
||||||
|
|
||||||
//--------Si5351 Declaration---------------//
|
//--------Si5351 Declaration---------------//
|
||||||
|
|
||||||
Si5351 si5351;
|
Si5351 si5351(0x61);
|
||||||
//SDA is on pin A4 for Arduino Uno
|
//SDA is on pin A4 for Arduino Uno
|
||||||
//SCL is on pin A5 for Arduino Uno
|
//SCL is on pin A5 for Arduino Uno
|
||||||
|
|
||||||
|
@ -315,6 +325,20 @@ char getPermission(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup(){
|
void setup(){
|
||||||
|
Serial.begin(9600); // This program won't work unless baud is 9600...why?
|
||||||
|
Serial.println("Start me up.");
|
||||||
|
|
||||||
|
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
|
||||||
|
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
|
||||||
|
Serial.println("SSD1306 allocation failed");
|
||||||
|
for(;;); // Don't proceed, loop forever
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear the buffer
|
||||||
|
display.clearDisplay();
|
||||||
|
display.drawPixel(10, 10, WHITE);
|
||||||
|
display.display(); // Call this AFTER any drawing command.
|
||||||
|
|
||||||
// inialize LCD, display welcome message
|
// inialize LCD, display welcome message
|
||||||
//lcd.begin(20, 4);
|
//lcd.begin(20, 4);
|
||||||
//delay(250);
|
//delay(250);
|
||||||
|
@ -350,46 +374,46 @@ void setup(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
//if (displayNeedsUpdate) {displayInfo();}
|
// //if (displayNeedsUpdate) {displayInfo();}
|
||||||
//delay(80);
|
// //delay(80);
|
||||||
|
|
||||||
//detect whether encoder has changed position
|
// //detect whether encoder has changed position
|
||||||
long reading = encoder.read();
|
// long reading = encoder.read();
|
||||||
long encoderChange = reading - encoderPosition;
|
// long encoderChange = reading - encoderPosition;
|
||||||
encoderPosition = reading;
|
// encoderPosition = reading;
|
||||||
|
|
||||||
displayNeedsUpdate = false;
|
// displayNeedsUpdate = false;
|
||||||
|
|
||||||
//step up or down or change step size, for either button presses or encoder turns
|
// //step up or down or change step size, for either button presses or encoder turns
|
||||||
if ((encoderChange > 0)){currFreq += steps[currMode][stepIndex]; currFreq = min(currFreq, MAX_FREQ); setFrequency_5351(currFreq); displayNeedsUpdate = true;}
|
// if ((encoderChange > 0)){currFreq += steps[currMode][stepIndex]; currFreq = min(currFreq, MAX_FREQ); setFrequency_5351(currFreq); displayNeedsUpdate = true;}
|
||||||
if ((encoderChange < 0)){currFreq -= steps[currMode][stepIndex]; currFreq = max(currFreq, MIN_FREQ); setFrequency_5351(currFreq); displayNeedsUpdate = true;}
|
// if ((encoderChange < 0)){currFreq -= steps[currMode][stepIndex]; currFreq = max(currFreq, MIN_FREQ); setFrequency_5351(currFreq); displayNeedsUpdate = true;}
|
||||||
|
|
||||||
//pressing the encoder button increments through the possible step sizes for each mode
|
// //pressing the encoder button increments through the possible step sizes for each mode
|
||||||
if (checkButtonPress(PIN_BUTTON_ENCODER)){stepIndex = (stepIndex + 1) % (NUM_STEP_OPTIONS[currMode]); displayNeedsUpdate = true;}
|
// if (checkButtonPress(PIN_BUTTON_ENCODER)){stepIndex = (stepIndex + 1) % (NUM_STEP_OPTIONS[currMode]); displayNeedsUpdate = true;}
|
||||||
|
|
||||||
//pressing the mode button cycles through the available modes
|
// //pressing the mode button cycles through the available modes
|
||||||
if (checkButtonPress(PIN_BUTTON_MODE)){currMode = (currMode+1) % NUM_MODES; stepIndex = 0; setFrequency_5351(currFreq); displayNeedsUpdate = true;}
|
// if (checkButtonPress(PIN_BUTTON_MODE)){currMode = (currMode+1) % NUM_MODES; stepIndex = 0; setFrequency_5351(currFreq); displayNeedsUpdate = true;}
|
||||||
|
|
||||||
/*The mode button: if currFreq is inside an amateur band, save that frequency as the one to return to when
|
// /*The mode button: if currFreq is inside an amateur band, save that frequency as the one to return to when
|
||||||
* the user returns to this band, and jump to the return frequency for the next higher band. Otherwise,
|
// * the user returns to this band, and jump to the return frequency for the next higher band. Otherwise,
|
||||||
* just jump to the next higher band
|
// * just jump to the next higher band
|
||||||
*/
|
// */
|
||||||
if (checkButtonPress(PIN_BUTTON_BAND)){
|
// if (checkButtonPress(PIN_BUTTON_BAND)){
|
||||||
int currBand = getCurrentBand();
|
// int currBand = getCurrentBand();
|
||||||
if (currBand >= 0){
|
// if (currBand >= 0){
|
||||||
lastBandFreq[currBand] = currFreq;
|
// lastBandFreq[currBand] = currFreq;
|
||||||
currFreq = lastBandFreq[(getCurrentBand() + 1) % NUM_BANDS];
|
// currFreq = lastBandFreq[(getCurrentBand() + 1) % NUM_BANDS];
|
||||||
setFrequency_5351(currFreq);
|
// setFrequency_5351(currFreq);
|
||||||
}
|
// }
|
||||||
else if (currBand == -2 || currBand == -3){
|
// else if (currBand == -2 || currBand == -3){
|
||||||
currFreq = lastBandFreq[0];
|
// currFreq = lastBandFreq[0];
|
||||||
setFrequency_5351(currFreq);
|
// setFrequency_5351(currFreq);
|
||||||
}
|
// }
|
||||||
else if (currBand == -1){
|
// else if (currBand == -1){
|
||||||
for (int i = 0; i < NUM_BANDS; i++){
|
// for (int i = 0; i < NUM_BANDS; i++){
|
||||||
if (currFreq < lastBandFreq[i]){currFreq = lastBandFreq[i]; setFrequency_5351(currFreq); break;}
|
// if (currFreq < lastBandFreq[i]){currFreq = lastBandFreq[i]; setFrequency_5351(currFreq); break;}
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
displayNeedsUpdate = true;
|
// displayNeedsUpdate = true;
|
||||||
}
|
// }
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user