Use OLED for screen. #8
78
src/main.cpp
78
src/main.cpp
|
@ -131,7 +131,7 @@ const long MAX_FREQ = 150000000;
|
|||
|
||||
//--------Si5351 Declaration---------------//
|
||||
|
||||
Si5351 si5351;
|
||||
Si5351 si5351(0x61);
|
||||
//SDA is on pin A4 for Arduino Uno
|
||||
//SCL is on pin A5 for Arduino Uno
|
||||
|
||||
|
@ -326,7 +326,8 @@ char getPermission(){
|
|||
|
||||
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");
|
||||
|
@ -336,6 +337,7 @@ void setup(){
|
|||
// Clear the buffer
|
||||
display.clearDisplay();
|
||||
display.drawPixel(10, 10, WHITE);
|
||||
display.display(); // Call this AFTER any drawing command.
|
||||
|
||||
// inialize LCD, display welcome message
|
||||
//lcd.begin(20, 4);
|
||||
|
@ -372,46 +374,46 @@ void setup(){
|
|||
}
|
||||
|
||||
void loop(){
|
||||
//if (displayNeedsUpdate) {displayInfo();}
|
||||
//delay(80);
|
||||
// //if (displayNeedsUpdate) {displayInfo();}
|
||||
// //delay(80);
|
||||
|
||||
//detect whether encoder has changed position
|
||||
long reading = encoder.read();
|
||||
long encoderChange = reading - encoderPosition;
|
||||
encoderPosition = reading;
|
||||
// //detect whether encoder has changed position
|
||||
// long reading = encoder.read();
|
||||
// long encoderChange = reading - encoderPosition;
|
||||
// encoderPosition = reading;
|
||||
|
||||
displayNeedsUpdate = false;
|
||||
// displayNeedsUpdate = false;
|
||||
|
||||
//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 = max(currFreq, MIN_FREQ); setFrequency_5351(currFreq); displayNeedsUpdate = true;}
|
||||
// //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 = max(currFreq, MIN_FREQ); setFrequency_5351(currFreq); displayNeedsUpdate = true;}
|
||||
|
||||
//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;}
|
||||
// //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;}
|
||||
|
||||
//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;}
|
||||
// //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;}
|
||||
|
||||
/*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,
|
||||
* just jump to the next higher band
|
||||
*/
|
||||
if (checkButtonPress(PIN_BUTTON_BAND)){
|
||||
int currBand = getCurrentBand();
|
||||
if (currBand >= 0){
|
||||
lastBandFreq[currBand] = currFreq;
|
||||
currFreq = lastBandFreq[(getCurrentBand() + 1) % NUM_BANDS];
|
||||
setFrequency_5351(currFreq);
|
||||
}
|
||||
else if (currBand == -2 || currBand == -3){
|
||||
currFreq = lastBandFreq[0];
|
||||
setFrequency_5351(currFreq);
|
||||
}
|
||||
else if (currBand == -1){
|
||||
for (int i = 0; i < NUM_BANDS; i++){
|
||||
if (currFreq < lastBandFreq[i]){currFreq = lastBandFreq[i]; setFrequency_5351(currFreq); break;}
|
||||
}
|
||||
}
|
||||
displayNeedsUpdate = true;
|
||||
}
|
||||
// /*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,
|
||||
// * just jump to the next higher band
|
||||
// */
|
||||
// if (checkButtonPress(PIN_BUTTON_BAND)){
|
||||
// int currBand = getCurrentBand();
|
||||
// if (currBand >= 0){
|
||||
// lastBandFreq[currBand] = currFreq;
|
||||
// currFreq = lastBandFreq[(getCurrentBand() + 1) % NUM_BANDS];
|
||||
// setFrequency_5351(currFreq);
|
||||
// }
|
||||
// else if (currBand == -2 || currBand == -3){
|
||||
// currFreq = lastBandFreq[0];
|
||||
// setFrequency_5351(currFreq);
|
||||
// }
|
||||
// else if (currBand == -1){
|
||||
// for (int i = 0; i < NUM_BANDS; i++){
|
||||
// if (currFreq < lastBandFreq[i]){currFreq = lastBandFreq[i]; setFrequency_5351(currFreq); break;}
|
||||
// }
|
||||
// }
|
||||
// displayNeedsUpdate = true;
|
||||
// }
|
||||
}
|
Loading…
Reference in New Issue
Block a user