good morning to all!
Good morning, I would like to know if anyone has experience in this matter.
vhf ptt trigger for relay control
the idea is that with a vhf band (118-136mhz) useful to receive PTT signals to the Rpi, then use Rpi to control a relay board. I have a device to control the track lights with GSM and it has been working excellent for three years, but I would like to be able to press the ptt of the radio 3 times and it closes the relay and with a contactor turns on the lights and then the relay opens turn off the lights after 30 minutes and be able to press the ptt of the radio 5 times and another relay to activate the ptt of the vhf and transmit the message atis and the relay opens or stop transmitting in 10 minutes to do so! I leave an example
Regarding the aeronautical authority, I am the head of the airport and pilot, for which I have the support and I can install it in a small private aerodrome.
PTTState
//constant value which will not change:
const int PTT = 6;
const int REL1 = 2;
const int REL2 = 3;
const int REL3 = 4;
const int REL4 = 5;
//values which will change:
int PTTState = 0;
int PTTPushCounter = 0;
int lastPTTState = 0;
unsigned long timeLastPush = 0; //Millisek. since last time PTT was pressed..
unsigned long timeOutPTT = 8000; // 2,0sek
void setup() {
pinMode(PTT,INPUT);
pinMode(REL1,OUTPUT);
pinMode(REL2,OUTPUT);
pinMode(REL3,OUTPUT);
pinMode(REL4,OUTPUT);
Serial.begin(9600);
Serial.println("PTT FUNCTION");
}
void loop() {
// read the pushbutton input pin:
PTTState = digitalRead(PTT);
// compare the PTTState to its previous state
if (PTTState != lastPTTState && lastPTTState == 0) { //If changed PTT state AND lastPTTState = 0,
if ((millis() - timeLastPush) > timeOutPTT ) { //If timeout-limit for PTT reached:
timeLastPush = millis(); //Set new timecouter start now,
PTTPushCounter = 0; //Set PTT counter to 0.
}
// if the state has changed, increment the counter
if (PTTState == HIGH) {
// if the current state is HIGH then the PTT went from off to on:
PTTPushCounter++;
Serial.println("on");
Serial.print("number of PTT pushes: ");
Serial.println(PTTPushCounter);
} else {
// if the current state is LOW then the PTT went from on to off:
Serial.println("off");
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
lastPTTState = PTTState;
if (PTTPushCounter % 4 == 3) {
digitalWrite(REL1, HIGH);
}
if (PTTPushCounter % 6 == 5) {
digitalWrite(REL2,HIGH);
}
if (PTTPushCounter % 8 == 7) {
digitalWrite(REL3,HIGH);
}
if (PTTPushCounter % 10 == 9) {
digitalWrite(REL4,HIGH);
}
else if (PTTPushCounter == 10) {
digitalWrite(REL1,LOW);
digitalWrite(REL2,LOW);
digitalWrite(REL3,LOW);
digitalWrite(REL4,LOW);
}
}