I Need help on my Duino Tag

i’m kinda lost
here is where i got the code and built the tagger

http://lizarum.com/assignments/physical_computing/2010/summer/duino_tag.html#

i can’t get it to work i keep on getting errors

15: error:expected intializer before 'senseIR'
Ino: in function 'void loop ()' :
143: error: expected intializer before 'senseIR'
293: error: expected '}' at end of input
/*
* Giving Credit where Credit Is Due
*
* Portions of this code were derived from code posted in the Arduino forums by Paul Malmsten.
* You can find the original thread here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1176098434
*
* The Audio portion of the code was derived from the Melody tutorial on the Arduino wiki
* You can find the original tutorial here: http://arduino.cc/en/Tutorial/Melody
*/

int sensorPin  = 2;      // Sensor pin 1
int senderPin  = 3;      // Infrared LED on Pin 3
int triggerPin = 4;      // Pushbutton Trigger on Pin 4
int speakerPin = 12;     // Positive Lead on the Piezo
int blinkPin   = 13;     // Positive Leg of the LED we will use to indicate signal

int startBit   = 2000;   // This pulse sets the threshold for a transmission start bit
int endBit     = 3000;   // This pulse sets the threshold for a transmission end bit
int one        = 1000;   // This pulse sets the threshold for a transmission that represents a 1
int zero       = 400;    // This pulse sets the threshold for a transmission that represents a 0
int trigger;             // This is used to hold the value of the trigger read;
boolean fired  = false;  // Boolean used to remember if the trigger has already been read.
int ret[2];              // Used to hold results from IR sensing.
int waitTime = 300;     // The amount of time to wait between pulses

int playerLine = 17;     // Any player ID >= this value is a referee, < this value is a player;
int myCode     = 1187;      // This is your unique player code;
int myLevel    = 1;      // This is your starting level;
int maxShots   = 6;      // You can fire 6 safe shots;
int maxHits    = 3;      // After 6 hits you are dead;
int myShots    = 0;      // You can fire 6 safe shots;
int myHits     = 0;      // After 6 hits you are dead;

int maxLevel   = 9;      // You cannot be promoted past level 9;
int minLevel   = 0;      // You cannot be demoted past level 0

int refPromote = 0;      // The refCode for promotion;
int refDemote  = 1;      // The refCode for demotion;
int refReset   = 2;      // The refCode for ammo reset;
int refRevive  = 3;      // The refCode for revival;

int replySucc  = 14;     // the player code for Success;
int replyFail  = 15;     // the player code for Failed;

void setup() {
  pinMode(blinkPin, OUTPUT);
  pinMode(speakerPin, OUTPUT);
  pinMode(senderPin, OUTPUT);
  pinMode(triggerPin, INPUT);
  pinMode(sensorPin, INPUT);
  randomSeed(analogRead(0));
  for (int i = 1;i < 4;i++) {
    digitalWrite(blinkPin, HIGH);
    playTone(900*i, 200);
    digitalWrite(blinkPin, LOW);
    delay(200);
  }

  Serial.begin(9600);
  Serial.println("Ready: ");
}

void loop() {
  senseFire();
{
  
  if (ret[0] != -1) {
    playTone(1000, 50);
    Serial.print("Who: ");
    Serial.print(ret[0]);
    Serial.print(" What: ");
    Serial.println(ret[1]);
    if (ret[0] >= playerLine) {
      if (ret[1] == refPromote) {
        // Promote
        if (myLevel < maxLevel) {
          Serial.println("PROMOTED!");
          myLevel++;
          playTone(900, 50);
          playTone(1800, 50);
          playTone(2700, 50);
        }
      } else if (ret[1] == refDemote) {
        // demote
        if (myLevel > minLevel) {
          Serial.println("DEMOTED!");
          myLevel--;
        }
          playTone(2700, 50);
          playTone(1800, 50);
          playTone(900, 50);
      } else if (ret[1] == refReset) {
        Serial.println("RESET!");
        myShots = maxShots;
        playTone(900, 50);
        playTone(450, 50);
        playTone(900, 50);
        playTone(450, 50);
        playTone(900, 50);
        playTone(450, 50);
      } else if (ret[1] == refRevive) {
        Serial.println("REVIVED!");
        myShots = 0;
        myHits = 0;
        myLevel = 1;
        playTone(900, 50);
        playTone(1800, 50);
        playTone(900, 50);
        playTone(1800, 50);
        playTone(900, 50);
        playTone(800, 50);
      }
    } else {
      if (ret[1] == replySucc) {
        playTone(9000, 50);
        playTone(450, 50);
        playTone(9000, 50);
        Serial.println("SUCCESS!");        
      } else if (ret[1] == replyFail) {
        playTone(450, 50);
        playTone(9000, 50);
        playTone(450, 50);
        Serial.println("FAILED!");        
      }
      if (ret[1] <= maxLevel && ret[1] >= myLevel){
        if(myHits < maxHits) {
             Serial.println("HIT!");
             myHits++;
             playTone(9000, 50);
             playTone(900, 50);
             playTone(9000, 50);
             playTone(900, 50);
         }else{
            Serial.println("DEAD!");
            playTone(1000, 50);
            playTone(9000, 50);
        }
        }
   }
}


void  loop senseIR ()
   int who[4];
   int what[4];
   int end;
  if (pulseIn(sensorPin, LOW, 50) < startBit) {
    digitalWrite(blinkPin, LOW);
    ret[0] = -1;
    return;
  }
  digitalWrite(blinkPin, HIGH);
  who[0]   = pulseIn(sensorPin, LOW);
  who[1]   = pulseIn(sensorPin, LOW);
  who[2]   = pulseIn(sensorPin, LOW);
  who[3]   = pulseIn(sensorPin, LOW);
  what[0]  = pulseIn(sensorPin, LOW);
  what[1]  = pulseIn(sensorPin, LOW);
  what[2]  = pulseIn(sensorPin, LOW);
  what[3]  = pulseIn(sensorPin, LOW);
  end      = pulseIn(sensorPin, LOW);
  if (end <= endBit) {
    Serial.print(end);
    Serial.println(" : bad end bit");
    ret[0] = -1;
    return;
  }
  Serial.println("---who---");
  for(int i=0;i<=3;i++) {
    Serial.println(who[i]);
    if(who[i] > one) {
      who[i] = 1;
    } else if (who[i] > zero) {
      who[i] = 0;
    } else {
      // Since the data is neither zero or one, we have an error
      Serial.println("unknown player");
      ret[0] = -1;
      return;
    }
  }
  ret[0]=convert(who);
  Serial.println(ret[0]);

  Serial.println("---what---");
  for(int i=0;i<=3;i++) {
    Serial.println(what[i]);
    if(what[i] > one) {
      what[i] = 1;
    } else if (what[i] > zero) {
      what[i] = 0;
    } else {
      // Since the data is neither zero or one, we have an error
      Serial.println("unknown action");
      ret[0] = -1;
      return;
    }
  }
  ret[1]=convert(what);
  Serial.println(ret[1]);
  return;
}

void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
  }
}

int convert(int bits[]) {
  int result = 0;
  int seed   = 1;
  for(int i=3;i>=0;i--) {
    if(bits[i] == 1) {
      result += seed;
    }
    seed = seed * 2;
  }
  return result;
}

void senseFire() {
  trigger = digitalRead(triggerPin);
  if (trigger == LOW && fired == false) {
    Serial.println("Button Pressed");
    fired = true;
    myShots++;
    if (myHits <= maxHits && myShots > maxShots && random(1,20) <= myShots) {
      Serial.println("SELF DESTRUCT");
      selfDestruct();
    } else if (myHits <= maxHits) {
      Serial.print("Firing Shot : ");
      Serial.println(myShots);
      fireShot(myCode, myLevel);
    }
  } else if (trigger == HIGH) {
    if (fired == true) {
      Serial.println("Button Released");
    }
    // reset the fired variable
    fired = false;
  }
}

void fireShot(int player, int level) {
  int encoded[8];
  digitalWrite(blinkPin, HIGH);
  for (int i=0; i<4; i++) {
    encoded[i] = player>>i & B1;   //encode data as '1' or '0'
  }
  for (int i=4; i<8; i++) {
    encoded[i] = level>>i & B1;
  }
  // send startbit
  oscillationWrite(senderPin, startBit);
  // send separation bit
  digitalWrite(senderPin, HIGH);
  delayMicroseconds(waitTime);
  // send the whole string of data
  for (int i=7; i>=0; i--) {
    if (encoded[i] == 0) {
      oscillationWrite(senderPin, zero);
    } else {
      oscillationWrite(senderPin, one);
    }
    // send separation bit
    digitalWrite(senderPin, HIGH);
    delayMicroseconds(waitTime);
  }
  oscillationWrite(senderPin, endBit);
  playTone(100, 5);
  digitalWrite(blinkPin, LOW);
}

void oscillationWrite(int pin, int time) {
  for(int i = 0; i <= time/26; i++) {
    digitalWrite(pin, HIGH);
    delayMicroseconds(13);
    digitalWrite(pin, LOW);
    delayMicroseconds(13);
  }
}

void selfDestruct() {
  myHits  = maxHits+1;
  playTone(1000, 250);
  playTone(750, 250);
  playTone(500, 250);
  playTone(250, 250);
{

2013-08-22 19.59.36.jpg

void  loop senseIR (){

What the heck is this supposed to be?

http://forum.arduino.cc/index.php/topic,148850.msg1118324.html#post_codetags

Ok I was on my tablet so I fixed the post and the weird } inthe code near the senseIR wasn't suppose to be there. But I am still getting the same errors

But I am still getting the same errors

See reply #1.

Sensor on pin number 2 it is an IR receiver 38khz

:fearful:

Here is some light reading about the tagger

Parts Infrared LED-a T1 three-quarter IR LED Infrared sensor-a TSOP2138YA Infrared Sensor Single-pole momentary switch- the trigger Piezo element 22-gauge solid wire-two colors Resistors-100 ohm,10k and a 82 ohm Capacitors-one 0.1uF capacitor. Lens- A small magnifying lens (three-quarters to 1 inch in diameter) universal remote

The sensor The sensor combines a photo sensor and a preamp. Most IR sensors of this type combine these two features into one component for convenience. The housing acts as an IR filter. The housing of this sensor and other sensors of this type serve to filter out background IR. The sensor uses a carrier frequency of 38 kHz. This is a commonly used IR frequency and means that your guns will need to transmit at 38 kHz, as well. This sensor has a simple 3-pin interface: Pin 1 provides a signal when a 38-kHz IR signal is sensed. Pin 2 connects to a supply voltage. Pin 3 connects to a ground.

Wiring Use the Ardweeny instead of an Arduino For wiring the IR sensor, you need the 100 ohm resistor and the capacitor. The spec sheet for the sensor suggests adding a capacitor and a resistor to "suppress power supply disturbances." When you finalize your gun configuration, you will want these additional components wired as close to the sensor as possible. The output from the sensor comes from pin 1, which should be wired to pin 2 on the Arduino board. The supply voltage, which comes into the sensor on pin 2, should come through the 100-ohm resistor. Run a line from the +5v pin on the Arduino board to the resistor, and connect the resistor to pin 2 on the IR sensor. The IR sensor is grounded through pin 3. The 0.1uF capacitor should be connected between pins 2 and 3 on the sensor Wire the positive leg of the LED to pin 13 on the Arduino board and the negative leg of the LED to the ground. You'll use this LED to indicate that a signal is being received. Use the piezo element to produce a sound when a signal is received. Wire the positive lead from the piezo to pin 12 on the Arduino and wire the negative lead to a ground pin. Connect pin 3 of the Arduino to 1 end of the 82-ohm resistor. Connect the other side of the resistor to the anode of the IR led. Connect the cathode side of the LED to one lead of the button. The important thing here is that the infrared LED and the infrared sensor face the same direction.

Connect Arduino pin 4 to the other lead of the button( not the one that the LED is connected to). Wire one end of the 10k-ohm resistor the same lead of the button and the other end to 5v.

When you coded the receiver, you told it to recognize a start bit, then read nine more pulses. The first four pulses are used to represent the player who fired (your Who). The second four pulses are used to represent what is being fired (either the player's level or the referee's command code — your What). The final pulse is used to help eliminate bad signal reads from any remote controls that might be in the area. You know some things about how the gun should behave in firing mode. When the rules of 'Duino tag were established, there were several statements that affect how the gun will work: When the player pulls a trigger, a single shot is fired. When the gun is fired, it should make a cool sound like "PEW PEW." Each gun has six "safe" shots. There is no reload. Each shot a player fires past the sixth increases the possibility of catastrophic gun failure. In the event of catastrophic gun failure, the player is eliminated. Upload your finished code to your Arduino board. In order to test, you'll need two guns and two computers. Turn on the serial monitor and start firing the gun until it blows up. You should see messages that indicate the gun is being fired until the self-destruct sequence is fired. Reset your board, pick up the second gun, and at point-blank range, aim the gun so the infrared LED is pointed at the infrared radiation sensor on the gun connected to the serial monitor, and fire a shot. Both guns should make some noise, and you should see the shot registered in the serial monitor.

Setting up the 'Duino tag protocol When a shot is fired, the IR LED in the transmitter broadcasts a small piece of encoded data. Before you can really decode this data, you need to know what the data will be. Doing so will require making some assumptions that should be spelled out clearly. 'Duino Tag is not a game for cheaters. Meaning that everyone plays by the rules. You could establish a lot of protocol overhead to make sure nobody could cheat. Teams are organic in nature, not enforced by the hardware. This allows for all sorts of behavior, such as making verbal alliances, betraying your allies, and accidentally shooting your friends. A referee is necessary. The referee should be able to change a player's level or ammo, reset a gun, etc. The assumptions are outlined, and you're transmitting data in binary type, so the only remaining question is how many bits do you need for the protocol? If you break the protocol roughly in half, the first half represents "Who" and the second half represents "What." For example, Player 1 (who) fired a shot of strength 2 (what), or Referee 2 (who) resurrected you (what). Using four bits, you could transmit 16 unique codes — more than enough to start. Likewise, 16 actions would be more than enough to start for a player or a referee. You could fire a range of 16 kinds of shots, or perform 16 different administrative actions.

You need eight bits total — the first four will correspond to a player's number, and the last four will correspond to an action of some kind (shot strength, or referee action). Now that you know approximately what to expect, start writing some code for the sensor:

The code for the sensor is written in four parts. First, you need to set up the pins and run a brief test sequence in the setup function. Then you'll put together a function to decode incoming IR signals. After this function is put together, you set up the Loop function to listen for signals. Finally, you'll sort out a function to play some tones. 1.Open Arduino Change the value of int myCode to a unique number Upload the code to your Arduino board. In order to test, you'll need two guns and two computers. Turn on the serial monitor and start firing the gun until it blows up. You should see messages that indicate the gun is being fired until the self-destruct sequence is fired. Reset your board, pick up the second gun, and at point-blank range, aim the gun so the infrared LED is pointed at the infrared radiation sensor on the gun connected to the serial monitor, and fire a shot. Both guns should make some noise, and you should see the shot registered in the serial monitor. Take a few steps back and fire again. It won't take long until your shots are no longer being registered. Your range may only be a few feet. That probably doesn't seem very useful, but it's a problem that is easily solved.

The resistor and capacitor for your infrared radiation sensor need to be mounted close to the sensor.

Mount the sensor facing the front of the gun, in a way that's visible and not blocked by other components.

Mount your lens tube straight and so you can aim it easily.

You'll need to include some battery power for your Arduino board.

Easy access to your Arduino board, at least to upload new software

The Referee gun Built into the protocol is the ability for a referee to promote, demote, reset, and revive players. A Referee's gun would have different software and would need more buttons. The simplest way to implement what was written into the protocol would be to build a gun with four buttons, one for each function (promote, demote, reset and revive).

Targets You could easily put together a set of targets that could be installed around the play area. The targets could be used to get points, fire random shots, or act as automated referees

http://aterribleidea.com/2009/02/25/building-an-arduino-based-laser-tag-game/

Moderator edit: Changed code tags to quote tags. That wasn't code. (Nick Gammon)

void  loop senseIR ()
   int who[4];
   int what[4];

This is wrong in a number of ways. Closer would be:

void  senseIR ()
   {
   int who[4];
   int what[4];

DJWildBill:
:fearful:

Here is some light reading about the tagger
[…]

Well I’m sure that’s important and all but that doesn’t really help solve your problem.

First off, not to put words in anyone’s mouth but I believe that PaulS was complaining about the following line of code:

void  loop senseIR ()

Specifically the word ‘loop’ doesn’t belong in there, just to spell it out for you.

Now, having fixed that… what other errors does the compiler complain about?

So it doesn’t like line 293. If you scroll down to the bottom of your code you’ll see that it ends with an open ("{") bracket. I’d bet money that no code ever ends with an open bracket. Fix that. Still doesn’t compile.

Now what? Well, if it was me, and I didn’t have a clue as to what was wrong… First off I’d make a copy of the code as a backup, so I could go back and fix what was wrong when I finally knew what the problem was (since It’s probably something simple).

Then, since I’d suspect a format problem of some kind, I would start removing “extra” lines, like all the calculations and prints; the delays; pin I/O… but not any lines that define variables, since I want it to compile. Nor delete any control statements (for/if/while) or any open/close brackets, since missing/extra/wrong brackets are likely the issue.

I’d remove a few lines and re-compile to see if the problem was fixed. Then I’d know the problem was in the area of code I removed, OR the code would shrink enough that I could see the problem. Repeat the cut a bit of code and then compile process until the code will compile, then look at the last set of edits for the problem.

Of course a big help is the IDE’s “auto format” (Control-T). The last errors were reported around the senseIR function, which implies a problem with the loop function (or something upstream). I kept adding close brackets just before senseIR until the format looked right (and the errors went away).

To be specific, see the attached file.

I don’t know if the attached code works (now it’s time to study that extra data you provide) but it will compile. I hope I provided a bit of insight for you the next time you have a problem (as opposed to just fixing your errors).

Regards,

Brad
KF7FER

EDIT: Oh yeah as Nick mentions you forgot the open bracket.

newCode.txt (8.47 KB)

The one reason I added the light reading in case he was asking what is that as in what is this thing hooked to. Ok so I tried adding } for it to work and it didn't seem to work at all I spent 6 hours trying to redo the code I'm a type of guy that don't really ask for help but I was at my wits end.

void  loop senseIR ()

Specifically the word 'loop' doesn't belong in there, just to spell it out for you.

Now, having fixed that... what other errors does the compiler complain about.

[\quote]

took away the loop I added the bracket took away the bracket and ripped out some hair and still told me the same thing.

ok i am going to go over your code line for line and see what i did wrong but it works. now i have to fix the sound cause it keeps going and going and going....... Thanks to everyone who helped i think i just needed to sleep on it [quote author=Brad Burleson link=topic=184012.msg1363045#msg1363045 date=1377232776]

I don't know if the attached code works (now it's time to study that extra data you provide) but it will compile. I hope I provided a bit of insight for you the next time you have a problem (as opposed to just fixing your errors).

Regards,

Brad KF7FER

EDIT: Oh yeah as Nick mentions you forgot the open bracket. [/quote]