Get display to minimally work.

This commit is contained in:
mattbk 2024-01-26 08:59:34 -06:00
parent 833bf317c7
commit 7c7d0e95db

View File

@ -131,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
@ -326,7 +326,8 @@ char getPermission(){
void setup(){ void setup(){
Serial.begin(9600); // This program won't work unless baud is 9600...why? 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 // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("SSD1306 allocation failed"); Serial.println("SSD1306 allocation failed");
@ -336,6 +337,7 @@ void setup(){
// Clear the buffer // Clear the buffer
display.clearDisplay(); display.clearDisplay();
display.drawPixel(10, 10, WHITE); 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);
@ -372,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;
} // }
} }