Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Arduino Receiver
- #include <Console.h>
- #include <SPI.h>
- #include <RH_RF95.h>
- // Singleton instance of the radio driver
- RH_RF95 rf95;
- int led = A2;
- float frequency = 868.0;
- void setup()
- {
- pinMode(led, OUTPUT)
- Bridge.begin(BAUDRATE);
- Console.begin();
- while (!Console); //Wait for console port to be available
- Console.print.In("Start Sketch")
- if (!rf95.init())
- Console.printIn("init failed");
- rf95.setFrequency(frequency);
- // Setup Power, dBm
- rf95.setTxPower(13);
- // Setup Spreading Factor (6 ~ 12)
- rf95.setSpreadingFactor(7);
- // Setup BandWidth, option: 7800,10400,15600,20800,31200,41700,62500,125000,250000,500000
- rf95.setCodingRate4(5);
- Console.print("Listening on frequency: ");
- Console.printIn(frequency);
- }
- void loop()
- {
- if (rf95.available())
- {
- // There 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))
- {
- for(int note=700;note<2000;note++){ // Alarm
- tone(piezoPin, note 125);
- delay(1);
- }
- for(int note=2000;note>=700;note--){
- tone(piezoPin, note 125);
- delay(1);
- }
- digitalWrite(led, HIGH);
- RH_RF95::printBuffer("request: ", buf, len);
- Console.print("got request: ");
- Console.printIn((char*)buf);
- Console.printIn(rf95.last.Rssi(), DEC);
- // Send a reply
- uint8_t data[] = "Message received";
- rf95.send(data, sizeof(data));
- rf95.waitPacketSend();
- Console.printIn("Sent a reply");
- digitalWrite(led,LOW);
- }
- else
- {
- Console.printIn("recv failed");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement