Variable Score/Points


i need some help getting a score to stop after adding 1 point everytime it receives the correct value at the moment when it receives the correct value it keep adding to the score

Pictures of code suck.

You want the variable Red_Life to count to 1 then stop counting?

if( Red_Life < 1 )
{
Red_Life++;
}

I'm new to arduino programming. I need the red and blue team to add 1 point every time it receives the value and then stop this is for a laser tag capture the flag but when it gets shot with blue or red team the score it just keeps adding points.

#include <IRremote.h>
#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
#include <Adafruit_SSD1306.h>
//IR.............................................initialization

// Use pins 2 and 3 to communicate with DFPlayer Mini
static const uint8_t PIN_MP3_TX = 2; // Connects to module's RX
static const uint8_t PIN_MP3_RX = 3; // Connects to module's TX
SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);

const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;

DFRobotDFPlayerMini player;

//Neopixel.............................................initialization
#ifdef AVR
#include <avr/power.h>
#endif
#define PIN 6
#define NUMPIXELS 15
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

//Variables.............................................INICIALIZATION
int Blue_Life = 0;
int Red_Life = 0;

int codeType = -1; // The type of code
unsigned int rawCodes[RAWBUF]; // The durations if raw
int codeLen; // The length of the code
// OLED display TWI address
#define OLED_ADDR 0x3C

const int lcdClockPin = A5;
const int lcdSerialPin = A4;

// reset pin not used on 4-pin OLED module
Adafruit_SSD1306 display(-1); // -1 = no reset pin

// IR codes for Laser X units
unsigned int teamA = {6500, 450, 600, 450, 1660, 450, 600, 450, 1700, 450, 650, 450, 600, 450, 1700, 450, 600};
unsigned int teamB = {6150, 550, 450, 600, 1450, 600, 400, 650, 1450, 550, 450, 600, 450, 550, 450, 600, 1400};
unsigned int renegade = {6100, 600, 450, 550, 1450, 600, 450, 600, 1450, 600, 450, 550, 400, 650, 1450, 600, 1500};

// 33EBDD7B - 871095675 A
// A3F34992 - 2750630290 B
// 33EBDD7A - 871095674 Renegade

void setup() {
display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
display.clearDisplay();
display.display();

display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(1,5);
display.print("Team Blue: " + String(Blue_Life));
display.setCursor(1,20);
display.print("Team Red: " + String(Red_Life));

display.display();

Serial.begin(9600);
softwareSerial.begin(9600);
irrecv.enableIRIn();
Serial.println("Hello! Laser X FLAG!");
pixels.begin();
pixels.clear();
if (player.begin(softwareSerial)) {
Serial.println("OK");

// Set volume to maximum (0 to 30).
player.volume(50);
// Play the first MP3 file on the SD card
player.play(1);

delay(2000);
// Set volume to maximum (0 to 30).
player.volume(50);
// Play the first MP3 file on the SD card
player.play(5);
}
pixels.setPixelColor(0, pixels.Color(0,50, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.setPixelColor(2, pixels.Color(0,0, 0));
pixels.setPixelColor(3, pixels.Color(0, 0, 0));
pixels.setPixelColor(4, pixels.Color(0,0, 0));
pixels.setPixelColor(5, pixels.Color(0, 0, 0));
pixels.setPixelColor(6, pixels.Color(0,0, 0));
pixels.setPixelColor(7, pixels.Color(0, 0, 0));
pixels.setPixelColor(8, pixels.Color(0,0, 0));
pixels.setPixelColor(9, pixels.Color(0, 0, 0));
pixels.setPixelColor(10, pixels.Color(0,0, 0));
pixels.setPixelColor(11, pixels.Color(0, 0, 0));
pixels.setPixelColor(12, pixels.Color(0,0, 0));
pixels.setPixelColor(13, pixels.Color(0, 0, 0));
pixels.setPixelColor(14, pixels.Color(0, 50, 0));
pixels.show();
delay(500);
pixels.setPixelColor(0, pixels.Color(0,0, 0));
pixels.setPixelColor(1, pixels.Color(0,50,0));
pixels.setPixelColor(2, pixels.Color(0,0, 0));
pixels.setPixelColor(3, pixels.Color(0, 0,0));
pixels.setPixelColor(4, pixels.Color(0,0, 0));
pixels.setPixelColor(5, pixels.Color(0, 0, 0));
pixels.setPixelColor(6, pixels.Color(0,0, 0));
pixels.setPixelColor(7, pixels.Color(0, 0, 0));
pixels.setPixelColor(8, pixels.Color(0,0, 0));
pixels.setPixelColor(9, pixels.Color(0, 0, 0));
pixels.setPixelColor(10, pixels.Color(0,0, 0));
pixels.setPixelColor(11, pixels.Color(0, 0, 0));
pixels.setPixelColor(12, pixels.Color(0,0, 0));
pixels.setPixelColor(13, pixels.Color(0, 50, 0));
pixels.setPixelColor(14, pixels.Color(0, 0, 0));
pixels.show();
delay(500);
pixels.setPixelColor(0, pixels.Color(0,0, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.setPixelColor(2, pixels.Color(0,50, 0));
pixels.setPixelColor(3, pixels.Color(0,0, 0));
pixels.setPixelColor(4, pixels.Color(0,0, 0));
pixels.setPixelColor(5, pixels.Color(0, 0, 0));
pixels.setPixelColor(6, pixels.Color(0,0, 0));
pixels.setPixelColor(7, pixels.Color(0, 0, 0));
pixels.setPixelColor(8, pixels.Color(0,0, 0));
pixels.setPixelColor(9, pixels.Color(0, 0, 0));
pixels.setPixelColor(10, pixels.Color(0,0, 0));
pixels.setPixelColor(11, pixels.Color(0, 0, 0));
pixels.setPixelColor(12, pixels.Color(0,50, 0));
pixels.setPixelColor(13, pixels.Color(0, 0, 0));
pixels.setPixelColor(14, pixels.Color(0, 0, 0));
pixels.show();
delay(500);
pixels.setPixelColor(0, pixels.Color(0,0, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.setPixelColor(2, pixels.Color(0,0, 0));
pixels.setPixelColor(3, pixels.Color(0,50, 0));
pixels.setPixelColor(4, pixels.Color(0,0, 0));
pixels.setPixelColor(5, pixels.Color(0,0, 0));
pixels.setPixelColor(6, pixels.Color(0,0, 0));
pixels.setPixelColor(7, pixels.Color(0, 0, 0));
pixels.setPixelColor(8, pixels.Color(0,0, 0));
pixels.setPixelColor(9, pixels.Color(0, 0, 0));
pixels.setPixelColor(10, pixels.Color(0,0, 0));
pixels.setPixelColor(11, pixels.Color(0, 50, 0));
pixels.setPixelColor(12, pixels.Color(0,0, 0));
pixels.setPixelColor(13, pixels.Color(0, 0, 0));
pixels.setPixelColor(14, pixels.Color(0, 0, 0));
pixels.show();
delay(500);
pixels.setPixelColor(0, pixels.Color(0,0, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.setPixelColor(2, pixels.Color(0,0, 0));
pixels.setPixelColor(3, pixels.Color(0, 0, 0));
pixels.setPixelColor(4, pixels.Color(0,50, 0));
pixels.setPixelColor(5, pixels.Color(0, 0, 0));
pixels.setPixelColor(6, pixels.Color(0,0, 0));
pixels.setPixelColor(7, pixels.Color(0, 0, 0));
pixels.setPixelColor(8, pixels.Color(0,0, 0));
pixels.setPixelColor(9, pixels.Color(0, 0, 0));
pixels.setPixelColor(10, pixels.Color(0,50, 0));
pixels.setPixelColor(11, pixels.Color(0, 0, 0));
pixels.setPixelColor(12, pixels.Color(0,0, 0));
pixels.setPixelColor(13, pixels.Color(0, 0, 0));
pixels.setPixelColor(14, pixels.Color(0, 0, 0));
pixels.show();
delay(500);
pixels.setPixelColor(0, pixels.Color(0,0, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.setPixelColor(2, pixels.Color(0,0, 0));
pixels.setPixelColor(3, pixels.Color(0, 0, 0));
pixels.setPixelColor(4, pixels.Color(0,0, 0));
pixels.setPixelColor(5, pixels.Color(0, 50, 0));
pixels.setPixelColor(6, pixels.Color(0,0, 0));
pixels.setPixelColor(7, pixels.Color(0, 0, 0));
pixels.setPixelColor(8, pixels.Color(0,0, 0));
pixels.setPixelColor(9, pixels.Color(0, 50, 0));
pixels.setPixelColor(10, pixels.Color(0,0, 0));
pixels.setPixelColor(11, pixels.Color(0, 0, 0));
pixels.setPixelColor(12, pixels.Color(0,0, 0));
pixels.setPixelColor(13, pixels.Color(0, 0, 0));
pixels.setPixelColor(14, pixels.Color(0, 0, 0));
pixels.show();
delay(500);
pixels.setPixelColor(0, pixels.Color(0,0, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.setPixelColor(2, pixels.Color(0,0, 0));
pixels.setPixelColor(3, pixels.Color(0,0, 0));
pixels.setPixelColor(4, pixels.Color(0,0, 0));
pixels.setPixelColor(5, pixels.Color(0, 0, 0));
pixels.setPixelColor(6, pixels.Color(0,50, 0));
pixels.setPixelColor(7, pixels.Color(0, 0, 0));
pixels.setPixelColor(8, pixels.Color(0,50, 0));
pixels.setPixelColor(9, pixels.Color(0, 0, 0));
pixels.setPixelColor(10, pixels.Color(0,0, 0));
pixels.setPixelColor(11, pixels.Color(0, 0, 0));
pixels.setPixelColor(12, pixels.Color(0,0, 0));
pixels.setPixelColor(13, pixels.Color(0, 0, 0));
pixels.setPixelColor(14, pixels.Color(0, 0, 0));
pixels.show();
delay(500);
pixels.setPixelColor(0, pixels.Color(0,0, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.setPixelColor(2, pixels.Color(0,0, 0));
pixels.setPixelColor(3, pixels.Color(0,0, 0));
pixels.setPixelColor(4, pixels.Color(0,0, 0));
pixels.setPixelColor(5, pixels.Color(0,0, 0));
pixels.setPixelColor(6, pixels.Color(0,0, 0));
pixels.setPixelColor(7, pixels.Color(0,50, 0));
pixels.setPixelColor(8, pixels.Color(0,0, 0));
pixels.setPixelColor(9, pixels.Color(0, 0, 0));
pixels.setPixelColor(10, pixels.Color(0,0, 0));
pixels.setPixelColor(11, pixels.Color(0, 0, 0));
pixels.setPixelColor(12, pixels.Color(0,0, 0));
pixels.setPixelColor(13, pixels.Color(0, 0, 0));
pixels.setPixelColor(14, pixels.Color(0, 0, 0));
pixels.show();
delay(500);
pixels.setPixelColor(0, pixels.Color(0,0, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.setPixelColor(2, pixels.Color(0,0, 0));
pixels.setPixelColor(3, pixels.Color(0,0, 0));
pixels.setPixelColor(4, pixels.Color(0,0, 0));
pixels.setPixelColor(5, pixels.Color(0, 0, 0));
pixels.setPixelColor(6, pixels.Color(0,50, 0));
pixels.setPixelColor(7, pixels.Color(0, 0, 0));
pixels.setPixelColor(8, pixels.Color(0,50, 0));
pixels.setPixelColor(9, pixels.Color(0, 0, 0));
pixels.setPixelColor(10, pixels.Color(0,0, 0));
pixels.setPixelColor(11, pixels.Color(0, 0, 0));
pixels.setPixelColor(12, pixels.Color(0,0, 0));
pixels.setPixelColor(13, pixels.Color(0, 0, 0));
pixels.setPixelColor(14, pixels.Color(0, 0, 0));
pixels.show();
delay(500);
pixels.setPixelColor(0, pixels.Color(0,0, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.setPixelColor(2, pixels.Color(0,0, 0));
pixels.setPixelColor(3, pixels.Color(0,0, 0));
pixels.setPixelColor(4, pixels.Color(0,0, 0));
pixels.setPixelColor(5, pixels.Color(0,50, 0));
pixels.setPixelColor(6, pixels.Color(0,0, 0));
pixels.setPixelColor(7, pixels.Color(0, 0, 0));
pixels.setPixelColor(8, pixels.Color(0,0, 0));
pixels.setPixelColor(9, pixels.Color(0, 50, 0));
pixels.setPixelColor(10, pixels.Color(0,0, 0));
pixels.setPixelColor(11, pixels.Color(0, 0, 0));
pixels.setPixelColor(12, pixels.Color(0,0, 0));
pixels.setPixelColor(13, pixels.Color(0, 0, 0));
pixels.setPixelColor(14, pixels.Color(0, 0, 0));
pixels.show();
delay(500);
pixels.setPixelColor(0, pixels.Color(0,0, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.setPixelColor(2, pixels.Color(0,0, 0));
pixels.setPixelColor(3, pixels.Color(0, 0, 0));
pixels.setPixelColor(4, pixels.Color(0,50, 0));
pixels.setPixelColor(5, pixels.Color(0, 0, 0));
pixels.setPixelColor(6, pixels.Color(0,0, 0));
pixels.setPixelColor(7, pixels.Color(0, 0, 0));
pixels.setPixelColor(8, pixels.Color(0,0, 0));
pixels.setPixelColor(9, pixels.Color(0, 0, 0));
pixels.setPixelColor(10, pixels.Color(0,50, 0));
pixels.setPixelColor(11, pixels.Color(0,0, 0));
pixels.setPixelColor(12, pixels.Color(0,0, 0));
pixels.setPixelColor(13, pixels.Color(0, 0, 0));
pixels.setPixelColor(14, pixels.Color(0, 0, 0));
pixels.show();
delay(500);
pixels.setPixelColor(0, pixels.Color(0,0, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.setPixelColor(2, pixels.Color(0,0, 0));
pixels.setPixelColor(3, pixels.Color(0, 50, 0));
pixels.setPixelColor(4, pixels.Color(0,0, 0));
pixels.setPixelColor(5, pixels.Color(0, 0, 0));
pixels.setPixelColor(6, pixels.Color(0,0, 0));
pixels.setPixelColor(7, pixels.Color(0, 0, 0));
pixels.setPixelColor(8, pixels.Color(0,0, 0));
pixels.setPixelColor(9, pixels.Color(0, 0, 0));
pixels.setPixelColor(10, pixels.Color(0,0, 0));
pixels.setPixelColor(11, pixels.Color(0, 50, 0));
pixels.setPixelColor(12, pixels.Color(0,0, 0));
pixels.setPixelColor(13, pixels.Color(0, 0, 0));
pixels.setPixelColor(14, pixels.Color(0, 0, 0));
pixels.show();
delay(500);
pixels.setPixelColor(0, pixels.Color(0,0, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.setPixelColor(2, pixels.Color(0,50, 0));
pixels.setPixelColor(3, pixels.Color(0,0, 0));
pixels.setPixelColor(4, pixels.Color(0,0, 0));
pixels.setPixelColor(5, pixels.Color(0, 0, 0));
pixels.setPixelColor(6, pixels.Color(0,0, 0));
pixels.setPixelColor(7, pixels.Color(0, 0, 0));
pixels.setPixelColor(8, pixels.Color(0,0, 0));
pixels.setPixelColor(9, pixels.Color(0, 0, 0));
pixels.setPixelColor(10, pixels.Color(0,0, 0));
pixels.setPixelColor(11, pixels.Color(0, 0, 0));
pixels.setPixelColor(12, pixels.Color(0,50, 0));
pixels.setPixelColor(13, pixels.Color(0, 0, 0));
pixels.setPixelColor(14, pixels.Color(0, 0, 0));
pixels.show();
delay(500);
pixels.setPixelColor(0, pixels.Color(0,0, 0));
pixels.setPixelColor(1, pixels.Color(0, 50, 0));
pixels.setPixelColor(2, pixels.Color(0,0, 0));
pixels.setPixelColor(3, pixels.Color(0, 0, 0));
pixels.setPixelColor(4, pixels.Color(0,0, 0));
pixels.setPixelColor(5, pixels.Color(0, 0, 0));
pixels.setPixelColor(6, pixels.Color(0,0, 0));
pixels.setPixelColor(7, pixels.Color(0, 0, 0));
pixels.setPixelColor(8, pixels.Color(0,0, 0));
pixels.setPixelColor(9, pixels.Color(0, 0, 0));
pixels.setPixelColor(10, pixels.Color(0,0, 0));
pixels.setPixelColor(11, pixels.Color(0, 0, 0));
pixels.setPixelColor(12, pixels.Color(0,0, 0));
pixels.setPixelColor(13, pixels.Color(0, 50, 0));
pixels.setPixelColor(14, pixels.Color(0, 0, 0));
pixels.show();
delay(500);
pixels.setPixelColor(0, pixels.Color(0,50, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.setPixelColor(2, pixels.Color(0,0, 0));
pixels.setPixelColor(3, pixels.Color(0,0, 0));
pixels.setPixelColor(4, pixels.Color(0,0, 0));
pixels.setPixelColor(5, pixels.Color(0, 0, 0));
pixels.setPixelColor(6, pixels.Color(0,0, 0));
pixels.setPixelColor(7, pixels.Color(0, 0, 0));
pixels.setPixelColor(8, pixels.Color(0,0, 0));
pixels.setPixelColor(9, pixels.Color(0, 0, 0));
pixels.setPixelColor(10, pixels.Color(0,0, 0));
pixels.setPixelColor(11, pixels.Color(0, 0, 0));
pixels.setPixelColor(12, pixels.Color(0,0, 0));
pixels.setPixelColor(13, pixels.Color(0, 0, 0));
pixels.setPixelColor(14, pixels.Color(0, 50, 0));
pixels.show();
delay(1000);
player.volume(50);
// Play the first MP3 file on the SD card
player.play(2);
}

void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, DEC);
irrecv.resume();
}
//Inputs................................................OPERATING
if (results.value == 2750630290) {
Blue_Life = Blue_Life <1;
(Blue_Life++;
delay(1000);
}
if (results.value == 871095675) {
Red_Life = Red_Life +1;
delay(1000);
}

//NeoPixel................................................OPERATION

if (Blue_Life == 8) {
pixels.setPixelColor(0, pixels.Color(0, 50, 0));
pixels.setPixelColor(1, pixels.Color(0, 50, 0));
pixels.setPixelColor(2, pixels.Color(0, 0, 0));
pixels.show();
}
if (Red_Life == 8){
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.setPixelColor(2, pixels.Color(50, 0, 0));
pixels.show();
}
}

Harsh.

But true and fair.

What causes results.value from keeping its value from loop to loop?

Please remember to use code tags when posting code

Oh You mean you want to do this:

If ( PicturesOfCodeSuck.value = 203975203957u203954720357)
{
Blue_Life ++;
PicturesOfCodeSuck.value = 0;
}

...

1 Like

Hi @Firefly723
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

This will help with advice on how to present your code and problems.

Thanks .. Tom... :smiley: :+1: :coffee: :australia:

The next thing you should do is learn about for loops:

    for (int aPixel = 0; aPixel < 15; aPixel++)
        pixels.setPixelColor(aPixel, pixels.Color(0,0, 0));

Edit: I failed to see, so just add two lines after the for loop…

  pixels.setPixelColor(1, pixels.Color(0, 50, 0));
  pixels.setPixelColor(13, pixels.Color(0, 50, 0));

If every block ends up just setting two pixels to not black, then the next next thing to learn about is functions, so you could write a general thing that turns off all pixels and sets two that you pass as parameters, even to a color or two that you also pass.

HTH

a7

1 Like

Post#4 is the solution.