Error to many arguments in function

Im new to making code and i keep getting this error message and I don't know how to fix it can someone help?
The code is programmable alarm by using an LCD and a piezo to represent the sound and i want to add a button that spots the piezo going off after it reaches the alarm time.

#include <LiquidCrystal.h>
#define AlarmSND 6
LiquidCrystal lcd (12, 11, 5, 4, 3, 2);
int Hours  = 9; //Set this Value to Set the Hours
int Minutes = 29; //Set this Value to Set the Minutes
int Seconds = 55; //Set this Value to Set the Seconds
int red = 8;
int button = 7;

void setup() {
  // put your setup code here, to run once:
  lcd.begin(16,2);
  pinMode (AlarmSND, OUTPUT);
  pinMode(button, INPUT);
  pinMode(red, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(1000);
  lcd.setCursor(0, 1);
  Seconds++;
  
  //Set the Below Values to Set the Alarm 
  if ( Hours  == 9)
  {
    if (Minutes >=30 && Minutes <= 45)
    {
      tone (AlarmSND, 600, 300);
       digitalWrite(red, HIGH);
       delay(100);
       digitalWrite(red, LOW);
      while (digitalRead(button, HIGH)){
        (digitalWrite(AlarmSND, LOW));
         }
    }
  }
 if ( Seconds == 60)
  {
    Minutes++;
    Seconds = 0;
  }
  
  if ( Minutes == 60)
  {
    Minutes = 0;
    Hours++;
  }

  if ( Hours == 24)
  {
    Hours = 0;
  }
   

 if (Hours >=0 && Hours <=9)
 {
   lcd.setCursor(2,1);
   lcd.print("0");
   lcd.setCursor(3,1);
   lcd.print(Hours);
 }
 else
 {
   lcd.setCursor(2,1);
   lcd.print(Hours);
 }

 lcd.setCursor(5,1);
 lcd.print(":");
    
 if (Minutes >=0 && Minutes <=9)
 {
   lcd.setCursor(7,1);
   lcd.print("0");
   lcd.print(Minutes);
 }
 else
 {
   lcd.setCursor(8,1);
   lcd.print(" ");
   lcd.setCursor(7,1);
   lcd.print(Minutes);
 }
 
 lcd.setCursor(10,1);
  lcd.print(":");
  
  if (Seconds >=0 && Seconds <=9)
 {
   lcd.setCursor(12,1);
   lcd.print("0");
   lcd.print(Seconds);
 }
 else
 {
   lcd.setCursor(13,1);
   lcd.print(" ");
   lcd.setCursor(12,1);
   lcd.print(Seconds);
 }
}

Here is the errors im getting:
In function 'void loop()':
33.38: error: too many arguments in function 'int digitalRead(uint8_t)'
1:0:
136.5: note: declared here

the digitalRead() function only takes one argument the pin to be read
e.g. did you intend to test for button being HIGH

while (digitalRead(button) == HIGH){
1 Like

This did solve my errors in the code but now im running into a different problem. I intended for the piezo to keep making noise until a press of the button but now it instantly turns off without me making anything, i tried changing the while value to a if but it did not work, do you have any tips for that? If not thanks for the initial help.

In the code, after the button is recognized as being pressed, "set a flag" that says "the button was pressed" and only clear that "button was pressed" flag when you want the sound to stop.

while (digitalRead(button) == HIGH) { // the button IS pressed
  buttonFlag = 1; // the button WAS pressed
.
.
if (buttonFlag == 1)
  // make sound

buttons are typically connected between the pin and ground, the pin configured as INPUT_PULLUP to use the internal pullup resistor which pulls the pin HIGH and when pressed, the button pulls the pin LOW.

if i make the flag = 0 does it mean that it will happend when I don't press the button?
[edit] Now when i put the flag it tells me it was not specified in the scope and gives me errors how do i specify it.

      while (digitalRead(button)== HIGH){
        buttonFlag = 1;
      }
      if (buttonFlag == 1){
        digitalWrite(AlarmSND, LOW);
         }
    }
  }

In function 'void loop()':
34:9: error: 'buttonFlag' was not declared in this scope
34:9: note: suggested alternative: 'button'
36:11: error: 'buttonFlag' was not declared in this scope
36:11: note: suggested alternative: 'button'

Well even after adding the Flag for the button it still just makes the piezo stop working, i wanted the button to, when pressed to disable it which was what the flag was for but even before adding the flag this already happened so the flag did not do anything

if the button is connected to Vcc (i don't see where you say how it's connected) then of course the condition is true the alarm turned off

Im trying to make an alarm design using some buttons and a lcd and im having trouble making it work.
To elaborate on my issue im trying to program the button, to when pressed to disable the piezo once it started making noise, if the button is not pressed the piezo will keep going until the button is pressed. The piezo does make noise and the lcd displaying the time does function as wanted is just the button that either breaks the piezo and instantly disables it without any input or it does not do anything, i tried adding a flag and if conditions but i think im doing something wrong, how can i make this work?

#include <LiquidCrystal.h>
#define AlarmSND 6
// piezo aka AlarmSND is connected to pin 6 and GND
LiquidCrystal lcd (12, 11, 5, 4, 3, 2);
int Hours  = 9; //Set this Value to Set the Hours
int Minutes = 29; //Set this Value to Set the Minutes
int Seconds = 55; //Set this Value to Set the Seconds
int red = 8; // connected into pin 7 and GND
int button = 7; // Button is connected to pin 7 only and GND
bool buttonFlag;

void setup() {
  // put your setup code here, to run once:
  lcd.begin(16,2);
  pinMode (AlarmSND, OUTPUT);
  pinMode(button, INPUT);
  pinMode(red, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(1000);
  lcd.setCursor(0, 1);
  Seconds++;
  
  //Set the Below Values to Set the Alarm 
  if ( Hours  == 9)
  {
    if (Minutes >=30 && Minutes <= 45)
    {
       tone(AlarmSND, 600, 300);
      if (digitalRead(AlarmSND)== LOW) {
       digitalWrite(red, HIGH);
       delay(100);
       digitalWrite(red, LOW);
      }
      while (digitalRead(button)== HIGH){
        buttonFlag = 1;
      }
      if (buttonFlag == 1){
        digitalWrite(AlarmSND, LOW); 
      }
        else digitalWrite(AlarmSND, HIGH);
         
      }
  }
 if ( Seconds == 60)
  {
    Minutes++;
    Seconds = 0;
  }
  
  if ( Minutes == 60)
  {
    Minutes = 0;
    Hours++;
  }

  if ( Hours == 24)
  {
    Hours = 0;
  }
   

 if (Hours >=0 && Hours <=9)
 {
   lcd.setCursor(2,1);
   lcd.print("0");
   lcd.setCursor(3,1);
   lcd.print(Hours);
 }
 else
 {
   lcd.setCursor(2,1);
   lcd.print(Hours);
 }

 lcd.setCursor(5,1);
 lcd.print(":");
    
 if (Minutes >=0 && Minutes <=9)
 {
   lcd.setCursor(7,1);
   lcd.print("0");
   lcd.print(Minutes);
 }
 else
 {
   lcd.setCursor(8,1);
   lcd.print(" ");
   lcd.setCursor(7,1);
   lcd.print(Minutes);
 }
 
 lcd.setCursor(10,1);
  lcd.print(":");
  
  if (Seconds >=0 && Seconds <=9)
 {
   lcd.setCursor(12,1);
   lcd.print("0");
   lcd.print(Seconds);
 }
 else
 {
   lcd.setCursor(13,1);
   lcd.print(" ");
   lcd.setCursor(12,1);
   lcd.print(Seconds);
 }
}

I corrected some lines in your code.
See if it now works as you want.
It is important to remember that as there is a delay of 1000 msec in your code, you have to keep the button pressed for at least 1 second to make sure it has been read.
This line uses the Arduino's internal PULL_UP, and the button needs to be connected between the pin and GND.
The button is LOW when pressed and HIGH when released.

#include <LiquidCrystal.h>
#define AlarmSND 6
// piezo aka AlarmSND is connected to pin 6 and GND
LiquidCrystal lcd (12, 11, 5, 4, 3, 2);
int Hours  = 9; //Set this Value to Set the Hours
int Minutes = 29; //Set this Value to Set the Minutes
int Seconds = 55; //Set this Value to Set the Seconds
int red = 8; // connected into pin 7 and GND
int button = 7; // Button is connected to pin 7 only and GND
bool buttonFlag;

void setup() {
  // put your setup code here, to run once:
  lcd.begin(16, 2);
  pinMode (AlarmSND, OUTPUT);
  pinMode(button, INPUT_PULLUP);
  pinMode(red, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(1000);
  lcd.setCursor(0, 1);
  Seconds++;

  //Set the Below Values to Set the Alarm

  if ( Hours  == 9)
  {
    if (Minutes >= 30 && Minutes <= 45)
    {
      if (buttonFlag == 0) {
        tone(AlarmSND, 600, 300);
        if (digitalRead(button) == HIGH) {
          digitalWrite(red, HIGH);
          delay(100);
          digitalWrite(red, LOW);
        }
      }
      while (digitalRead(button) == LOW) {
        buttonFlag = 1;
      }
      if (buttonFlag == 1) {
        noTone(AlarmSND);

      }
    }
  }
  if ( Seconds == 60)
  {
    Minutes++;
    Seconds = 0;
  }

  if ( Minutes == 60)
  {
    Minutes = 0;
    Hours++;
  }

  if ( Hours == 24)
  {
    Hours = 0;
  }


  if (Hours >= 0 && Hours <= 9)
  {
    lcd.setCursor(2, 1);
    lcd.print("0");
    lcd.setCursor(3, 1);
    lcd.print(Hours);
  }
  else
  {
    lcd.setCursor(2, 1);
    lcd.print(Hours);
  }

  lcd.setCursor(5, 1);
  lcd.print(":");

  if (Minutes >= 0 && Minutes <= 9)
  {
    lcd.setCursor(7, 1);
    lcd.print("0");
    lcd.print(Minutes);
  }
  else
  {
    lcd.setCursor(8, 1);
    lcd.print(" ");
    lcd.setCursor(7, 1);
    lcd.print(Minutes);
  }

  lcd.setCursor(10, 1);
  lcd.print(":");

  if (Seconds >= 0 && Seconds <= 9)
  {
    lcd.setCursor(12, 1);
    lcd.print("0");
    lcd.print(Seconds);
  }
  else
  {
    lcd.setCursor(13, 1);
    lcd.print(" ");
    lcd.setCursor(12, 1);
    lcd.print(Seconds);
  }
}

Your two or more topics on the same or similar subject have been merged.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.