I have this binary switch (10 pos) based on a encoder which works fine for its purpose
(selecting bcd input to a ham radio transceivers PLL(phase lock loop BCD weighted lines) for selecting correct frequencies )
it out puts the channel number to a tm1637 display (1-10 in decimal) .
what I want to do is add a scan feature so it steps up the "channels" one by one then cycle around back to channel 1 and back on up to ch 10 and so on till A5 goes high (will receive a high from the radios squelch line when the squelch is open receives a signal via a gate buffer in the radio)
So what I am asking is anyone got a snippet of code i can insert into my existing code to start increment of channels when a switch is activated on A6 (used as a digital pin with pullup) until detects a HIGH on A5 (the squelch gate line) and stops at that "channel"
I am fairly new to arduino coding and this below is one of my first real attempts at atmega
digital pins d2-d12 are used for pll bcd weighting (portB and D) encoding
pins A0-A4 are used for the display and encoder
the reset pin sends the radio back to ch 5 when encoder button is pressed (home channel) ..of course when powered up the radio starts up on ch5
please forgive for my rubbish coding in advance !
#include <RotaryEncoder.h>
#include <Arduino.h>
#include <TM1637Display.h>
#define Steps 1
#define Min 1
#define Max 10
// Module connection pins (Digital Pins)
#define CLK A0 //TM1637
#define DIO A1 //TM1637
// The amount of time (in milliseconds) between tests
int lastPos = -1;
RotaryEncoder encoder(A2, A3); //(A2= CLK,A3 = DT)
TM1637Display display(CLK, DIO);
void setup() {
Serial.begin(9600);
Serial.println("Encoder Position");
encoder.setPosition(5 / Steps); // start with the value of 5
}
void loop() {
int k;
uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
uint8_t blank[] = { 0x00, 0x00, 0x00, 0x00 };
display.setBrightness(0x05);
encoder.tick();
// get the current physical position and calc the logical position
int newPos = encoder.getPosition() * Steps;
if (newPos < Min) {
encoder.setPosition(Max / Steps);
newPos = Max;
} else if (newPos > Max) {
encoder.setPosition(Min / Steps);
newPos = Min;
}
if (lastPos != newPos) {
Serial.print(newPos);
Serial.println();
lastPos = newPos;
}
//send data to pins
switch (newPos) {
case 1:
//PLL OUTPUTS
PORTD = B10000100;
PORTB = B000010;
// displayed number
display.showNumberDec(1); // Expect: ___1
break;
case 2:
//PLL OUTPUTS
PORTD = B10001000;
PORTB = B000010;
// displayed number
display.showNumberDec(2); // Expect: ___2
break;
case 3:
//PLL OUTPUTS
PORTD = B10001100;
PORTB = B000010;
// displayed number
display.showNumberDec(3); // Expect: ___3
break;
case 4:
//PLL OUTPUTS
PORTD = B10010100;
PORTB = B000010;
// displayed number
display.showNumberDec(4); // Expect: ___4
break;
case 5:
//PLL OUTPUTS
PORTD = B10011000;
PORTB = B000010;
// displayed number
display.showNumberDec(5); // Expect: ___5
break;
case 6:
//PLL OUTPUTS
PORTD = B10011100;
PORTB = B000010;
// displayed number
display.showNumberDec(6); // Expect: ___6
break;
case 7:
//PLL OUTPUTS
PORTD = B11100000;
PORTB = B000010;
// displayed number
display.showNumberDec(7); // Expect: ___7
break;
case 8:
//PLL OUTPUTS
PORTD = B00000000;
PORTB = B000100;
// displayed number
display.showNumberDec(8); // Expect: ___8
break;
case 9:
//PLL OUTPUTS
PORTD = B00000100;
PORTB = B000100;
// displayed number
display.showNumberDec(9); // Expect: ___9
break;
case 10:
//PLL OUTPUTS
PORTD = B00001000;
PORTB = B000100;
// displayed number
display.showNumberDec(10); // Expect: ___10
break;
}
}