How do I attach files to my code?

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

How do I attach files to my code?

Post by animefruit »

Hello.

This is Neal, I do Arduino projects.

I have a working code that makes this servo move after the pezio sensors are pressed too much.
My code for that is here:

Code: Select all

 #include <Servo.h>
#include "Wire.h"
#include "Adafruit_LiquidCrystal.h"
 
 
#define LED 13// FOR LED
 
 
 
Adafruit_LiquidCrystal lcd(0);
 
Servo myservo1;
Servo myservo2;
 
//cant do A4 and A5(they are for lcd)
// Analogs 0 to 5
const int knockSensor = A0;
const int knockSensor1= A1;
const int knockSensor2= A2;
const int knockSensor3= A3;
const int knockSensor4= A6;
const int knockSensor5= A7;
 
 
const int threshold = 10;
int health = 500;
 
// 6 total sensor readings (from 0 to 5)
 
int sensorReading = 0;
int sensorReading1 =0;
int sensorReading2 =0;
int sensorReading3 =0;
int sensorReading4 =0;
int sensorReading5 =0;
 
 
int pos =0;
 
 
 
int deaths=1;// gonna be number of deaths
 
 
 
void setup()
 
{
 // pinMode(LED_BUILTIN, OUTPUT); //LED ON ARDUINO
  pinMode(LED, OUTPUT);//FOR LED
 
  Serial.begin(9600);
  Serial.println("Nerf Target v0.0.1, github.com/mcoms/nerf-target, 2014.");
 
// sg90
 
  lcd.begin (20 , 4);
  lcd.clear();
 
 
  Serial.begin(9600);
  myservo1.attach(9);
  myservo1.write(0);//was 0
 
  myservo2.attach(10);
  myservo2.write(45);//was 179
 
 
 
 
}
 
void loop()
{
  do
  {
 
 
    myservo1.detach();
    myservo2.detach();
 
    sensorReading = analogRead(knockSensor);
   
 
    lcd.setCursor(0, 1);
    Serial.println(health);
    lcd.println(health);
 
    if (sensorReading > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading;
 
     
     
      Serial.print(sensorReading);
      lcd.print(sensorReading);
 
 
      int sensorValue = analogRead(A0);
 
      Serial.println(sensorValue);
 
 
     
     
 
 
     
      delay(1);
 
    }
 
//duplicate
 
sensorReading1= analogRead(knockSensor1);
 
 if (sensorReading1 > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading1;
 
     
     
      Serial.print(sensorReading1);
      lcd.print(sensorReading1);
 
 
      int sensorValue = analogRead(A1);
 
      Serial.println(sensorValue);
 
 
      delay(1);
 
    }
 
 
 
//duplicate
 
sensorReading2= analogRead(knockSensor2);
 
 if (sensorReading2 > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading2;
 
     
     
      Serial.print(sensorReading2);
      lcd.print(sensorReading2);
 
 
      int sensorValue = analogRead(A2);
 
      Serial.println(sensorValue);
 
 
      delay(1);
 
    }
 
 
 
 
//duplicate
 
sensorReading3= analogRead(knockSensor3);
 
 if (sensorReading3 > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading3;
 
     
     
      Serial.print(sensorReading3);
      lcd.print(sensorReading3);
 
 
      int sensorValue = analogRead(A3);
 
      Serial.println(sensorValue);
 
 
      delay(1);
 
    }
 
 
 
//duplicate
 
 
 
sensorReading4= analogRead(knockSensor4);
 
 if (sensorReading4 > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading4;
 
     
     
      Serial.print(sensorReading4);
      lcd.print(sensorReading4);
 
 
      int sensorValue = analogRead(A6);
 
      Serial.println(sensorValue);
 
 
      delay(1);
 
    }
 
 
 
//duplicate
 
sensorReading5= analogRead(knockSensor5);
 
 if (sensorReading5 > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading5;
 
     
     
      Serial.print(sensorReading5);
      lcd.print(sensorReading5);
 
 
      int sensorValue = analogRead(A7);
 
      Serial.println(sensorValue);
 
 
      delay(1);
 
    }
 
 
 
 
 
 
 
  } while (health > 1);
 
 
 
  digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);//was 2000             // FOR LED IN ARDUINO
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
 
 
  /*
digitalWrite(LED, HIGH);
delay(2000);                 //FOR LED
digitalWrite(LED, HIGH);
delay(1000);
 */
  myservo1.attach(9);
  myservo2.attach(10);
 
  delay(15);
 //Servo Starts Moving Here
 for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);    // waits 15 ms for the servo to reach the position
 
 //Servo Stops Moving Here
  }
 
 delay(1000);
 
 
 lcd.setCursor(0, 2);
      Serial.println(deaths); //showind number of deaths on the lcd
      lcd.println(deaths);
 
 
deaths= deaths + 1;// adding deaths
 
 
 
 
 
 
 
  health = 500;
}
 
  
Now I have 2 Arduino Nanos that do the code above.
A RFM69HCW radio is connected to each Arduino Nano.
What I am trying to do is when the servo moves I want it to send a message into to the other Arduino.
I am trying to do this with file tabs in this code:

One Tab shows the original code that calls what I name the "radio_setuprxtx" code which is basically "RadioHead69_RawDemoTXRX OLED" example code here:

Code: Select all

 #include "radio_setuprxtx.h"

#include <Servo.h>
#include "Wire.h"
#include "Adafruit_LiquidCrystal.h"
 
 
#define LED 13// FOR LED
 
 
 
Adafruit_LiquidCrystal lcd(0);
 
Servo myservo1;
Servo myservo2;
 
//cant do A4 and A5(they are for lcd)
// Analogs 0 to 5
const int knockSensor = A0;
const int knockSensor1= A1;
const int knockSensor2= A2;
const int knockSensor3= A3;
const int knockSensor4= A6;
const int knockSensor5= A7;
 
 
const int threshold = 10;
int health = 500;
 
// 6 total sensor readings (from 0 to 5)
 
int sensorReading = 0;
int sensorReading1 =0;
int sensorReading2 =0;
int sensorReading3 =0;
int sensorReading4 =0;
int sensorReading5 =0;
 
 
int pos =0;
 
 
 
//int deaths=1;// gonna be number of deaths
 
 
 
void setup()
 
{
 // pinMode(LED_BUILTIN, OUTPUT); //LED ON ARDUINO
  pinMode(LED, OUTPUT);//FOR LED
 
  Serial.begin(9600);
  Serial.println("Nerf Target v0.0.1, github.com/mcoms/nerf-target, 2014.");
 
// sg90
 
 // lcd.begin (20 , 4);
 // lcd.clear();
 
 
  Serial.begin(9600);
  myservo1.attach(9);
  myservo1.write(0);//was 0
 
  myservo2.attach(10);
  myservo2.write(45);//was 179
 
 
 
 
}
 
void loop()
{
  do
  {
 
 
    myservo1.detach();
    myservo2.detach();
 
    sensorReading = analogRead(knockSensor);
   
 
    lcd.setCursor(0, 1);
    Serial.println(health);
    lcd.println(health);
 
    if (sensorReading > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading;
 
     
     
      Serial.print(sensorReading);
      //lcd.print(sensorReading);
 
 
      int sensorValue = analogRead(A0);
 
      Serial.println(sensorValue);
 
 
     
     
 
 
     
      delay(1);
 
    }
 
//duplicate
 
sensorReading1= analogRead(knockSensor1);
 
 if (sensorReading1 > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading1;
 
     
     
      Serial.print(sensorReading1);
    //  lcd.print(sensorReading1);
 
 
      int sensorValue = analogRead(A1);
 
      Serial.println(sensorValue);
 
 
      delay(1);
 
    }
 
 
 
//duplicate
 
sensorReading2= analogRead(knockSensor2);
 
 if (sensorReading2 > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading2;
 
     
     
      Serial.print(sensorReading2);
    //  lcd.print(sensorReading2);
 
 
      int sensorValue = analogRead(A2);
 
      Serial.println(sensorValue);
 
 
      delay(1);
 
    }
 
 
 
 
//duplicate
 
sensorReading3= analogRead(knockSensor3);
 
 if (sensorReading3 > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading3;
 
     
     
      Serial.print(sensorReading3);
     // lcd.print(sensorReading3);
 
 
      int sensorValue = analogRead(A3);
 
      Serial.println(sensorValue);
 
 
      delay(1);
 
    }
 
 
 
//duplicate
 
 
 
sensorReading4= analogRead(knockSensor4);
 
 if (sensorReading4 > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading4;
 
     
     
      Serial.print(sensorReading4);
    //  lcd.print(sensorReading4);
 
 
      int sensorValue = analogRead(A6);
 
      Serial.println(sensorValue);
 
 
      delay(1);
 
    }
 
 
 
//duplicate
 
sensorReading5= analogRead(knockSensor5);
 
 if (sensorReading5 > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading5;
 
     
     
      Serial.print(sensorReading5);
      //lcd.print(sensorReading5);
 
 
      int sensorValue = analogRead(A7);
 
      Serial.println(sensorValue);
 
 
      delay(1);
 
    }
 
 
 
 
 
 
 
  } while (health > 1);
 

 
 
  digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);//was 2000             // FOR LED IN ARDUINO
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
 
 
  /*
digitalWrite(LED, HIGH);
delay(2000);                 //FOR LED
digitalWrite(LED, HIGH);
delay(1000);
 */
  myservo1.attach(9);
  myservo2.attach(10);
 
  delay(15);
 //Servo Starts Moving Here
 for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);    // waits 15 ms for the servo to reach the position
 
 //Servo Stops Moving Here
  }
 
 delay(1000);
 
 
 //lcd.setCursor(0, 2);
      //Serial.println(deaths); //showind number of deaths on the lcd
      //lcd.println(deaths);
 
 
//deaths= deaths + 1;// adding deaths
 
 
 
 
 radio_setuprxtx(); // My Code that Calls the Radio Code
 
 
  health = 500;



  
}
 
   
Another tab is the code called the "radio_setuprxtx" which is the code that the above code calls.
Here it is:

Code: Select all

 #include <SPI.h>
#include <RH_RF69.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

/************ OLED Setup ***************/
Adafruit_SSD1306 oled = Adafruit_SSD1306();

#if defined(ESP8266)
  #define BUTTON_A 0
  #define BUTTON_B 16
  #define BUTTON_C 2
  #define LED      0
#elif defined(ESP32)
  #define BUTTON_A 15
  #define BUTTON_B 32
  #define BUTTON_C 14
  #define LED      13
#elif defined(ARDUINO_STM32F2_FEATHER)
  #define BUTTON_A PA15
  #define BUTTON_B PC7
  #define BUTTON_C PC5
  #define LED PB5
#elif defined(TEENSYDUINO)
  #define BUTTON_A 4
  #define BUTTON_B 3
  #define BUTTON_C 8
  #define LED 13
#elif defined(ARDUINO_NRF52832_FEATHER)
  #define BUTTON_A 31
  #define BUTTON_B 30
  #define BUTTON_C 27
  #define LED 17
#else // 32u4, M0, and 328p
  #define BUTTON_A 9
  #define BUTTON_B 6
  #define BUTTON_C 5
  #define LED      13
#endif


/************ Radio Setup ***************/

// Change to 434.0 or other frequency, must match RX's freq!
//#define RF69_FREQ 915.0
#define RF69_FREQ 434.0
#if defined (__AVR_ATmega32U4__) // Feather 32u4 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     7
  #define RFM69_RST     4
#endif

#if defined(ARDUINO_SAMD_FEATHER_M0) // Feather M0 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     3
  #define RFM69_RST     4
#endif

#if defined (__AVR_ATmega328P__)  // Feather 328P w/wing
  #define RFM69_INT     3  // 
  #define RFM69_CS      4  //
  #define RFM69_RST     2  // "A"
#endif

#if defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) || defined(ARDUINO_NRF52840_FEATHER) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
  #define RFM69_INT     9  // "A"
  #define RFM69_CS      10  // "B"
  #define RFM69_RST     11  // "C"
  #define LED           13

#elif defined(ESP32)    // ESP32 feather w/wing
  #define RFM69_RST     13   // same as LED
  #define RFM69_CS      33   // "B"
  #define RFM69_INT     27   // "A"
#endif

#if defined(ARDUINO_NRF52832_FEATHER)
  /* nRF52832 feather w/wing */
  #define RFM69_RST     7   // "A"
  #define RFM69_CS      11   // "B"
  #define RFM69_INT     31   // "C"
  #define LED           17
#endif

// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);

void setup() 
{
  delay(500);
  Serial.begin(115200);
  //while (!Serial) { delay(1); } // wait until serial console is open, remove if not tethered to computer

  // Initialize OLED display
  oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
  oled.display();
  delay(500);
  oled.clearDisplay();
  oled.display();

  pinMode(BUTTON_A, INPUT_PULLUP);
  pinMode(BUTTON_B, INPUT_PULLUP);
  pinMode(BUTTON_C, INPUT_PULLUP);

  pinMode(LED, OUTPUT);     
  pinMode(RFM69_RST, OUTPUT);
  digitalWrite(RFM69_RST, LOW);

  Serial.println("Feather RFM69 RX/TX Test!");

  // manual reset
  digitalWrite(RFM69_RST, HIGH);
  delay(10);
  digitalWrite(RFM69_RST, LOW);
  delay(10);
  
  if (!rf69.init()) {
    Serial.println("RFM69 radio init failed");
    while (1);
  }
  Serial.println("RFM69 radio init OK!");
  
  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)
  // No encryption
  if (!rf69.setFrequency(RF69_FREQ)) {
    Serial.println("setFrequency failed");
  }

  // If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the
  // ishighpowermodule flag set like this:
  rf69.setTxPower(14, true);

  // The encryption key has to be the same as the one in the server
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);
  
  pinMode(LED, OUTPUT);

  Serial.print("RFM69 radio @");  Serial.print((int)RF69_FREQ);  Serial.println(" MHz");

  // OLED text display tests
  oled.setTextSize(2);
  oled.setTextColor(WHITE);
  oled.setCursor(0,0);
  oled.println("RFM69 @ ");
  oled.print((int)RF69_FREQ);
  oled.println(" MHz");
  oled.display();

  delay(500);
}


void loop()
{  if (rf69.waitAvailableTimeout(100)) {
    // Should be a message for us now   
    uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
    
    if (! rf69.recv(buf, &len)) {
      Serial.println("Receive failed");
      return;
    }
    digitalWrite(LED, HIGH);
    rf69.printBuffer("Received: ", buf, len);
    buf[len] = 0;
    
    Serial.print("Got: "); Serial.println((char*)buf);
    Serial.print("RSSI: "); Serial.println(rf69.lastRssi(), DEC);

    oled.clearDisplay();
    oled.setCursor(0,0);
    oled.println((char*)buf);
    oled.print("RSSI: "); oled.print(rf69.lastRssi());
    oled.display(); 
    digitalWrite(LED, LOW);
  }

  if (!digitalRead(BUTTON_A) || !digitalRead(BUTTON_B) || !digitalRead(BUTTON_C))
  {
    Serial.println("Button pressed!");
    
    char radiopacket[20] = "Button #";
    if (!digitalRead(BUTTON_A)) radiopacket[8] = 'A';
    if (!digitalRead(BUTTON_B)) radiopacket[8] = 'B';
    if (!digitalRead(BUTTON_C)) radiopacket[8] = 'C';
    radiopacket[9] = 0;

    Serial.print("Sending "); Serial.println(radiopacket);
    rf69.send((uint8_t *)radiopacket, strlen(radiopacket));
    rf69.waitPacketSent();
  }
} 

Then there is another tab that is just the top part of the "radio_setuprxtx" code and is called "radio_setuprxtx.h"
Here it is:

Code: Select all

 #include <SPI.h>
#include <RH_RF69.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

/************ OLED Setup ***************/
Adafruit_SSD1306 oled = Adafruit_SSD1306();

#if defined(ESP8266)
  #define BUTTON_A 0
  #define BUTTON_B 16
  #define BUTTON_C 2
  #define LED      0
#elif defined(ESP32)
  #define BUTTON_A 15
  #define BUTTON_B 32
  #define BUTTON_C 14
  #define LED      13
#elif defined(ARDUINO_STM32F2_FEATHER)
  #define BUTTON_A PA15
  #define BUTTON_B PC7
  #define BUTTON_C PC5
  #define LED PB5
#elif defined(TEENSYDUINO)
  #define BUTTON_A 4
  #define BUTTON_B 3
  #define BUTTON_C 8
  #define LED 13
#elif defined(ARDUINO_NRF52832_FEATHER)
  #define BUTTON_A 31
  #define BUTTON_B 30
  #define BUTTON_C 27
  #define LED 17
#else // 32u4, M0, and 328p
  #define BUTTON_A 9
  #define BUTTON_B 6
  #define BUTTON_C 5
  #define LED      13
#endif


/************ Radio Setup ***************/

// Change to 434.0 or other frequency, must match RX's freq!
//#define RF69_FREQ 915.0
#define RF69_FREQ 434.0
#if defined (__AVR_ATmega32U4__) // Feather 32u4 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     7
  #define RFM69_RST     4
#endif

#if defined(ARDUINO_SAMD_FEATHER_M0) // Feather M0 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     3
  #define RFM69_RST     4
#endif

#if defined (__AVR_ATmega328P__)  // Feather 328P w/wing
  #define RFM69_INT     3  // 
  #define RFM69_CS      4  //
  #define RFM69_RST     2  // "A"
#endif

#if defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) || defined(ARDUINO_NRF52840_FEATHER) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
  #define RFM69_INT     9  // "A"
  #define RFM69_CS      10  // "B"
  #define RFM69_RST     11  // "C"
  #define LED           13

#elif defined(ESP32)    // ESP32 feather w/wing
  #define RFM69_RST     13   // same as LED
  #define RFM69_CS      33   // "B"
  #define RFM69_INT     27   // "A"
#endif

#if defined(ARDUINO_NRF52832_FEATHER)
  /* nRF52832 feather w/wing */
  #define RFM69_RST     7   // "A"
  #define RFM69_CS      11   // "B"
  #define RFM69_INT     31   // "C"
  #define LED           17
#endif

// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);  

I do get errors but I would rather like to know if I am doing this right or not.
This is one of my first code that I am using multiple files inside it.
Can you tell me if I am doing this right?

I also have a picture so you know what I mean by multiple files being in my code.
Those multiple files are the tabs on top of the code in the image.
Attachments
Original Code with Radio File Picture.PNG
Original Code with Radio File Picture.PNG (22.96 KiB) Viewed 285 times

User avatar
dastels
 
Posts: 15666
Joined: Tue Oct 20, 2015 3:22 pm

Re: How do I attach files to my code?

Post by dastels »

You need to explicit #include headers that you want to reference. Being in the same directory (and hence in another tab) isn't enough.

Dave

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I attach files to my code?

Post by animefruit »

Ok. I did so.

I used #include in my code now.

Here is a picture of some of what I did in the beginning of my code for using the #include:

I should turn the “.ino” files into “.h” files though.
Attachments
70988B02-C666-4F49-8878-CB01B6A4F381.jpeg
70988B02-C666-4F49-8878-CB01B6A4F381.jpeg (222.55 KiB) Viewed 257 times

User avatar
dastels
 
Posts: 15666
Joined: Tue Oct 20, 2015 3:22 pm

Re: How do I attach files to my code?

Post by dastels »

There should be only one ino file. That's what Arduino annoyingly insists on using for the "main" file. Any other files containing C++ code should have a suffix of cpp and any header files should have a suffix of h. See https://en.wikibooks.org/wiki/C%2B%2B_P ... ganization for a discussion of these.

Dave

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I attach files to my code?

Post by animefruit »

Ok. I did so.

It all works better now.

The problem was that there were multiple files that had the same name.

I just had to rename them.

Before than I was giving you code that I copied and pasted from each tab from another code I tried to save, so it didn't have .h files.

Now when I used the code I saved after I renamed the files with the same name, it worked!

Now I would like to include my original code into this radio code I am using.

Here is my original code:

Code: Select all

  #include <Servo.h>
#include "Wire.h"
#include "Adafruit_LiquidCrystal.h"


#define LED 13// FOR LED



Adafruit_LiquidCrystal lcd(0);

Servo myservo1;
Servo myservo2;

//cant do A4 and A5(they are for lcd)
// Analogs 0 to 5
const int knockSensor = A0;
const int knockSensor1= A1;
const int knockSensor2= A2;
const int knockSensor3= A3;
const int knockSensor4= A6;
const int knockSensor5= A7;


const int threshold = 0;
int health = 500;

// 6 total sensor readings (from 0 to 5)

int sensorReading = 0;
int sensorReading1 =0;
int sensorReading2 =0;
int sensorReading3 =0;
int sensorReading4 =0;
int sensorReading5 =0;


int pos =0;



int deaths=1;// gonna be number of deaths



void setup()

{
 // pinMode(LED_BUILTIN, OUTPUT); //LED ON ARDUINO
  pinMode(LED, OUTPUT);//FOR LED

  Serial.begin(9600);
  Serial.println("Nerf Target v0.0.1, github.com/mcoms/nerf-target, 2014.");

// sg90

  lcd.begin (20 , 4);
  lcd.clear();


  Serial.begin(9600);
  myservo1.attach(9);
  myservo1.write(0);//was 0

  myservo2.attach(10);
  myservo2.write(45);//was 179




}

void loop()
{
  do
  {


    myservo1.detach();
    myservo2.detach();

    sensorReading = analogRead(knockSensor);
    

    lcd.setCursor(0, 1);
    Serial.println(health);
    lcd.println(health);

    if (sensorReading > threshold) {

      Serial.println("Knock!");
      health = health - sensorReading;

      
      
      Serial.print(sensorReading);
      lcd.print(sensorReading);


      int sensorValue = analogRead(A0);

      Serial.println(sensorValue);


      
      


      
      delay(1);

    }

//duplicate 

sensorReading1= analogRead(knockSensor1);

 if (sensorReading1 > threshold) {

      Serial.println("Knock!");
      health = health - sensorReading1;

      
      
      Serial.print(sensorReading1);
      lcd.print(sensorReading1);


      int sensorValue = analogRead(A1);

      Serial.println(sensorValue);


      delay(1);

    }

  

//duplicate

sensorReading2= analogRead(knockSensor2);

 if (sensorReading2 > threshold) {

      Serial.println("Knock!");
      health = health - sensorReading2;

      
      
      Serial.print(sensorReading2);
      lcd.print(sensorReading2);


      int sensorValue = analogRead(A2);

      Serial.println(sensorValue);


      delay(1);

    }


 

//duplicate 

sensorReading3= analogRead(knockSensor3);

 if (sensorReading3 > threshold) {

      Serial.println("Knock!");
      health = health - sensorReading3;

      
      
      Serial.print(sensorReading3);
      lcd.print(sensorReading3);


      int sensorValue = analogRead(A3);

      Serial.println(sensorValue);


      delay(1);

    }

 

//duplicate 



sensorReading4= analogRead(knockSensor4);

 if (sensorReading4 > threshold) {

      Serial.println("Knock!");
      health = health - sensorReading4;

      
      
      Serial.print(sensorReading4);
      lcd.print(sensorReading4);


      int sensorValue = analogRead(A6);

      Serial.println(sensorValue);


      delay(1);

    }

 

//duplicate 

sensorReading5= analogRead(knockSensor5);

 if (sensorReading5 > threshold) {

      Serial.println("Knock!");
      health = health - sensorReading5;

      
      
      Serial.print(sensorReading5);
      lcd.print(sensorReading5);


      int sensorValue = analogRead(A7);

      Serial.println(sensorValue);


      delay(1);

    }







  } while (health > 1);

  
  
  digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);//was 2000             // FOR LED IN ARDUINO
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
 
 
  /*
digitalWrite(LED, HIGH);
delay(2000);                 //FOR LED
digitalWrite(LED, HIGH);
delay(1000);
 */
  myservo1.attach(9);
  myservo2.attach(10);

  delay(15);

 for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);    // waits 15 ms for the servo to reach the position
  
  
  }

 delay(1000);


 lcd.setCursor(0, 2);
      Serial.println(deaths); //showind number of deaths on the lcd
      lcd.println(deaths);


deaths= deaths + 1;// adding deaths






  
  health = 500;
}

      

I would like to have it to where when the health gets down to 0 I would like it to send the message like it does in the radio code now.

Do you know how I could do that?

If so that would be great!

User avatar
dastels
 
Posts: 15666
Joined: Tue Oct 20, 2015 3:22 pm

Re: How do I attach files to my code?

Post by dastels »

Just work slowly, adding one little bit at a time and making sure it all still works. That has the benefit of increasing your understand a little at a time as you go. Trying to add a bunch without fully understanding what you're doing is almost guaranteed to drive you crazy with frustration.

Dave

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I attach files to my code?

Post by animefruit »

Ok.

I will start out with something simpler.

Where would I put the Sweep code for a Servo in my Radio Code if I want the Radio Message to Send after the Servo Sweeps?

What Tab of my code would I put it in and Where in that Tab?

Here is the Sweep Code to remind you:

Code: Select all

   #include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}    
Here is my Radio Code right now.

I have my code set up in different tabs.

This shows the the names of the tabs and the code after them.

Radio TXRX:

Code: Select all

    #include "Radio_TX_Loop.h"
#include "Radio_RX_Setup.h"
#include "Radio_RX_Loop.h"

void setup() 
{
  // Setup the radio for RX:
  Radio_RX_Setup();
  
  // Setup the radio for TX:
  Radio_TX_Setup();

  sendMessage("Score: 900pts, Hit: 7pts");
}

void loop()
{
  // Loop through the TX (Talker):
  Radio_TX_Loop();

  // Loop through the RX (Listener):
  Radio_RX_Loop();
}

  

Radio_RX_Loop.h:

Code: Select all

    void Radio_RX_Loop() 
{
 if (rf69.available()) 
 {
    // Should be a message for us now   
    uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);

    if (rf69.recv(buf, &len)) 
    {     
      if (!len) return;
      buf[len] = 0;
      Serial.print("Received [");
      Serial.print(len);
      Serial.print("]: ");
      Serial.println((char*)buf);
      Serial.print("RSSI: ");
      Serial.println(rf69.lastRssi(), DEC);
      
    } else {
      Serial.println("Receive failed");
    }
  }
}


   
Radio_RX_Setup.h:

Code: Select all

    
//#include <SPI.h>
//#include <RH_RF69.h>
//
///************ Radio Setup ***************/
//
//// Change to 434.0 or other frequency, must match RX's freq!
//#define RF69_FREQ 915.0
//
//#if defined (__AVR_ATmega32U4__) // Feather 32u4 w/Radio
//  #define RFM69_CS      8
//  #define RFM69_INT     7
//  #define RFM69_RST     4
//  #define LED           13
//#endif
//
//#if defined(ADAFRUIT_FEATHER_M0) || defined(ADAFRUIT_FEATHER_M0_EXPRESS) || defined(ARDUINO_SAMD_FEATHER_M0)
//  // Feather M0 w/Radio
//  #define RFM69_CS      8
//  #define RFM69_INT     3
//  #define RFM69_RST     4
//  #define LED           13
//#endif
//
//#if defined (__AVR_ATmega328P__)  // Feather 328P w/wing
//  #define RFM69_INT     3  // 
//  #define RFM69_CS      4  //
//  #define RFM69_RST     2  // "A"
//  #define LED           13
//#endif
//
//#if defined(ESP8266)    // ESP8266 feather w/wing
//  #define RFM69_CS      2    // "E"
//  #define RFM69_IRQ     15   // "B"
//  #define RFM69_RST     16   // "D"
//  #define LED           0
//#endif
//
//#if defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) || defined(ARDUINO_NRF52840_FEATHER) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
//  #define RFM69_INT     9  // "A"
//  #define RFM69_CS      10  // "B"
//  #define RFM69_RST     11  // "C"
//  #define LED           13
//
//#elif defined(ESP32)    // ESP32 feather w/wing
//  #define RFM69_RST     13   // same as LED
//  #define RFM69_CS      33   // "B"
//  #define RFM69_INT     27   // "A"
//  #define LED           13
//#endif
//
//#if defined(ARDUINO_NRF52832_FEATHER)
//  /* nRF52832 feather w/wing */
//  #define RFM69_RST     7   // "A"
//  #define RFM69_CS      11   // "B"
//  #define RFM69_INT     31   // "C"
//  #define LED           17
//#endif
//
///* Teensy 3.x w/wing
//#define RFM69_RST     9   // "A"
//#define RFM69_CS      10   // "B"
//#define RFM69_IRQ     4    // "C"
//#define RFM69_IRQN    digitalPinToInterrupt(RFM69_IRQ )
//*/
// 
///* WICED Feather w/wing 
//#define RFM69_RST     PA4     // "A"
//#define RFM69_CS      PB4     // "B"
//#define RFM69_IRQ     PA15    // "C"
//#define RFM69_IRQN    RFM69_IRQ
//*/
//
//// Singleton instance of the radio driver
//RH_RF69 rf69(RFM69_CS, RFM69_INT);
//
//int16_t packetnum = 0;  // packet counter, we increment per xmission

void Radio_RX_Setup()
{
  Serial.begin(115200);

  pinMode(LED, OUTPUT);     
  pinMode(RFM69_RST, OUTPUT);
  digitalWrite(RFM69_RST, LOW);

  Serial.print("Feather RFM69 - RX Test Status: ");
  //Serial.println();

  // manual reset
  digitalWrite(RFM69_RST, HIGH);
  delay(10);
  digitalWrite(RFM69_RST, LOW);
  delay(10);
  
  if (!rf69.init()) 
  {
    Serial.print("Failed");
    while (1);
  }
  Serial.print("OK");
  
  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)
  // No encryption
  if (!rf69.setFrequency(RF69_FREQ)) 
  {
    Serial.println("setFrequency failed");
  }

  // If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the
  // ishighpowermodule flag set like this:
  rf69.setTxPower(20, true);  // range from 14-20 for power, 2nd arg must be true for 69HCW

  // The encryption key has to be the same as the one in the server
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);
  
  Serial.print(" @");
  Serial.print((int)RF69_FREQ);
  Serial.println(" MHz");
}

   


Radio_TX_Loop.h:

Code: Select all

  void Radio_TX_Loop()
{
  
} 
Radio_TX_Setup.h:

Code: Select all

   #include <SPI.h>
#include <RH_RF69.h>

/************ Radio Setup ***************/

// Change to 434.0 or other frequency, must match RX's freq!
#define RF69_FREQ 915.0

#if defined (__AVR_ATmega32U4__) // Feather 32u4 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     7
  #define RFM69_RST     4
  #define LED           13
  
#elif defined(ADAFRUIT_FEATHER_M0) || defined(ADAFRUIT_FEATHER_M0_EXPRESS) || defined(ARDUINO_SAMD_FEATHER_M0)
  // Feather M0 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     3
  #define RFM69_RST     4
  #define LED           13
  
#elif defined (__AVR_ATmega328P__)  // Feather 328P w/wing
  #define RFM69_INT     3  // 
  #define RFM69_CS      4  //
  #define RFM69_RST     2  // "A"
  #define LED           13

#elif defined(ESP8266)    // ESP8266 feather w/wing
  #define RFM69_CS      2    // "E"
  #define RFM69_IRQ     15   // "B"
  #define RFM69_RST     16   // "D"
  #define LED           0

#elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) || defined(ARDUINO_NRF52840_FEATHER) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
  #define RFM69_INT     9  // "A"
  #define RFM69_CS      10  // "B"
  #define RFM69_RST     11  // "C"
  #define LED           13

#elif defined(ESP32)    // ESP32 feather w/wing
  #define RFM69_RST     13   // same as LED
  #define RFM69_CS      33   // "B"
  #define RFM69_INT     27   // "A"
  #define LED           13

#elif defined(ARDUINO_NRF52832_FEATHER)
  /* nRF52832 feather w/wing */
  #define RFM69_RST     7   // "A"
  #define RFM69_CS      11   // "B"
  #define RFM69_INT     31   // "C"
  #define LED           17

#endif

// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);

int16_t packetnum = 0;  // packet counter, we increment per xmission

void Radio_TX_Setup() 
{
  Serial.begin(115200);

  pinMode(LED, OUTPUT);     
  pinMode(RFM69_RST, OUTPUT);
  digitalWrite(RFM69_RST, LOW);

  Serial.print("Feather RFM69 - TX Test Status:");
  //Serial.println();

  // manual reset
  digitalWrite(RFM69_RST, HIGH);
  delay(10);
  digitalWrite(RFM69_RST, LOW);
  delay(10);
  
  if (!rf69.init()) 
  {
    Serial.print("Failed");
    while (1);
  }
  Serial.print("OK");
  
  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)
  // No encryption
  if (!rf69.setFrequency(RF69_FREQ)) 
  {
    Serial.println("setFrequency failed");
  }

  // If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the
  // ishighpowermodule flag set like this:
  rf69.setTxPower(20, true);  // range from 14-20 for power, 2nd arg must be true for 69HCW

  // The encryption key has to be the same as the one in the server
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);
  
  //pinMode(LED, OUTPUT);

  Serial.print(" @");  
  Serial.print((int)RF69_FREQ);  
  Serial.println(" MHz");


//  delay(1000);  // Wait 1 second between transmits, could also 'sleep' here!
//
//  char radiopacket[30] = "Message 1";
//  Serial.print("Sending "); 
//  Serial.println(radiopacket);
//  
//  // Send a message!
//  rf69.send((uint8_t *)radiopacket, strlen(radiopacket));
//  rf69.waitPacketSent();
}

void sendMessage(char* input)
{
  Serial.print("Sending "); 
  Serial.println(input);
  
  // Send a message!
  rf69.send((uint8_t *)input, strlen(input));
  rf69.waitPacketSent();
}
     
If you could tell me how to do that than that would be great!

User avatar
dastels
 
Posts: 15666
Joined: Tue Oct 20, 2015 3:22 pm

Re: How do I attach files to my code?

Post by dastels »

The tabs are just to hold the various source files.

Keep in mind that you can only have one setup() function and one loop() function. You can do setup and loop stuff in other function but they need different names and would get called from setup/loop.

It matters more when thing happen (e.g. the sweep) than where you put them. It might be easier to understand & work on if you keep to one file. For a complex program it makes more sense to decompose it into files but for something fairly simple, a single file is often easier to work with.

Dave

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I attach files to my code?

Post by animefruit »

Ok .

I will just use the normal 'RadioHead69_RawDemoTXRX_OLED' example code.

This code uses Buttons so I guess I will do something with the Buttons.

So How could I put the Servo Sweep Code into This Code so that after the Buttons are pressed the Servo Sweeps and after the Servo Sweeps it will send the Radio Message?

Here is the normal 'RadioHead69_RawDemoTXRX_OLED' example code:

Code: Select all

  // rf69 demo tx rx oled.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messageing client
// with the RH_RF69 class. RH_RF69 class does not provide for addressing or
// reliability, so you should only use RH_RF69  if you do not need the higher
// level messaging abilities.
// It is designed to work with the other example rf69_server.
// Demonstrates the use of AES encryption, setting the frequency and modem 
// configuration

#include <SPI.h>
#include <RH_RF69.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

/************ OLED Setup ***************/
Adafruit_SSD1306 oled = Adafruit_SSD1306();

#if defined(ESP8266)
  #define BUTTON_A 0
  #define BUTTON_B 16
  #define BUTTON_C 2
  #define LED      0
#elif defined(ESP32)
  #define BUTTON_A 15
  #define BUTTON_B 32
  #define BUTTON_C 14
  #define LED      13
#elif defined(ARDUINO_STM32F2_FEATHER)
  #define BUTTON_A PA15
  #define BUTTON_B PC7
  #define BUTTON_C PC5
  #define LED PB5
#elif defined(TEENSYDUINO)
  #define BUTTON_A 4
  #define BUTTON_B 3
  #define BUTTON_C 8
  #define LED 13
#elif defined(ARDUINO_NRF52832_FEATHER)
  #define BUTTON_A 31
  #define BUTTON_B 30
  #define BUTTON_C 27
  #define LED 17
#else // 32u4, M0, and 328p
  #define BUTTON_A 9
  #define BUTTON_B 6
  #define BUTTON_C 5
  #define LED      13
#endif


/************ Radio Setup ***************/

// Change to 434.0 or other frequency, must match RX's freq!
#define RF69_FREQ 915.0

#if defined (__AVR_ATmega32U4__) // Feather 32u4 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     7
  #define RFM69_RST     4
#endif

#if defined(ARDUINO_SAMD_FEATHER_M0) // Feather M0 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     3
  #define RFM69_RST     4
#endif

#if defined (__AVR_ATmega328P__)  // Feather 328P w/wing
  #define RFM69_INT     3  // 
  #define RFM69_CS      4  //
  #define RFM69_RST     2  // "A"
#endif

#if defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) || defined(ARDUINO_NRF52840_FEATHER) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
  #define RFM69_INT     9  // "A"
  #define RFM69_CS      10  // "B"
  #define RFM69_RST     11  // "C"
  #define LED           13

#elif defined(ESP32)    // ESP32 feather w/wing
  #define RFM69_RST     13   // same as LED
  #define RFM69_CS      33   // "B"
  #define RFM69_INT     27   // "A"
#endif

#if defined(ARDUINO_NRF52832_FEATHER)
  /* nRF52832 feather w/wing */
  #define RFM69_RST     7   // "A"
  #define RFM69_CS      11   // "B"
  #define RFM69_INT     31   // "C"
  #define LED           17
#endif

// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);

void setup() 
{
  delay(500);
  Serial.begin(115200);
  //while (!Serial) { delay(1); } // wait until serial console is open, remove if not tethered to computer

  // Initialize OLED display
  oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
  oled.display();
  delay(500);
  oled.clearDisplay();
  oled.display();

  pinMode(BUTTON_A, INPUT_PULLUP);
  pinMode(BUTTON_B, INPUT_PULLUP);
  pinMode(BUTTON_C, INPUT_PULLUP);

  pinMode(LED, OUTPUT);     
  pinMode(RFM69_RST, OUTPUT);
  digitalWrite(RFM69_RST, LOW);

  Serial.println("Feather RFM69 RX/TX Test!");

  // manual reset
  digitalWrite(RFM69_RST, HIGH);
  delay(10);
  digitalWrite(RFM69_RST, LOW);
  delay(10);
  
  if (!rf69.init()) {
    Serial.println("RFM69 radio init failed");
    while (1);
  }
  Serial.println("RFM69 radio init OK!");
  
  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)
  // No encryption
  if (!rf69.setFrequency(RF69_FREQ)) {
    Serial.println("setFrequency failed");
  }

  // If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the
  // ishighpowermodule flag set like this:
  rf69.setTxPower(14, true);

  // The encryption key has to be the same as the one in the server
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);
  
  pinMode(LED, OUTPUT);

  Serial.print("RFM69 radio @");  Serial.print((int)RF69_FREQ);  Serial.println(" MHz");

  // OLED text display tests
  oled.setTextSize(2);
  oled.setTextColor(WHITE);
  oled.setCursor(0,0);
  oled.println("RFM69 @ ");
  oled.print((int)RF69_FREQ);
  oled.println(" MHz");
  oled.display();

  delay(500);
}


void loop()
{  if (rf69.waitAvailableTimeout(100)) {
    // Should be a message for us now   
    uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
    
    if (! rf69.recv(buf, &len)) {
      Serial.println("Receive failed");
      return;
    }
    digitalWrite(LED, HIGH);
    rf69.printBuffer("Received: ", buf, len);
    buf[len] = 0;
    
    Serial.print("Got: "); Serial.println((char*)buf);
    Serial.print("RSSI: "); Serial.println(rf69.lastRssi(), DEC);

    oled.clearDisplay();
    oled.setCursor(0,0);
    oled.println((char*)buf);
    oled.print("RSSI: "); oled.print(rf69.lastRssi());
    oled.display(); 
    digitalWrite(LED, LOW);
  }

  if (!digitalRead(BUTTON_A) || !digitalRead(BUTTON_B) || !digitalRead(BUTTON_C))
  {
    Serial.println("Button pressed!");
    
    char radiopacket[20] = "Button #";
    if (!digitalRead(BUTTON_A)) radiopacket[8] = 'A';
    if (!digitalRead(BUTTON_B)) radiopacket[8] = 'B';
    if (!digitalRead(BUTTON_C)) radiopacket[8] = 'C';
    radiopacket[9] = 0;

    Serial.print("Sending "); Serial.println(radiopacket);
    rf69.send((uint8_t *)radiopacket, strlen(radiopacket));
    rf69.waitPacketSent();
  }
}
    

User avatar
dastels
 
Posts: 15666
Joined: Tue Oct 20, 2015 3:22 pm

Re: How do I attach files to my code?

Post by dastels »

When the button press is detected, sweep the servo. You'll want to either set its angle to the end point and delay for long enough to let it get there or step it a bit at a time (with a short delay to let the servo catch up)so that when it's at the endpoint your code just carries on. In either case it would then send the radio message. I would tend to use the step a bit at a time approach since it will be more independent of the servo speed.

Dave

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I attach files to my code?

Post by animefruit »

Ok.

I started putting in the Servo Sweep Code into the RadioHead69_RawDemoTXRX_OLED example code.

But even when I put in the first code for the Sweep code into the Radio code I get the error that says " Error compiling for board Arduino Nano."

There is an attached image of the error.

Here is how the code looks like for that:

Code: Select all

  // rf69 demo tx rx oled.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messageing client
// with the RH_RF69 class. RH_RF69 class does not provide for addressing or
// reliability, so you should only use RH_RF69  if you do not need the higher
// level messaging abilities.
// It is designed to work with the other example rf69_server.
// Demonstrates the use of AES encryption, setting the frequency and modem 
// configuration

#include <SPI.h>
#include <RH_RF69.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>


#include <Servo.h>



/************ OLED Setup ***************/
Adafruit_SSD1306 oled = Adafruit_SSD1306();

#if defined(ESP8266)
  #define BUTTON_A 0
  #define BUTTON_B 16
  #define BUTTON_C 2
  #define LED      0
#elif defined(ESP32)
  #define BUTTON_A 15
  #define BUTTON_B 32
  #define BUTTON_C 14
  #define LED      13
#elif defined(ARDUINO_STM32F2_FEATHER)
  #define BUTTON_A PA15
  #define BUTTON_B PC7
  #define BUTTON_C PC5
  #define LED PB5
#elif defined(TEENSYDUINO)
  #define BUTTON_A 4
  #define BUTTON_B 3
  #define BUTTON_C 8
  #define LED 13
#elif defined(ARDUINO_NRF52832_FEATHER)
  #define BUTTON_A 31
  #define BUTTON_B 30
  #define BUTTON_C 27
  #define LED 17
#else // 32u4, M0, and 328p
  #define BUTTON_A 9
  #define BUTTON_B 6
  #define BUTTON_C 5
  #define LED      13
#endif


/************ Radio Setup ***************/

// Change to 434.0 or other frequency, must match RX's freq!
//#define RF69_FREQ 915.0
#define RF69_FREQ 434.0

#if defined (__AVR_ATmega32U4__) // Feather 32u4 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     7
  #define RFM69_RST     4
#endif

#if defined(ARDUINO_SAMD_FEATHER_M0) // Feather M0 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     3
  #define RFM69_RST     4
#endif

#if defined (__AVR_ATmega328P__)  // Feather 328P w/wing
  #define RFM69_INT     3  // 
  #define RFM69_CS      4  //
  #define RFM69_RST     2  // "A"
#endif

#if defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) || defined(ARDUINO_NRF52840_FEATHER) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
  #define RFM69_INT     9  // "A"
  #define RFM69_CS      10  // "B"
  #define RFM69_RST     11  // "C"
  #define LED           13

#elif defined(ESP32)    // ESP32 feather w/wing
  #define RFM69_RST     13   // same as LED
  #define RFM69_CS      33   // "B"
  #define RFM69_INT     27   // "A"
#endif

#if defined(ARDUINO_NRF52832_FEATHER)
  /* nRF52832 feather w/wing */
  #define RFM69_RST     7   // "A"
  #define RFM69_CS      11   // "B"
  #define RFM69_INT     31   // "C"
  #define LED           17
#endif

// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);

void setup() 
{
  delay(500);
  Serial.begin(115200);
  //while (!Serial) { delay(1); } // wait until serial console is open, remove if not tethered to computer

  // Initialize OLED display
  oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
  oled.display();
  delay(500);
  oled.clearDisplay();
  oled.display();

  pinMode(BUTTON_A, INPUT_PULLUP);
  pinMode(BUTTON_B, INPUT_PULLUP);
  pinMode(BUTTON_C, INPUT_PULLUP);

  pinMode(LED, OUTPUT);     
  pinMode(RFM69_RST, OUTPUT);
  digitalWrite(RFM69_RST, LOW);

  Serial.println("Feather RFM69 RX/TX Test!");

  // manual reset
  digitalWrite(RFM69_RST, HIGH);
  delay(10);
  digitalWrite(RFM69_RST, LOW);
  delay(10);
  
  if (!rf69.init()) {
    Serial.println("RFM69 radio init failed");
    while (1);
  }
  Serial.println("RFM69 radio init OK!");
  
  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)
  // No encryption
  if (!rf69.setFrequency(RF69_FREQ)) {
    Serial.println("setFrequency failed");
  }

  // If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the
  // ishighpowermodule flag set like this:
  rf69.setTxPower(14, true);

  // The encryption key has to be the same as the one in the server
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);
  
  pinMode(LED, OUTPUT);

  Serial.print("RFM69 radio @");  Serial.print((int)RF69_FREQ);  Serial.println(" MHz");

  // OLED text display tests
  oled.setTextSize(2);
  oled.setTextColor(WHITE);
  oled.setCursor(0,0);
  oled.println("RFM69 @ ");
  oled.print((int)RF69_FREQ);
  oled.println(" MHz");
  oled.display();

  delay(500);
}


void loop()
{  if (rf69.waitAvailableTimeout(100)) {
    // Should be a message for us now   
    uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
    
    if (! rf69.recv(buf, &len)) {
      Serial.println("Receive failed");
      return;
    }
    digitalWrite(LED, HIGH);
    rf69.printBuffer("Received: ", buf, len);
    buf[len] = 0;
    
    Serial.print("Got: "); Serial.println((char*)buf);
    Serial.print("RSSI: "); Serial.println(rf69.lastRssi(), DEC);

    oled.clearDisplay();
    oled.setCursor(0,0);
    oled.println((char*)buf);
    oled.print("RSSI: "); oled.print(rf69.lastRssi());
    oled.display(); 
    digitalWrite(LED, LOW);
  }

  if (!digitalRead(BUTTON_A) || !digitalRead(BUTTON_B) || !digitalRead(BUTTON_C))
  {
    Serial.println("Button pressed!");
    
    char radiopacket[20] = "Button #";
    if (!digitalRead(BUTTON_A)) radiopacket[8] = 'A';
    if (!digitalRead(BUTTON_B)) radiopacket[8] = 'B';
    if (!digitalRead(BUTTON_C)) radiopacket[8] = 'C';
    radiopacket[9] = 0;

    Serial.print("Sending "); Serial.println(radiopacket);
    rf69.send((uint8_t *)radiopacket, strlen(radiopacket));
    rf69.waitPacketSent();
  }
}
  
I added each line of code and got the same error.

It also has the same error when putting All of the code from Sweep into the RadioHead69_RawDemoTXRX_OLED example code.

There is also an image of the error of that attached.

Here is the code from that:

Code: Select all

     // rf69 demo tx rx oled.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messageing client
// with the RH_RF69 class. RH_RF69 class does not provide for addressing or
// reliability, so you should only use RH_RF69  if you do not need the higher
// level messaging abilities.
// It is designed to work with the other example rf69_server.
// Demonstrates the use of AES encryption, setting the frequency and modem 
// configuration

#include <SPI.h>
#include <RH_RF69.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#include <Servo.h>
Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position




/************ OLED Setup ***************/
Adafruit_SSD1306 oled = Adafruit_SSD1306();

#if defined(ESP8266)
  #define BUTTON_A 0
  #define BUTTON_B 16
  #define BUTTON_C 2
  #define LED      0
#elif defined(ESP32)
  #define BUTTON_A 15
  #define BUTTON_B 32
  #define BUTTON_C 14
  #define LED      13
#elif defined(ARDUINO_STM32F2_FEATHER)
  #define BUTTON_A PA15
  #define BUTTON_B PC7
  #define BUTTON_C PC5
  #define LED PB5
#elif defined(TEENSYDUINO)
  #define BUTTON_A 4
  #define BUTTON_B 3
  #define BUTTON_C 8
  #define LED 13
#elif defined(ARDUINO_NRF52832_FEATHER)
  #define BUTTON_A 31
  #define BUTTON_B 30
  #define BUTTON_C 27
  #define LED 17
#else // 32u4, M0, and 328p
  #define BUTTON_A 9
  #define BUTTON_B 6
  #define BUTTON_C 5
  #define LED      13
#endif


/************ Radio Setup ***************/

// Change to 434.0 or other frequency, must match RX's freq!
//#define RF69_FREQ 915.0
#define RF69_FREQ 434.0
#if defined (__AVR_ATmega32U4__) // Feather 32u4 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     7
  #define RFM69_RST     4
#endif

#if defined(ARDUINO_SAMD_FEATHER_M0) // Feather M0 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     3
  #define RFM69_RST     4
#endif

#if defined (__AVR_ATmega328P__)  // Feather 328P w/wing
  #define RFM69_INT     3  // 
  #define RFM69_CS      4  //
  #define RFM69_RST     2  // "A"
#endif

#if defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) || defined(ARDUINO_NRF52840_FEATHER) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
  #define RFM69_INT     9  // "A"
  #define RFM69_CS      10  // "B"
  #define RFM69_RST     11  // "C"
  #define LED           13

#elif defined(ESP32)    // ESP32 feather w/wing
  #define RFM69_RST     13   // same as LED
  #define RFM69_CS      33   // "B"
  #define RFM69_INT     27   // "A"
#endif

#if defined(ARDUINO_NRF52832_FEATHER)
  /* nRF52832 feather w/wing */
  #define RFM69_RST     7   // "A"
  #define RFM69_CS      11   // "B"
  #define RFM69_INT     31   // "C"
  #define LED           17
#endif

// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);

void setup() 
{
  delay(500);

  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  
  Serial.begin(115200);
  //while (!Serial) { delay(1); } // wait until serial console is open, remove if not tethered to computer

  // Initialize OLED display
  oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
  oled.display();
  delay(500);
  oled.clearDisplay();
  oled.display();

  pinMode(BUTTON_A, INPUT_PULLUP);
  pinMode(BUTTON_B, INPUT_PULLUP);
  pinMode(BUTTON_C, INPUT_PULLUP);

  pinMode(LED, OUTPUT);     
  pinMode(RFM69_RST, OUTPUT);
  digitalWrite(RFM69_RST, LOW);

  Serial.println("Feather RFM69 RX/TX Test!");

  // manual reset
  digitalWrite(RFM69_RST, HIGH);
  delay(10);
  digitalWrite(RFM69_RST, LOW);
  delay(10);
  
  if (!rf69.init()) {
    Serial.println("RFM69 radio init failed");
    while (1);
  }
  Serial.println("RFM69 radio init OK!");
  
  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)
  // No encryption
  if (!rf69.setFrequency(RF69_FREQ)) {
    Serial.println("setFrequency failed");
  }

  // If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the
  // ishighpowermodule flag set like this:
  rf69.setTxPower(14, true);

  // The encryption key has to be the same as the one in the server
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);
  
  pinMode(LED, OUTPUT);

  Serial.print("RFM69 radio @");  Serial.print((int)RF69_FREQ);  Serial.println(" MHz");

  // OLED text display tests
  oled.setTextSize(2);
  oled.setTextColor(WHITE);
  oled.setCursor(0,0);
  oled.println("RFM69 @ ");
  oled.print((int)RF69_FREQ);
  oled.println(" MHz");
  oled.display();

  delay(500);
}


void loop()
{  if (rf69.waitAvailableTimeout(100)) {
    // Should be a message for us now   
    uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
    
    if (! rf69.recv(buf, &len)) {
      Serial.println("Receive failed");
      return;
    }
    digitalWrite(LED, HIGH);
    rf69.printBuffer("Received: ", buf, len);
    buf[len] = 0;
    
    Serial.print("Got: "); Serial.println((char*)buf);
    Serial.print("RSSI: "); Serial.println(rf69.lastRssi(), DEC);

    oled.clearDisplay();
    oled.setCursor(0,0);
    oled.println((char*)buf);
    oled.print("RSSI: "); oled.print(rf69.lastRssi());
    oled.display(); 
    digitalWrite(LED, LOW);
  }

  if (!digitalRead(BUTTON_A) || !digitalRead(BUTTON_B) || !digitalRead(BUTTON_C))
  {
    Serial.println("Button pressed!");
    
    char radiopacket[20] = "Button #";
    if (!digitalRead(BUTTON_A)) radiopacket[8] = 'A';
    if (!digitalRead(BUTTON_B)) radiopacket[8] = 'B';
    if (!digitalRead(BUTTON_C)) radiopacket[8] = 'C';
    radiopacket[9] = 0;

    Serial.print("Sending "); Serial.println(radiopacket);
    rf69.send((uint8_t *)radiopacket, strlen(radiopacket));
    rf69.waitPacketSent();

 for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
//}




    
  }
}    

Can you tell my why the "Error compiling for Arduino Nano" is popping up so I can fix it?

If so that would be great.
Attachments
Error2.PNG
Error2.PNG (35.96 KiB) Viewed 214 times
Error.PNG
Error.PNG (32.03 KiB) Viewed 214 times

User avatar
dastels
 
Posts: 15666
Joined: Tue Oct 20, 2015 3:22 pm

Re: How do I attach files to my code?

Post by dastels »

That's just the final line of the output. The stuff before that will tell you what's going on.

Dave

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I attach files to my code?

Post by animefruit »

What is the “final line of output”?

What “stuff” before that output tells me what’s going on?

How would I figure out what is going on by looking at that code?

User avatar
dastels
 
Posts: 15666
Joined: Tue Oct 20, 2015 3:22 pm

Re: How do I attach files to my code?

Post by dastels »

Make the build output pane bigger (you can drag the divider up). Ypu'll see any error messages there telling you what the problem is. At the end of the output it puts a link saying whether it succeeded or fails. In your case it said that it fails i.e. "Error compiling".

Ideally copy the output and paste it here. There should be a button near the bottom of the window to copy the output.

Dave

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I attach files to my code?

Post by animefruit »

Ok.
I actually got some code that works way better.
I had to use PWM servo rather than Servo.h because the code doesn't accept that.
This code is supposed to move the servo when I press a Button and then send the message.
The problem now is that the serial monitor is printing out text rather than printing out the button status.

I have images of the what I want in the Serial Monitor and what I don't want in the Seriel Monitor.
The Bad one keeps repaeating "RFM69 Radio @434 MHZ"
The Good one shows Button #C


Can you tell me how to change the code so that it makes the Serial Monitor the way I want it?


Here is the code for this:

Code: Select all

//#include <Servo.h>
#include <PWMServo.h>

#include "Adafruit_LiquidCrystal.h"


//ADD OF B START

#include <SPI.h>
#include <RH_RF69.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

 
#define LED 13// FOR LED


#define RF69_FREQ 434.0
/************ OLED Setup ***************/
Adafruit_SSD1306 oled = Adafruit_SSD1306();

#if defined(ESP8266)
  #define BUTTON_A 0
  #define BUTTON_B 16
  #define BUTTON_C 2
  #define LED      0
#elif defined(ESP32)
  #define BUTTON_A 15
  #define BUTTON_B 32
  #define BUTTON_C 14
  #define LED      13
#elif defined(ARDUINO_STM32F2_FEATHER)
  #define BUTTON_A PA15
  #define BUTTON_B PC7
  #define BUTTON_C PC5
  #define LED PB5
#elif defined(TEENSYDUINO)
  #define BUTTON_A 4
  #define BUTTON_B 3
  #define BUTTON_C 8
  #define LED 13
#elif defined(ARDUINO_NRF52832_FEATHER)
  #define BUTTON_A 31
  #define BUTTON_B 30
  #define BUTTON_C 27
  #define LED 17
#else // 32u4, M0, and 328p
  #define BUTTON_A 9
  #define BUTTON_B 6
  #define BUTTON_C 5
  #define LED      13
#endif


/************ Radio Setup ***************/

// Change to 434.0 or other frequency, must match RX's freq!
//#define RF69_FREQ 915.0
#define RF69_FREQ 434.0
#if defined (__AVR_ATmega32U4__) // Feather 32u4 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     7
  #define RFM69_RST     4
#endif

#if defined(ARDUINO_SAMD_FEATHER_M0) // Feather M0 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     3
  #define RFM69_RST     4
#endif

#if defined (__AVR_ATmega328P__)  // Feather 328P w/wing
  #define RFM69_INT     3  // 
  #define RFM69_CS      4  //
  #define RFM69_RST     2  // "A"
#endif

#if defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) || defined(ARDUINO_NRF52840_FEATHER) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
  #define RFM69_INT     9  // "A"
  #define RFM69_CS      10  // "B"
  #define RFM69_RST     11  // "C"
  #define LED           13

#elif defined(ESP32)    // ESP32 feather w/wing
  #define RFM69_RST     13   // same as LED
  #define RFM69_CS      33   // "B"
  #define RFM69_INT     27   // "A"
#endif

#if defined(ARDUINO_NRF52832_FEATHER)
  /* nRF52832 feather w/wing */
  #define RFM69_RST     7   // "A"
  #define RFM69_CS      11   // "B"
  #define RFM69_INT     31   // "C"
  #define LED           17
#endif

// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);

//ADD OF B END

Adafruit_LiquidCrystal lcd(0);
 
PWMServo myservo1; //THE BIG CHANGE MARK MADE
PWMServo myservo2; //THE BIG CHANGE MARK MADE


 /*
//cant do A4 and A5(they are for lcd)
// Analogs 0 to 5
const int knockSensor = A0;
const int knockSensor1= A1;
const int knockSensor2= A2;
const int knockSensor3= A3;
const int knockSensor4= A6;
const int knockSensor5= A7;
 
 
const int threshold = 10;
int health = 500;
 
// 6 total sensor readings (from 0 to 5)
 
int sensorReading = 0;
int sensorReading1 =0;
int sensorReading2 =0;
int sensorReading3 =0;
int sensorReading4 =0;
int sensorReading5 =0;
 */
 
int pos =0;
 
 
 
//int deaths=1;// gonna be number of deaths
 
 
 
void setup()
 
{
 // pinMode(LED_BUILTIN, OUTPUT); //LED ON ARDUINO
  pinMode(LED, OUTPUT);//FOR LED
 
  Serial.begin(115200);//was 9600
  Serial.println("Nerf Target v0.0.1, github.com/mcoms/nerf-target, 2014.");

  pinMode(BUTTON_A, INPUT_PULLUP);
  pinMode(BUTTON_B, INPUT_PULLUP);
  pinMode(BUTTON_C, INPUT_PULLUP);


  pinMode(LED, OUTPUT);    
  pinMode(RFM69_RST, OUTPUT);
  digitalWrite(RFM69_RST, LOW);

Serial.println("Feather RFM69 RX/TX Test!");

 
 // manual reset
  digitalWrite(RFM69_RST, HIGH);
  delay(10);
  digitalWrite(RFM69_RST, LOW);
  delay(10);
 
 
 
 
 if (!rf69.init()) {
    Serial.println("RFM69 radio init failed");
    while (1);
  }    // failed


 Serial.println("RFM69 radio init OK!");
  
  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)
  // No encryption
  if (!rf69.setFrequency(RF69_FREQ)) {
    Serial.println("setFrequency failed");
  }

  // If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the
  // ishighpowermodule flag set like this:

rf69.setTxPower(14, true);

// The encryption key has to be the same as the one in the server
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);
  
  pinMode(LED, OUTPUT);

  Serial.print("RFM69 radio @");  Serial.print((int)RF69_FREQ);  Serial.println(" MHz");

  // OLED text display tests
  oled.setTextSize(2);
  oled.setTextColor(WHITE);
  oled.setCursor(0,0);
  oled.println("RFM69 @ ");
  oled.print((int)RF69_FREQ);
  oled.println(" MHz");
  oled.display();

  delay(500);



 
// sg90
 
  lcd.begin (20 , 4);
  lcd.clear();
 
 
  Serial.begin(115200);
  myservo1.attach(9);
  myservo1.write(0);//was 0
 
  myservo2.attach(10);
  myservo2.write(45);//was 179
 
 
 
 
}
 
void loop()
{
 
 
 
 
  digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);//was 2000             // FOR LED IN ARDUINO
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
 
 
  /*
digitalWrite(LED, HIGH);
delay(2000);                 //FOR LED
digitalWrite(LED, HIGH);
delay(1000);
 */
 
 




 
 //lcd.setCursor(0, 2);
      //Serial.println(deaths); //showind number of deaths on the lcd
      //lcd.println(deaths);
 
 
//deaths= deaths + 1;// adding deaths
 
 //Start of Radio Sending Message
 
 {  if (rf69.waitAvailableTimeout(100)) {
    // Should be a message for us now  
    uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
   
   if (! rf69.recv(buf , & len )) {
      Serial.println("Receive failed");
      return;
    }
    digitalWrite(LED, HIGH);
    rf69.printBuffer("Received: ", buf, len);
    buf[len] = 0;
   
    Serial.print("Got: "); Serial.println((char*) buf);
    Serial.print("RSSI: "); Serial.println(rf69.lastRssi(), DEC);

    oled.clearDisplay();
    oled.setCursor(0,0);
    oled.println((char*)buf);
    oled.print("RSSI: "); oled.print(rf69.lastRssi());
    oled.display(); 
    digitalWrite(LED, LOW);


    
  }


  if (!digitalRead(BUTTON_A) || !digitalRead(BUTTON_B) || !digitalRead(BUTTON_C))
  {
    Serial.println("Button pressed!");
    
    char radiopacket[20] = "Button #";
    if (!digitalRead(BUTTON_A)) radiopacket[8] = 'A';
    if (!digitalRead(BUTTON_B)) radiopacket[8] = 'B';
    if (!digitalRead(BUTTON_C)) radiopacket[8] = 'C';
    radiopacket[9] = 0;

    Serial.print("Sending "); Serial.println(radiopacket);
    rf69.send((uint8_t *)radiopacket, strlen(radiopacket));
    rf69.waitPacketSent();




 myservo1.attach(9);
  myservo2.attach(10);
 
  delay(15);
 //Servo Starts Moving Here
 for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);    // waits 15 ms for the servo to reach the position
 
 //Servo Stops Moving Here
  }






 
 delay(1000);




 
  


  //delay(5000);
}
 }
}
 
Attachments
BUTTUN C.PNG
BUTTUN C.PNG (14.98 KiB) Viewed 197 times
RFM  434.PNG
RFM 434.PNG (21.89 KiB) Viewed 197 times

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”