Novachris
Published © CC BY-NC

Talking Portal 2 Turret Gun

Fully functional, automatic talking turret gun from the video game Portal 2!

AdvancedFull instructions provided4,550
Talking Portal 2 Turret Gun

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Lens+v3b.stl

Body-RHS+v4.stl

Body-LHS+w+components+v4.stl

Wing+RH+bottom+v4.stl

Wing+RH+top+v4.stl

Wing+LH+bottom+v4.stl

Wing+LH+top+v4.stl

Pitch+Frame+v4.stl

Leg+-+REAR+v4.stl

Infill+strips+v3.stl

Leg+-+REAR+test.stl

Pitch+Frame+-+modified+1.stl

Arduino+Base+w+Radio.stl

Schematics

Wiring Schematic - radio option

Schematic that I made for building the turret.

Code

Portal turret w Radio (RED)

C/C++
Code used for turret. This includes code that will enable control by the Master Turret Control, featured on another page.
Different flavours require tweaking.
//
/* Portal Turret - Option With Radio!!
 *  Chris Nowak - Feb 2019
 *  https://www.instructables.com/member/ChrisN219/
 *  https://create.arduino.cc/projecthub/Novachris/talking-portal-2-turret-gun-637bf3
 *  
 *  This code includes all the features needed to perform the Cara Mia Opera, 
 *  Chat Time and Manual mode, as controlled by the Maseter Turret Control (MTC).
 *  The MTC is a separate controller featured on another build.  The turret
 *  will operate autonomously using this code without the MTC.
 *  
 *  The code is built to work with three turrets, but each will operate independently.
 *  Lots of debugging code left in.  Use or clean up as desired.  It's mostly debugged,
 *  but isn't perfect.  Given the price you paid, I figure that's ok! ;)
 * ================= RED ====================
 */

#include <Wire.h>
#include <VL53L0X.h>
#include "Arduino.h"
#include <SoftwareSerial.h>
#include <Servo.h>
#include <DFMiniMp3.h>
#include <RF24.h>
#include <RF24Network.h>
#include <SPI.h>
class Mp3Notify
{
public:
  static void OnError(uint8_t errorCode)
  {
    // see DfMp3_Error for code meaning
    Serial.println();
    Serial.print("Com Error ");
    Serial.println(errorCode);
  }
  static void OnPlayFinished(uint8_t globalTrack)
  {
    Serial.println();
    Serial.print("Play finished for #");
    Serial.println(globalTrack);   
  }
  static void OnCardOnline(uint8_t code)
  {
    Serial.println();
    Serial.print("Card online ");
    Serial.println(code);     
  }
  static void OnCardInserted(uint8_t code)
  {
    Serial.println();
    Serial.print("Card inserted ");
    Serial.println(code); 
  }
  static void OnCardRemoved(uint8_t code)
  {
    Serial.println();
    Serial.print("Card removed ");
    Serial.println(code);  
  }
}; 

Servo servo_pivot;
Servo servo_wings;
Servo servo_pitch;
VL53L0X sensor;

// Setup for soundcard
SoftwareSerial secondarySerial(4, 2); // RX, TX
DFMiniMp3<SoftwareSerial, Mp3Notify> mp3(secondarySerial);

// Setup for radio
RF24 radio(10, 9);               // nRF24L01 (CE,CSN)
RF24Network network(radio);      // Include the radio in the network
const uint64_t this_node = 01;   // This turret  - Red - in Octal format ( 04,031, etc)
const uint64_t WHT = 02;      // Turret 02 - White
const uint64_t BLU = 03;      // Turret 03 - Blue
const uint64_t MTC = 00;      // Master Turret Control
unsigned long previousMillis1 = 0;
unsigned long previousMillis2 = 0;
unsigned long previousMillis3 = 0;
byte LED_LH_up = A1;
byte LED_LH_down = A2;
byte LED_CENTRE = A3;
byte LED_RH_up = 7;
byte LED_RH_down = 8;
byte PIVOT = 6; //white
byte WINGS = 3; //yellow
byte PITCH = 5; //blue
byte parkPIVOT = 96;  //Smaller number rotates CW as viewed from the top
byte posPIVOT = 96;
byte maxPIVOT = 116;
byte minPIVOT = 76;
byte WINGclose = 165;
byte WINGopen = 10;
byte WINGpos = 160;
byte parkPITCH = 86;
byte posPITCH = 86;
byte maxPITCH = 96;
byte minPITCH = 75;
byte pos = 90;
byte pulse = 20;
byte pitchCW = 1;
byte pivotCW = 1;
byte randomWake;
byte randomOpen;
byte randomFalse;
byte randomStart;
byte randomDisengage;
int triggerDistance = 300; 
byte buttonStatus;
byte busyRed = 1;
byte restModeWhite;
byte goState;
int x;
int y;
byte pb1State; // Fire
byte pb2State; // say random comment
byte pb3State;
byte randomPic;
// Payload from Master Turret Control (MTC)
// int payload [] = {0, 1,    2    ,    3    ,     4   ,    5   };
// int payload [] = {x, y, pb1State, pb2State, pb3State, goState};
int payload [6];

/* This is the "conversation" map for "Chat Time".  
 * 0-99 = Red Turret sayings 
 * 100-199 = White Turret sayings 
 * 200-299 = Blue Turret sayings
 * Files on all SD cards are saved as 0-100.
 * Add 100 to the file number here for White, 200 for Blue.
 * File 204 would be BLUE turret, file number 0004.
 */ 
int chatSayings [] = {
  0,              // Start pause on i = 0, followed by "rounds"...
  204, 164, 25,   // 1
  205, 127, 76,   // 2
  208, 162, 65,   // 3
  143, 230, 23,   // 4
  130, 41, 225,   // 5
  153, 31, 133,   // 6
  234, 49, 155,   // 7
  229, 175, 74,   // 8
  231, 58, 226,   // 9
  161, 223, 59,   // 10
  227, 68, 236,   // 11
  136, 50, 224,   // 12
  34, 160, 78,    // 13
  222, 42         // End
};

/* This is the RED and WHITE turret timing map.  They share sayings.
 *  These timings correspond to the time needed
 *  to play the individual sayings, in milliseconds.
 *  Change the sayings above as desired, but do not change these timings.
 *  For example, i = 2 will take 0.8 seconds (NormalTimings[2])
 *  to play the chatSayings[2] file.
 */
int NormalTimings [] = {
1000,  // Start pause on i = 0, followed by "rounds"...
2600, 800, 2800, 900, 1700, 1600, 1300, 2500, 1400, 1900,     // 1 - 10
1600, 2300, 800, 3000, 300, 100, 200, 0, 0, 300,              // 11 - 20
298000, 1300, 2600, 1300, 1400, 2100, 1900, 1600, 800, 1700,  // 21 - 30
1100, 1000, 1000, 2100, 1500, 1300, 1100, 800, 1200, 1000,    // 31 - 40
2200, 1700, 1300, 1400, 1500, 1000, 2000, 500, 2700, 9000,    // 41 - 50
1100, 1200, 900, 2400, 1200, 1100, 2100, 2000, 2500, 1700,    // 51 - 60
1100, 1000, 1100, 500, 1900, 0, 1300, 2100, 1700, 900,        // 61 - 70
1100, 800, 1100, 1700, 1100, 1100, 1500, 1500, 500, 900,      // 71 - 80
2100                                                          // 81
};
/* This is the BLUE turret timing map.
 *  These timings correspond to the time needed
 *  to play the individual sayings, in seconds.
 *  For example, i = 2 will take 0.9 seconds (DefectiveTimings[2])
 *  to play the chatSayings [2] file.
 */
int DefectiveTimings [] = {
1000,   // Start pause on i = 0, followed by "rounds"...
1700, 900, 2000, 600, 1100, 1800, 1900, 3000, 1500, 800,    // 1 - 10
2100, 800, 1900, 900, 3200, 2700, 0, 0, 0, 2000,            // 11 - 20
4400, 800, 3200, 900, 1400, 2000, 2100, 1200, 1300, 1000,   // 21 - 30
1100, 1400, 2100, 1000, 1600, 1000, 1200                    // 31 - 40
};
/////////////////////////////////////////////////////////////////// 
//======================= SETUP =================================//
///////////////////////////////////////////////////////////////////
void setup(){
   secondarySerial.begin(9600);//
   Serial.begin(9600);//
   mp3.begin();
   mp3.setVolume(22);
   Wire.begin();
   SPI.begin();  // Radio setup
   radio.begin();
   radio.setPALevel(RF24_PA_LOW); // set radio to low power.  All near each other
   radio.setDataRate(RF24_2MBPS); // I find this works best with multiple radios
   network.begin(70, this_node);  //(channel, node address)
   sensor_read();
   pinMode(LED_LH_up, OUTPUT);
   pinMode(LED_LH_down, OUTPUT);
   pinMode(LED_CENTRE, OUTPUT);
   pinMode(LED_RH_up, OUTPUT);
   pinMode(LED_RH_down, OUTPUT);
   digitalWrite(LED_CENTRE, HIGH);
   activate_servos();
   servo_wings.write(WINGopen); // open wings
   servo_pivot.write(parkPIVOT); // park pivot
   servo_pitch.write(parkPITCH); // park pitch
   randomWake = random(1, 3);
   mp3.playMp3FolderTrack(1); // play waking up comment
   delay(2000);
   servo_wings.write(WINGclose); // close wings
   delay(1500);
   digitalWrite(LED_CENTRE, LOW);
   turn_off_servos();
   busyRed = 0;
}
///////////////////////////////////////////////////////////////////
//======================= MAIN LOOP =============================//
///////////////////////////////////////////////////////////////////
void loop(){
  while (sensor.readRangeSingleMillimeters()>triggerDistance) { //nothing in front of sensor, do nothing
    ReadNet();
    WriteNet();
    output_sensor();
    if (payload[5] == 1) { // Conditions used with MTC. Turret will work automatically without MTC
      delay(500);
      WriteNet();
      Cara_Mia(); // Opera time!!  
    }
    else if (payload[5] == 2) { 
      delay(500);
      WriteNet();
      Chatty_time(); // Chatty time!!}
      ReadNet();
    }
    else if (payload[5] == 3) {
      delay(500);
      WriteNet();
      ManualControl (); // Manual Control
    }     
  }
  
  if (sensor.readRangeSingleMillimeters()<triggerDistance){ //something in front of sensor
    delay (200); //wait before checking again to see if someone still there...
    if (sensor.readRangeSingleMillimeters()<triggerDistance){ //someone there (not false trigger)
      busyRed = 1;
      ReadNet();
      WriteNet();
      output_sensor();
      activate_servos(); // wake up servos
      activate(); // open wings and say "I see you" comment
      if (sensor.readRangeSingleMillimeters()>triggerDistance){ // opened up and person gone
        falseActivate();  //say "where'd you go?" comment and close up
        delay (2000);
        scanArea(); //perform scan of area
      }
      else { // someone definitely there - open fire!! 
        engage();
        delay (2400); 
        for (int j=0; j <= 2; j++){
          if (sensor.readRangeSingleMillimeters()<triggerDistance){ // as long as someone there...
            for (int i=0; i <= 25; i++){ // fire for a short period
              fire();} // shoot them...
            output_sensor();
          }
        }
      }      
    output_sensor(); 
    disengage(); // no more target, stop firing and prepare to close
  }
  else {
    output_sensor();
    delay(350);
    }
  }
}

///////////////////////////////////////////////////////////////////
//======================= SUBROUTINES ===========================//
///////////////////////////////////////////////////////////////////

//=====  read the VLX53 sensor  =====//
void sensor_read(){  
  sensor.init();
  sensor.setTimeout(100);
  // lower the return signal rate limit (default is 0.25 MCPS)
  sensor.setSignalRateLimit(0.25); // started with 0.1
  // increase laser pulse periods (defaults are 14 and 10 PCLKs)
  sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 14); //started with 18
  sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 10); //started with 14
}
//=====  monitor output for debugging  =====//
void output_sensor(){ // Option out or delete if not interested.
  Serial.println();
  Serial.print ("-RED-  ");
  Serial.print("Distance "); Serial.print(sensor.readRangeSingleMillimeters()); Serial.print ("\t");
  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
  Serial.print(F("Pivot< ")); Serial.print (posPIVOT); Serial.print ("   ");
  Serial.print(F("Pitch< ")); Serial.print (posPITCH); Serial.print ("   ");
  Serial.print(F("Wings< ")); Serial.print (WINGpos); Serial.print ("   ");
  Serial.print(F("busyRed: "));Serial.print (busyRed); Serial.print ("   ");
  Serial.print(F("x :"));Serial.print (payload[0]); Serial.print ("\t");
  Serial.print(F("y :"));Serial.print (payload[1]); Serial.print ("\t");
  Serial.print(F("pb1 :"));Serial.print (payload[2]); Serial.print ("   ");
  Serial.print(F("pb2 :"));Serial.print (payload[3]); Serial.print ("   ");
  Serial.print(F("pb3 :"));Serial.print (payload[4]); Serial.print ("   ");
  Serial.print(F("goState: ")); Serial.print(payload[5]);Serial.print ("   ");
}
//=====  update servo positions =====//
void increment_servos(){ 
  if (pitchCW == 0) posPITCH = posPITCH - 3; // the higher the number, the jerkier the motion
  if (pitchCW == 1) posPITCH = posPITCH + 3;
  if (pivotCW == 0) posPIVOT = posPIVOT - 3;
  if (pivotCW == 1) posPIVOT = posPIVOT + 3;
  if (posPIVOT >= maxPIVOT) pivotCW = 0;
  if (posPIVOT <= minPIVOT) pivotCW = 1;
  if (posPITCH >= maxPITCH) pitchCW = 0;
  if (posPITCH <= minPITCH) pitchCW = 1;
}
///////////////////////////////////////////////////////////////////
//======================= ACTIVATE ==============================//
///////////////////////////////////////////////////////////////////
void activate(){ // open up wings and say something
  busyRed = 1;
  ReadNet();
  WriteNet();
  output_sensor();
  digitalWrite(LED_CENTRE, HIGH); //LED eye on
  randomOpen = random(3, 6);// pick random opening comment
  mp3.playMp3FolderTrack(randomOpen); // play random "I see you" comment 
  servo_wings.write(WINGopen); // open wings
  output_sensor();
  delay (3400);
}
///////////////////////////////////////////////////////////////////
//====================FALSE ACTIVATE ============================//
///////////////////////////////////////////////////////////////////
void falseActivate(){ // 
  busyRed = 1;
  ReadNet();
  WriteNet();
  output_sensor();
  randomFalse = random(6, 9);// pick random opening comment
  mp3.playMp3FolderTrack(randomFalse); // play random "where'd you go?" comment
  delay (1800);
}
///////////////////////////////////////////////////////////////////
//======================= SCAN AREA =============================//
///////////////////////////////////////////////////////////////////
void scanArea(){ // continue scanning for a bit after falseActivate
  busyRed = 1;
  ReadNet();
  WriteNet();
  output_sensor();
  mp3.playMp3FolderTrack(2); // "searching..."
  servo_pitch.write(parkPITCH);
  delay(1600);
  servo_pitch.detach();
  servo_wings.detach();
  mp3.playMp3FolderTrack(21);
  for (int i=0; i <= 220; i++){ //scan for a little bit...
    output_sensor();
    if (pivotCW == 0) posPIVOT = posPIVOT - 1; // increment one step CW if CW = 0
    if (pivotCW == 1) posPIVOT = posPIVOT + 1; // otherwise go one step other direction
    if (posPIVOT >= maxPIVOT) pivotCW = 0; // if max rotation clockwise, switch to counterclockwise
    if (posPIVOT <= minPIVOT) pivotCW = 1; // if min rotation counterclockwise,switch to clockwise
    servo_pivot.write(posPIVOT);
    if (sensor.readRangeSingleMillimeters()<triggerDistance/2){ //Somebody stepped in front
      i = 350;
      engage();  
      delay (2500);
      activate_servos();
      for (int i=0; i <= 25; i++){ // fire for a short period
        fire(); // shoot them...
      } 
    }
  }
  activate_servos(); // fully scanned with no one passing...
  servo_pivot.write(parkPIVOT); //close up.
  output_sensor();
  delay(1200);
}
///////////////////////////////////////////////////////////////////
//======================= ENGAGE ================================//
///////////////////////////////////////////////////////////////////
void engage(){ //smartass comment before firing
  busyRed = 1;
  ReadNet();
  WriteNet();
  output_sensor();
  randomStart = random(9, 12);// pick random smartass comment before firing
  mp3.playMp3FolderTrack(randomStart);
  output_sensor();
}
///////////////////////////////////////////////////////////////////
//======================= FIRE ==================================//
///////////////////////////////////////////////////////////////////
void fire(){ // fire sound and turret movement
  
  ReadNet();
  WriteNet();
  output_sensor();
  mp3.playMp3FolderTrack(15);
  servo_pivot.write(posPIVOT);
  servo_pitch.write(posPITCH);
  digitalWrite(LED_CENTRE, HIGH);
  digitalWrite(LED_LH_up, LOW);    
  digitalWrite(LED_LH_down, HIGH);        
  digitalWrite(LED_RH_up, LOW);                      
  digitalWrite(LED_RH_down, HIGH);     
  delay(pulse*2); 
  servo_pivot.write(posPIVOT);
  servo_pitch.write(posPITCH);
  digitalWrite(LED_LH_up, HIGH);    
  digitalWrite(LED_LH_down, LOW);        
  digitalWrite(LED_RH_up, HIGH);                      
  digitalWrite(LED_RH_down, LOW);  
  delay(pulse); 
  digitalWrite(LED_LH_up, LOW); 
  digitalWrite(LED_RH_up, LOW);            
  increment_servos(); // update servo position
}
///////////////////////////////////////////////////////////////////
//======================= DISENGAGE =============================//
///////////////////////////////////////////////////////////////////
void disengage(){ //re-align wings (pitch) and pivot home before closing wings
  busyRed = 1;
  ReadNet();
  WriteNet();
  output_sensor();
  delay(2000);
  randomDisengage = random(12, 15);
  mp3.playMp3FolderTrack(randomDisengage); // "Goodbye" comment
  servo_pivot.write(parkPIVOT);
  servo_pitch.write(parkPITCH);
  digitalWrite(LED_LH_up, LOW);    
  digitalWrite(LED_LH_down, LOW);        
  digitalWrite(LED_RH_up, LOW);                      
  digitalWrite(LED_RH_down, LOW); // turn off firing LEDs
  delay (2000);
  servo_wings.write(WINGclose);
  delay (1500);
  digitalWrite(LED_CENTRE, LOW); // turn off central LED
  delay (100);
  output_sensor();
  turn_off_servos();
  busyRed = 0;
}
void turn_off_servos(){ // detach servos so they're not engaged
  servo_pivot.detach();
  servo_pitch.detach();
  servo_wings.detach();  
}
void activate_servos(){ // activate servos for movement
  servo_pivot.attach(PIVOT);
  servo_pitch.attach(PITCH);
  servo_wings.attach(WINGS);  
}

/////////////////////////////////////////////////////////////////// 
//======================= CARA MIA OPERA ========================//
///////////////////////////////////////////////////////////////////
void Cara_Mia(){
  busyRed = 1;
  WriteNet();
  digitalWrite(LED_CENTRE, HIGH);
  int randomWingPos;
  activate_servos();
  unsigned long endTimer[] = {8200, 40000, 100000}; // 
  unsigned long startTimer;
  for (int i=0; i <= 2; i++) {
    startTimer = millis();
    mp3.playMp3FolderTrack(100 + i);
    while (millis() < (startTimer + endTimer[i])){
      ReadNet();
      WriteNet();
      if (payload[4] == 0) {
        disengage();
        busyRed = 0;
        WriteNet();
        return;}
        //  debugging print below.  Delete or comment out as desired.
      Serial.print(F("millis() ")); Serial.print (millis()); Serial.print ("   ");
      Serial.print(F("startTimer ")); Serial.print (startTimer); Serial.print ("   ");
      Serial.print(F("endTimer ")); Serial.print (endTimer[i]); Serial.print ("   ");
      Serial.print(F("End Time ")); Serial.print (endTimer[i] + startTimer); Serial.print ("   ");
      Serial.print(F("previousMillis1 ")); Serial.print (previousMillis1); Serial.print ("   ");
      Serial.println();
      if ((millis() - previousMillis1) >= (850 + (i * 100))) { // 1050
        randomWingPos = random(10 + (i*20), (60 + (i*20)));
        servo_wings.write(randomWingPos);      
        previousMillis1 = millis();    
      }
    } 
  }
  disengage();
  busyRed = 0;
  goState = 0;
  mp3.stop();
  ReadNet();
  delay(1000);
}
/////////////////////////////////////////////////////////////////// 
//======================= CHATTY TIME ===========================//
///////////////////////////////////////////////////////////////////
void Chatty_time(){
  busyRed = 1;
  WriteNet();
  int i = 0;
  int talk;
  int saying;
  int timeadder = 750;
  int talkTime = NormalTimings[i];
  int randomPivotPos;
  activate_servos();
  servo_wings.write(WINGopen);
  digitalWrite(LED_CENTRE, HIGH);
  do {
    ReadNet();
    WriteNet();
    //output_sensor(); //  used for debugging...
    if (i >= 43) { // end of sequence
      busyRed = 0;
      WriteNet();
      disengage();
      return;
    }
    unsigned long currentMillis = millis(); // grab current time
    if ((unsigned long)(currentMillis - previousMillis3) >= talkTime) {
      if (chatSayings[i] < 100) { // RED Turret talking
        talk = chatSayings[i];
        saying = chatSayings[i];
        talkTime = (NormalTimings[saying] + timeadder); 
      }
      else if ((chatSayings[i] > 99) && (chatSayings[i] < 200)) { // WHITE turret talking
        talk = 0;
        saying = chatSayings[i] - 100;
        talkTime = (NormalTimings[saying] + timeadder);
      }
  
      else {  // BLUE turret talking
        talk = 0;
        saying = chatSayings[i] - 200; // sound file # of BLUE
        talkTime = (DefectiveTimings[saying] + timeadder); // Time for that saying
      }

      if (talk == 0) {
        digitalWrite(LED_CENTRE, LOW);
      }
      else {
        digitalWrite(LED_CENTRE, HIGH);
        mp3.playMp3FolderTrack(talk);
      }
      randomPivotPos = random(minPIVOT, maxPIVOT);
      servo_pivot.write(randomPivotPos);
      Serial.println();
      Serial.print(F("i: ")); Serial.print (i); Serial.print ("\t");
      Serial.print(F("chatSayings[i] ")); Serial.print (chatSayings[i]); Serial.print ("\t");
      Serial.print(F("Saying ")); Serial.print (saying); Serial.print ("\t");
      Serial.print(F("talk ")); Serial.print (talk); Serial.print ("\t");
      Serial.print(F("chat time ")); Serial.print (talkTime); Serial.print ("\t");
      Serial.print(F("busyRed: "));Serial.print (busyRed); Serial.print ("   ");
      previousMillis3 = millis();
      i++;
    }
  }
  while (payload[4] == 1);
  busyRed = 0;
  WriteNet();
  digitalWrite(LED_CENTRE, LOW); 
  disengage();
}
/////////////////////////////////////////////////////////////////// 
//======================= MANUAL CONTROL =======================//
///////////////////////////////////////////////////////////////////
void ManualControl(){
  int servoWings;
  int servoPitch;
  int servoPivot;
  activate_servos();
  servo_wings.write(WINGopen);
  digitalWrite(LED_CENTRE, HIGH);
  ReadNet();  
  do {
    output_sensor();
    ReadNet();
    servoPivot = map(payload[0], 1023, 0, minPIVOT, maxPIVOT);  
    servoPitch = map(payload[1], 1023, 0, minPITCH, maxPITCH);  
    servo_pivot.write(servoPivot);
    servo_pitch.write(servoPitch);
    unsigned long currentMillis = millis(); // grab current time
    if (payload[3] == 0) {
      if ((unsigned long)(currentMillis - previousMillis1) >= 2500) {  
      randomPic = random(1, 20);
      mp3.playMp3FolderTrack(randomPic);
      previousMillis1 = millis();
      }
    }
    if (payload[2] == 0){
      fire();
    }  
  }
  while (payload[5] == 3);
  disengage();
  busyRed = 0;
  WriteNet();
  digitalWrite(LED_CENTRE, LOW); 
}
///////////////////////////////////////////////////////////////////
//========================= RECEIVING ===========================//
///////////////////////////////////////////////////////////////////
void ReadNet(){
  network.update();
  if ( network.available() )  {
    RF24NetworkHeader header;
    network.peek(header);
    network.read(header, &payload, sizeof(payload));} // Read the package        
}
///////////////////////////////////////////////////////////////////
//========================= SENDING =============================//
///////////////////////////////////////////////////////////////////
void WriteNet(){
  network.update();
  RF24NetworkHeader header4(MTC);
  bool ok4 = network.write(header4, &busyRed, sizeof(busyRed));
/*  if (ok4) { // used for debugging...
    Serial.print("MTC ok4  ");}
  else {
    Serial.print("-------  ");} 
    */
}

Credits

Novachris

Novachris

0 projects • 12 followers

Comments