I have an Adafruit feather 32u4 LoRa transmitter, I want to make a digital Morse transmitter, I took the transmission code from the internet and decided to write my own code for the rest. The two transistors transmit to each other but the micro don sees my input buttons.
int StatoPrecP2 = 0;
int i;
char SendData;
void loop()
{
switch (Stato) {
StatoAttP1 = digitalRead(P_Riga);
StatoAttP2 = digitalRead (P_Punto);
case 0:
if (StatoAttP1 == 1) /*&& (StatoPrecP1 != StatoAttP1 )) */{
digitalWrite(ButtonRecived, HIGH);
delay (250);
digitalWrite(ButtonRecived, LOW);
Stato = 1;
SendData = ".";
}
if ((StatoAttP2 == 1) && (StatoPrecP2 != StatoAttP1)) {
digitalWrite(ButtonRecived, 1);
delay (250);
digitalWrite(ButtonRecived, 0);
Stato = 1;
SendData = "-";
}
if (rf95.available())
{
// Should be a message for us now
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf95.recv(buf, &len))
{
digitalWrite(LED, HIGH);
RH_RF95::printBuffer("Received: ", buf, len);
Serial.print("Got: ");
Serial.println((char*)buf);
Serial.print("RSSI: ");
Serial.println(rf95.lastRssi(), DEC);
if (*buf = ".") {
PORTF = PORTF | 0x20;
delay(1000);
PORTF = PORTF & ~0x20;
}
else if (*buf = "-") {
PORTF = PORTF | 0x20;
delay(2500);
PORTF = PORTF & ~0x20;
}
}
else
{
Serial.println("Receive failed");
}
case 1:
// Send a reply
for (i = 0; i < 5000; i++) {
uint8_t data = SendData;
rf95.send(data, sizeof(data));
rf95.waitPacketSent();
Serial.println("Sent a reply");
digitalWrite(LED, LOW);
if ((StatoAttP1 = 1) & (StatoAttP1 != StatoPrecP1)) {
PORTF = PORTF | 0x10;
delay (250);
PORTF = PORTF & ~0x10;
Stato = 1;
uint8_t data[] = ".";
i = 0;
}
else if ((StatoAttP2 = 1) & (StatoAttP2 != StatoPrecP2)) {
PORTF = PORTF | 0x10;
delay (250);
PORTF = PORTF & ~0x10;
Stato = 1;
uint8_t data[] = "-";
i = 0;
}
delay (1);
}
Stato = 0;
}
}
StatoPrecP1 = StatoAttP1;
StatoPrecP2 = StatoAttP2;
}