Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- /*OLED Display*/
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- // Color definitions
- #define BLACK 0x0000
- #define BLUE 0x001F
- #define RED 0xF800
- #define GREEN 0x07E0
- #define CYAN 0x07FF
- #define MAGENTA 0xF81F
- #define YELLOW 0xFFE0
- #define SCREEN_WIDTH 128 // OLED display width, in pixels
- #define SCREEN_HEIGHT 64 // OLED display height, in pixels
- // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
- #define SDA A4
- #define SCL A5
- Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
- #include <SPI.h>
- #include <Wire.h>
- #include "nRF24L01.h"
- #include "RF24.h"
- RF24 radio(0, 2, 14, 12, 13);
- const byte pipes[][6] = {"1000", "2000", "3000", "4000", "5000", "6000"};
- //#include <WiFi.h>
- //#include <HTTPClient.h>
- const char* ssid = "UIR WIFI";
- const char* password = "";
- byte channel = 101;
- const String this_node = "F";
- void radioConfig() {
- // radio.begin();
- display.clearDisplay();
- display.setTextColor(WHITE);
- display.setTextSize(1);
- display.setCursor(0, 0);
- if (!radio.begin()) {
- display.println("Radio failed");
- display.display();
- for (;;);
- }
- if (radio.isChipConnected()) {
- display.println("Radio is connected");
- display.display();
- }
- radio.setChannel(channel);
- radio.setPayloadSize(32);
- radio.setPALevel(RF24_PA_MAX);
- radio.setDataRate(RF24_250KBPS);
- radio.openReadingPipe(0, pipes[5]); //F
- radio.startListening();
- // //Serial.println();
- // //Serial.println("Radio Received Start Listening");
- }
- void setup(void) {
- Serial.begin(115200);
- if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
- ////Serial.println(F("SSD1306 allocation failed"));
- for (;;);
- }
- display.clearDisplay();
- display.display();
- delay(1000);
- radioConfig();
- delay(2000);
- }
- String d;
- void loop() {
- while (Serial.available()) {
- d = Serial.readString();
- radio.stopListening();
- radio.openWritingPipe(pipes[4]);
- char msg[33];
- d.toCharArray(msg, sizeof(msg));
- byte cek = radio.write(msg, sizeof(msg));
- radio.startListening();
- }
- readRadio();
- }
- char msg[33];
- String data;
- void readRadio() {
- delay(5);
- byte pipe_num = 0;
- if (radio.available(&pipe_num)) {
- display.clearDisplay();
- display.setTextColor(WHITE);
- display.setTextSize(1);
- display.setCursor(0, 0);
- display.print("Reading...");
- radio.read(msg, sizeof(msg));
- data = String(msg);
- Serial.println("#################################");
- Serial.print("Data: ");
- Serial.println(msg);
- display.setCursor(0, 10);
- display.print("Message: ");
- display.println(msg);
- display.display();
- delay(2000);
- } else {
- display.clearDisplay();
- display.setTextColor(WHITE);
- display.setTextSize(1);
- display.setCursor(0, 50);
- display.println("Radio no available");
- display.display();
- }
- }
Add Comment
Please, Sign In to add comment