Atem tally light code (creating tally byte)

Hi,

I'm trying to create a byte that contains all the program and tally information but there is someting wrong with the creation of the byte (and maybe also with me progamming skills :wink:
The byte is named payload.tally
This byte will later be send with a JeeLAb radio to wireless tally's

/*****************
 * Example: ATEM Monitor
 * Connects to the Atem Switcher and outputs changes to Preview and Program on the Serial monitor (at 9600 baud)
 *
 * - kasper
 */
/*****************
 * TO MAKE THIS EXAMPLE WORK:
 * - You must have an Arduino with Ethernet Shield (or compatible such as "Arduino Ethernet", http://arduino.cc/en/Main/ArduinoBoardEthernet)
 * - You must have an Atem Switcher connected to the same network as the Arduino - and you should have it working with the desktop software
 * - You must make specific set ups in the below lines where the comment "// SETUP" is found!
 */



// Including libraries: 
#include <SPI.h>         // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <ATEMTally.h>
#include <TextFinder.h>
#include <EEPROM.h>
//#include <MemoryFree.h>


// MAC address and IP address for this *particular* Arduino / Ethernet Shield!
// The MAC address is printed on a label on the shield or on the back of your device
// The IP address should be an available address you choose on your subnet where the switcher is also present
byte mac[] = { 
  0x90, 0xA2, 0xDA, 0x0D, 0x6B, 0xB9 };      // <= SETUP!  MAC address of the Arduino
IPAddress ip(192, 168, 10, 99);              // <= SETUP!  IP address of the Arduino


// Include ATEM library and make an instance:
// Connect to an ATEM switcher on this address and using this local port:
// The port number is chosen randomly among high numbers.
#include <ATEM.h>
ATEM AtemSwitcher(IPAddress(192, 168, 10, 240), 56417);  // <= SETUP (the IP address of the ATEM switcher)



// No-cost stream operator as described at 
// http://arduiniana.org/libraries/streaming/
template<class T>
inline Print &operator <<(Print &obj, T arg)
{  
  obj.print(arg); 
  return obj; 
}

// create a new AtemSwitcher and ATEMTally object
//ATEM AtemSwitcher;
ATEMTally ATEMTally;
  
// define a structure for sending over the radio
struct {
  	byte tally;
} payload;

void setup() { 

  // Start the Ethernet, Serial (debugging) and UDP:
  Ethernet.begin(mac,ip);
  Serial.begin(9600);
  Serial << F("\n- - - - - - - -\nSerial Started\n");  

  // Initialize a connection to the switcher:
//koen  AtemSwitcher.serialOutput(true);  // Remove or comment out this line for production code. Serial output may decrease performance!
  AtemSwitcher.connect();

  // Shows free memory:  
//  Serial << F("freeMemory()=") << freeMemory() << "\n";
}

void loop() {
  // Check for packets, respond to them etc. Keeping the connection alive!
  // VERY important that this function is called all the time - otherwise connection might be lost because packets from the switcher is
  // overlooked and not responded to.
    AtemSwitcher.runLoop();

  // If connection is gone anyway, try to reconnect:
  if (AtemSwitcher.isConnectionTimedOut())  {
    Serial << F("Connection to ATEM Switcher has timed out - reconnecting!\n");
    AtemSwitcher.connect();
  }  else  {
            payload.tally = 
             for (uint8_t i=1;i<=8;i++) {
               bitset(AtemSwitcher.getProgramTally(i),8+i-1)
             }
            ;
               for (uint8_t i=1;i<=8;i++) {
               bitset(AtemSwitcher.getPreviewTally(i),i-1)
             }
            ;

            Serial.print ("Tally byte= ");
            Serial.println (payload.tally,BIN);
            
        
            
  }

  // If you fancy to make delays in your sketches, ALWAYS do it using the AtemSwitcher delay function - this will wait while calling ru
  // Loop() checking for packets and thus keeping the connection up.
    AtemSwitcher.delay(50);


  // If you monitor the serial output, you should see a lot of "ACK, rpID: xxxx" and then every 5 seconds this message:
//koen  Serial << F("End of normal loop() - still kicking?\n");

  // Now, try also to disconnect the network cable - and see if it reconnects properly.
}

I hope someone can help me out.

Kind regards Koen

but there is someting wrong with the creation of the byte

But you're not going to tell us what that "someting" is, or why you suspect that there is "someting" wrong.

payload.tally = 
             for (uint8_t i=1;i<=8;i++) {
               bitset(AtemSwitcher.getProgramTally(i),8+i-1)
             }

A for loop does not return a value. You can't assign a non-value to payload.tally. You can't set a bit in a function call. bitset shoiuld be bitSet.

Try again.

It seems to me that the first argument to bitSet should be payload.tally, since that is the value that you want to set the bit in.

Hi Paul,

Thx for your quick reply.
I changed the code to

[             for (uint8_t i=1;i<=8;i++) {
               if (AtemSwitcher.getProgramTally(i)){
                 bitSet((payload.tally),8+i-1);
               }
             }
            
             for (uint8_t i=1;i<=8;i++) {
               if (AtemSwitcher.getPreviewTally(i)){
                 bitSet((payload.tally),i-1);
               }
             }
/code]

Now the sketch is compiling :D

I will test the code a soon i have the ATEM availible.

Kind regards 
Koen