FT817Serial/src/main.cpp

68 lines
1.3 KiB
C++
Raw Normal View History

2020-05-06 20:50:15 +00:00
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <FT817_NBS.h>
2020-05-06 20:50:15 +00:00
2020-05-07 21:17:49 +00:00
#define SET_FREQ 4
#define SWITCH_AB 5
SoftwareSerial radio = SoftwareSerial(2, 3);
FT817_NBS ft817(radio);
2020-05-06 20:50:15 +00:00
2020-05-07 21:17:49 +00:00
void setFreq();
2020-05-06 20:50:15 +00:00
void setup() {
// put your setup code here, to run once:
radio.begin(9600);
ft817 = FT817_NBS(radio);
Serial.begin(9600);
2020-05-07 21:17:49 +00:00
pinMode(SET_FREQ, INPUT_PULLUP);
pinMode(SWITCH_AB, INPUT_PULLUP);
2020-05-06 20:50:15 +00:00
}
2020-05-07 21:17:49 +00:00
boolean pressBlockSetFreq = false;
boolean pressBlockSwitchAB = false;
2020-05-06 20:50:15 +00:00
void loop() {
// put your main code here, to run repeatedly:
2020-05-07 21:17:49 +00:00
if (digitalRead(SET_FREQ) == LOW && !pressBlockSetFreq){
pressBlockSetFreq = true;
setFreq();
}
else if(digitalRead(SET_FREQ) != LOW){
pressBlockSetFreq = false;
}
if (digitalRead(SWITCH_AB) == LOW && !pressBlockSwitchAB){
ft817.toggleAB();
2020-05-07 21:17:49 +00:00
pressBlockSwitchAB = true;
}
else if(digitalRead(SWITCH_AB) != LOW){
pressBlockSwitchAB = false;
}
//String freq = Serial.readString();
}
void setFreq(){
unsigned long frequency = ft817.getFrequency().frequency;
2020-05-07 21:17:49 +00:00
if(frequency < 28850000){
Serial.println("Please go into the 70 cm Band!");
2020-05-07 21:17:49 +00:00
return;
}
delay(300);
unsigned long newFrequency = frequency - 28850000;
ft817.toggleAB();
delay(300);
2020-05-07 21:17:49 +00:00
ft817.setFrequency(newFrequency);
2020-05-07 21:17:49 +00:00
delay(300);
2020-05-07 21:17:49 +00:00
ft817.toggleAB();
}