Ammo Counter

Hi guys I have tried to compile the code below but keep getting the error any help?

I am getting this error:

Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "Pro Trinket 5V/16MHz (USB)"

nerf-ammo-counter:37:64: error: no matching function for call to 'Button::Button(int, bool, bool, int)'

Button triggerBtn (TRIGGER_BTN_PIN, PULLUP, INVERT, DEBOUNCE_MS); //trigger button

^

C:\Users\Nick\Downloads\nerf-ammo-counter-master\nerf-ammo-counter-master\nerf-ammo-counter\nerf-ammo-counter.ino:37:64: note: candidates are:

In file included from C:\Users\Nick\Downloads\nerf-ammo-counter-master\nerf-ammo-counter-master\nerf-ammo-counter\nerf-ammo-counter.ino:15:0:

C:\Users\Nick\Documents\Arduino\libraries\Button-1.0.0/Button.h:14:3: note: Button::Button(uint8_t)

Button(uint8_t pin);

^

C:\Users\Nick\Documents\Arduino\libraries\Button-1.0.0/Button.h:14:3: note: candidate expects 1 argument, 4 provided

C:\Users\Nick\Documents\Arduino\libraries\Button-1.0.0/Button.h:11:7: note: constexpr Button::Button(const Button&)

class Button

^

C:\Users\Nick\Documents\Arduino\libraries\Button-1.0.0/Button.h:11:7: note: candidate expects 1 argument, 4 provided

C:\Users\Nick\Documents\Arduino\libraries\Button-1.0.0/Button.h:11:7: note: constexpr Button::Button(Button&&)

C:\Users\Nick\Documents\Arduino\libraries\Button-1.0.0/Button.h:11:7: note: candidate expects 1 argument, 4 provided

nerf-ammo-counter:38:62: error: no matching function for call to 'Button::Button(int, bool, bool, int)'

Button reloadBtn (RELOAD_BTN_PIN, PULLUP, INVERT, DEBOUNCE_MS); //reloading button

^

C:\Users\Nick\Downloads\nerf-ammo-counter-master\nerf-ammo-counter-master\nerf-ammo-counter\nerf-ammo-counter.ino:38:62: note: candidates are:

In file included from C:\Users\Nick\Downloads\nerf-ammo-counter-master\nerf-ammo-counter-master\nerf-ammo-counter\nerf-ammo-counter.ino:15:0:

C:\Users\Nick\Documents\Arduino\libraries\Button-1.0.0/Button.h:14:3: note: Button::Button(uint8_t)

Button(uint8_t pin);

^

C:\Users\Nick\Documents\Arduino\libraries\Button-1.0.0/Button.h:14:3: note: candidate expects 1 argument, 4 provided

C:\Users\Nick\Documents\Arduino\libraries\Button-1.0.0/Button.h:11:7: note: constexpr Button::Button(const Button&)

class Button

^

C:\Users\Nick\Documents\Arduino\libraries\Button-1.0.0/Button.h:11:7: note: candidate expects 1 argument, 4 provided

C:\Users\Nick\Documents\Arduino\libraries\Button-1.0.0/Button.h:11:7: note: constexpr Button::Button(Button&&)

C:\Users\Nick\Documents\Arduino\libraries\Button-1.0.0/Button.h:11:7: note: candidate expects 1 argument, 4 provided

nerf-ammo-counter:39:68: error: no matching function for call to 'Button::Button(int, bool, bool, int)'

Button magSzTogBtn (MAG_SZ_TOG_BTN_PIN, PULLUP, INVERT, DEBOUNCE_MS); //magazine size toggle button

^

C:\Users\Nick\Downloads\nerf-ammo-counter-master\nerf-ammo-counter-master\nerf-ammo-counter\nerf-ammo-counter.ino:39:68: note: candidates are:

In file included from C:\Users\Nick\Downloads\nerf-ammo-counter-master\nerf-ammo-counter-master\nerf-ammo-counter\nerf-ammo-counter.ino:15:0:

C:\Users\Nick\Documents\Arduino\libraries\Button-1.0.0/Button.h:14:3: note: Button::Button(uint8_t)

Button(uint8_t pin);

^

C:\Users\Nick\Documents\Arduino\libraries\Button-1.0.0/Button.h:14:3: note: candidate expects 1 argument, 4 provided

C:\Users\Nick\Documents\Arduino\libraries\Button-1.0.0/Button.h:11:7: note: constexpr Button::Button(const Button&)

class Button

^

C:\Users\Nick\Documents\Arduino\libraries\Button-1.0.0/Button.h:11:7: note: candidate expects 1 argument, 4 provided

C:\Users\Nick\Documents\Arduino\libraries\Button-1.0.0/Button.h:11:7: note: constexpr Button::Button(Button&&)

C:\Users\Nick\Documents\Arduino\libraries\Button-1.0.0/Button.h:11:7: note: candidate expects 1 argument, 4 provided

C:\Users\Nick\Downloads\nerf-ammo-counter-master\nerf-ammo-counter-master\nerf-ammo-counter\nerf-ammo-counter.ino: In function 'void countAmmo()':

nerf-ammo-counter:89:18: error: 'class Button' has no member named 'wasPressed'

if (triggerBtn.wasPressed()) { //trigger button pressed

^

C:\Users\Nick\Downloads\nerf-ammo-counter-master\nerf-ammo-counter-master\nerf-ammo-counter\nerf-ammo-counter.ino: In function 'void reload()':

nerf-ammo-counter:101:17: error: 'class Button' has no member named 'wasPressed'

if (reloadBtn.wasPressed()) { //reload button pressed

^

C:\Users\Nick\Downloads\nerf-ammo-counter-master\nerf-ammo-counter-master\nerf-ammo-counter\nerf-ammo-counter.ino: In function 'void toggleMags()':

nerf-ammo-counter:109:19: error: 'class Button' has no member named 'wasPressed'

if (magSzTogBtn.wasPressed()) { //magazine size toggle button pressed

^

Multiple libraries were found for "Adafruit_GFX.h"
Used: C:\Users\Nick\Documents\Arduino\libraries\Adafruit_GFX_Library
Not used: C:\Users\Nick\Documents\Arduino\libraries\Adafruit-GFX-Library-master
Multiple libraries were found for "Wire.h"
Used: C:\Users\Nick\Documents\ArduinoData\packages\adafruit\hardware\avr\1.4.13\libraries\Wire
Not used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\Wire
exit status 1
no matching function for call to 'Button::Button(int, bool, bool, int)'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I think there are some errors in the code you didn't post.

Okay your right I forgot to include the code but here it is:

//libraries, so the display can work
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Button.h>

//set the height and width of the screen
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

//initialize stuff for display
#define OLED_RESET 4
#define TEXT_SIZE 8

//pins for button
#define TRIGGER_BTN_PIN 1
#define RELOAD_BTN_PIN 4
#define MAG_SZ_TOG_BTN_PIN 5

//parameters for buttons
#define INVERT true
#define PULLUP true
#define DEBOUNCE_MS

Adafruit_SSD1306 display(OLED_RESET); //display

Button triggerBtn (TRIGGER_BTN_PIN, PULLUP, INVERT, DEBOUNCE_MS); //trigger button
Button reloadBtn (RELOAD_BTN_PIN, PULLUP, INVERT, DEBOUNCE_MS); //reloading button
Button magSzTogBtn (MAG_SZ_TOG_BTN_PIN, PULLUP, INVERT, DEBOUNCE_MS); //magazine size toggle button

//stuff to help keep track of magazine stuff
//if you want to add/remove magazine sizes, do that here. Remember, they go in order when you toggle between them, from left to right in this.
//
//when you change the value, the "currentMagSize"(several lines below) has to be less than the number of different magazines sizes,
//the number of different magazine size values in the "magSizeArr" you can change "currentMagSize" to whatever you want.
//When it program first starts, when the microcontroller turns on, the 5th element of "magSizeArr" is the current magazine size,
//starting from 0. 0 is used for count-up mode.
//Ex: byte array = {1(0), 2(1), 3(2), 4(3)} - the numbers without parenthesis are the values this array/list
//stores, and the number between the parenthesis indicates which place they are, their "index", where they are in the list/array.
//If I want to access the value 1, which is the first value of the array/list, which the computer sees as the
//"zeroith" value, I would do array[0]. If I want to access the value 3, the third value of the array, I would do array[2]
byte magSizeArr[] = {5, 6, 10, 12, 15, 18, 20, 22, 25, 36, 0}; //keep track of the magazine sizes
byte currentMagSize = 0; //keep track of the current magazine size
byte currentAmmo = magSizeArr[currentMagSize]; //keep track of how much ammo there currently is
byte maxAmmo = magSizeArr[currentMagSize]; //keep track of what the max ammo is, for use when reloading

//this code will run when the Arduino turns on
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //begin stuff for the display
initDisplayAmmo(); //show the ammo
}

//this code loops many times a second
void loop() {
countAmmo(); //count ammo, constantly check for the trigger switch to be pressed to count
reload(); //reload, constantly check for the magazine switch to be pressed/not pressed
toggleMags(); //toggle between magazine sizes, constanly check for the magazine toggle switch to be pressed
}

//actually dispaly ammo onto screen
void displayAmmo (String ammoToDisplay) {
display.clearDisplay(); //clear the display, so the stuff that was here before is no longer here
display.setTextSize(TEXT_SIZE); //set the size of the text
display.setTextColor(WHITE); //set the color of text text
display.setCursor( (SCREEN_WIDTH/2) - ((ammoToDisplay.length()*2) * (TEXT_SIZE * 1.5)), (SCREEN_HEIGHT/2) - (TEXT_SIZE * 3) ); //center text
display.print(ammoToDisplay); //print the text
display.display(); //display the text
}

//set up ammo to be displayed
void initDisplayAmmo () {
//if the ammo to print, current ammo, is less that 10, make it like '01' or '04'
String ammoToDisplay = currentAmmo < 10 ? ("0" + (String)currentAmmo) : (String)currentAmmo;
displayAmmo(ammoToDisplay); //display the text, the ammo
}

void countAmmo () {
triggerBtn.read(); //read trigger button
if (triggerBtn.wasPressed()) { //trigger button pressed
if (maxAmmo != 0 && currentAmmo < 99 && currentAmmo > 0) { //make sure that the ammo is less than 99 so it doesnt overflow the display and not in count-up mode
currentAmmo--; //increment ammo
} else if (maxAmmo == 0 && currentAmmo < 99) { //make sure that the ammo is more than 0 so no negative numbers are displayed and in count-up mode
currentAmmo++; //decrement ammo
}
initDisplayAmmo(); //display ammo
}
}

void reload () {
reloadBtn.read(); //read reload button
if (reloadBtn.wasPressed()) { //reload button pressed
currentAmmo = maxAmmo; //reset ammo
initDisplayAmmo(); //display ammo
}
}

void toggleMags () {
magSzTogBtn.read(); //read magazine size toggle button
if (magSzTogBtn.wasPressed()) { //magazine size toggle button pressed
//cycle through mag sizes based on array, and make sure array doens't overflow
currentMagSize = (currentMagSize < (sizeof(magSizeArr)/sizeof(magSizeArr[0]) - 1)) ? currentMagSize + 1 : 0;

//there's a new max ammo, because there's a new magazine size
maxAmmo = magSizeArr[currentMagSize];
currentAmmo = maxAmmo;

initDisplayAmmo(); //display ammo
}
}

How did you get to such a large code and only now discover that it doesn't compile? Didn't you develop it in small pieces and test as you went? If you had, the problem would have been the last thing you added.

Dude:

Read "How To Use This Forum"

This is what happens when you do not

Please provide the place where you found the Button library, as there are several with the same name. It seems the parameters for the declaration of your buttons are incorrect

Okay so I got the code from another user (Monty Choy) who was working on the project that is similar to my project and I tried to compile the code and got the error. I tried to google the error and tried to figure out why the error is coming up I just don't understand what to change or fix code wise.

I got the button.h library from the original post on get hub.

is there any way that I can make this work or should I consider scraping it and starting all over? I am not a programmer so I would have to try and learn how everything works which I honestly don't know where to begin

nanoshot:
I got the button.h library from the original post on get hub.

GitHub - mochoy/smart-blaster: Arduino library for ammo counters and more in modified NERF blasters.

Are you sure you got it there, and not from:

The reason I ask is because your error message shows you're using a project named nerf-ammo-counter, not a project named smart blaster:
C:\Users\Nick\Downloads\nerf-ammo-counter-master\nerf-ammo-counter-master\nerf-ammo-counter\nerf-ammo-counter.ino

What we find is that neither of those projects currently contain a file named Button.h. They did contain that file a couple of years ago, but they don't any more. I find it somewhat hard to believe that you downloaded the project years ago and are only now getting around to compiling it. The Button library included with the mochoy projects does indeed contain the expected constructor signature, while yours doesn't. Another discrepancy is that the Button library included with those projects is in a folder named Button, yet your Button library is in a folder named Button-1.0.0:
C:\Users\Nick\Documents\Arduino\libraries\Button-1.0.0/Button.h
So it seems clear that for some reason you're not telling us the truth about where you got this Button library.

So here I am reading through some readme, hunting the history of multiple repositories, just to try to sleuth out information that you know already but didn't feel like sharing. That wastes my time and makes it take longer for you to get a solution so everyone loses.

So I'll help you, but give you a taste of your own medicine. Somewhere in the history of those repositories is the Button library you need. I know where it's at, but for some reason I don't feel like sharing that information, so you get to go through the same scavenger hunt I just did. Have fun!

pert:
So I'll help you, but give you a taste of your own medicine.

:smiling_imp:

The original author of this thing has several websites, with different activity volumes: This first one explains how to build the ammo counter but the last comment was more than one year ago. However, that one has more recent activity. You should ask him where exactly he found the button library, because I couldn't find any such information in his websites. And that's the clue of your problems.

When you have installed the proper library (and removed the one you're currently using), everything should be correct... hopefully