Ok.
I tried to combine both of the code together, my code from earlier and the RadioHead69_RawDemoTXRX_OLED.ino code.
I tried combining them twice and got 2 different errors.
The images of the errors are attached below.
I also replaced "BUTTON" as "SERVO" so it would print something when one of the servos move instead.
My first code was this:
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 <Servo.h>
#include "Wire.h"
#include "Adafruit_LiquidCrystal.h" //from other
#include <SPI.h>
#include <RH_RF69.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define LED 13 //from other
Adafruit_LiquidCrystal lcd(0);
Servo myservo1;
Servo myservo2; //from other
const int knockSensor = A0;
const int knockSensor1= A1;
const int knockSensor2= A2;
const int knockSensor3= A3;
const int knockSensor4= A6;
const int knockSensor5= A7;//from other
const int threshold = 0;
int health = 500; //from other
int sensorReading = 0;
int sensorReading1 =0;
int sensorReading2 =0;
int sensorReading3 =0;
int sensorReading4 =0;
int sensorReading5 =0;//from other
int pos =0;// from other
int deaths=1;
/************ OLED Setup ***************/
Adafruit_SSD1306 oled = Adafruit_SSD1306();
#if defined(ESP8266)
#define SERVO_A 0
#define SERVO_B 16
#define SERVO_C 2
#define LED 0
#elif defined(ESP32)
#define SERVO_A 15
#define SERVO_B 32
#define SERVO_C 14
#define LED 13
#elif defined(ARDUINO_STM32F2_FEATHER)
#define SERVO_A PA15
#define SERO_B PC7
#define SERVO_C PC5
#define LED PB5
#elif defined(TEENSYDUINO)
#define SERVO_A 4
#define SERVO_B 3
#define SERVO_C 8
#define LED 13
#elif defined(ARDUINO_NRF52832_FEATHER)
#define SERVO_A 31
#define SERVO_B 30
#define SERVO_C 27
#define LED 17
#else // 32u4, M0, and 328p
#define SERVO_A 9
#define SERVO_B 6
#define SERVO_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);
pinMode(LED, OUTPUT);//from other
Serial.begin(115200);
//while (!Serial) { delay(1); } // wait until serial console is open, remove if not tethered to computer
Serial.println("Nerf Target v0.0.1, github.com/mcoms/nerf-target, 2014.");//from other
lcd.begin (20 , 4);
lcd.clear(); //from other
lcd.begin (20 , 4);
lcd.clear(); //from other
// 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(SERVO_A, INPUT_PULLUP);
pinMode(SERVO_B, INPUT_PULLUP);
pinMode(SERVO_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()
{
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;
{ 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(SERVO_A) || !digitalRead(SERVO_B) || !digitalRead(SERVO_C))
{
Serial.println("Button pressed!");
char radiopacket[20] = "Button #";
if (!digitalRead(SERVO_A)) radiopacket[8] = 'A';
if (!digitalRead(SERVO_B)) radiopacket[8] = 'B';
if (!digitalRead(SERVO_C)) radiopacket[8] = 'C';
radiopacket[9] = 0;
Serial.print("Sending "); Serial.println(radiopacket);
rf69.send((uint8_t *)radiopacket, strlen(radiopacket));
rf69.waitPacketSent();
}
}
}
The error was "Error compiling for Arduino Nano"
My second code was this:
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 <Servo.h>
#include "Wire.h"
#include "Adafruit_LiquidCrystal.h"
Adafruit_LiquidCrystal lcd(0);
Servo myservo1;
Servo myservo2;
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;
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
#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();
#define LED 13// FOR LED
#if defined(ESP8266)
#define SERVO_A 0
#define SERVO_B 16
#define SERVO_C 2
#define LED 0
#elif defined(ESP32)
#define SERVO_A 15
#define SERVO_B 32
#define SERVO_C 14
#define LED 13
#elif defined(ARDUINO_STM32F2_FEATHER)
#define SERVO_A PA15
#define SERVO_B PC7
#define SERVO_C PC5
#define LED PB5
#elif defined(TEENSYDUINO)
#define SERVO_A 4
#define SERVO_B 3
#define SERVO_C 8
#define LED 13
#elif defined(ARDUINO_NRF52832_FEATHER)
#define SERVO_A 31
#define SERVO_B 30
#define SERVO_C 27
#define LED 17
#else // 32u4, M0, and 328p
#define SERVO_A 9
#define SERVO_B 6
#define SERVO_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);
pinMode(LED, OUTPUT);//FOR LED
Serial.begin(115200);
lcd.begin (20 , 4);
lcd.clear();
myservo1.attach(9);
myservo1.write(0);//was 0
myservo2.attach(10);
myservo2.write(45);//was 179
//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(SERVO_A, INPUT_PULLUP);
pinMode(SERVO_B, INPUT_PULLUP);
pinMode(SERVO_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()
{
do
{
myservo1.detach();
myservo2.detach();
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;
}
{ 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(SERVO_A) || !digitalRead(SERVO_B) || !digitalRead(SERVO_C))
{
Serial.println("Button pressed!");
char radiopacket[20] = "Button #";
if (!digitalRead(SERVO_A)) radiopacket[8] = 'A';
if (!digitalRead(SERVO_B)) radiopacket[8] = 'B';
if (!digitalRead(SERVO_C)) radiopacket[8] = 'C';
radiopacket[9] = 0;
Serial.print("Sending "); Serial.println(radiopacket);
rf69.send((uint8_t *)radiopacket, strlen(radiopacket));
rf69.waitPacketSent();
}
}
The error was "expected unqualified-id before '{' token"
Can you help me combine both of this code without errors?