problem with coding [solved in an unspecified way]

haii… can anynone help me…im trying to build up a vending machine with just a basic function. so far i get the part for coin accceptor and lcd display… but i have a problem regarding push button, i try to put it in the skecth where i think it should be… but nothings work… tq in advance… here my sketch

// include the library code:
#include <LiquidCrystal.h>
#include <Wire.h>
#include <Servo.h> 
 
// include the library code:
 
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7,8,9,10,11,12);
 
volatile byte CoinPulseCount = 0;
byte NewCoinInserted;
byte Command = 0;
int OpticalCountPin = 3;
volatile unsigned long PulseTime;
float CurrentCredit;
float NewCurrentCredit;
const int buttonPin = 13;//set pin for the button
int buttonState = 0;// the initial stateof the button

int k =0;

Servo myservoa;// create servo object to control a servo
// twelve servo objects can be created on most boards
Servo myservob; 

String OnePulse = "50 Sen";
String TwoPulses = "20 Sen";
String ThreePulses = "10 Sen";


 
void showCredit(){


  NewCurrentCredit = (CurrentCredit/100) + NewCurrentCredit;
  Serial.print("Total Credit: RM ");
  Serial.println(NewCurrentCredit);
  //lcd.begin(16,2);
  lcd.clear();
if(NewCurrentCredit >= 2.00)
{
  
  lcd.setCursor(0,0);
  lcd.print("Total Credit: RM");
  lcd.setCursor(0,1);
  lcd.print(NewCurrentCredit);
  delay(3000);
  lcd.clear();
  
  lcd.setCursor(0,0);
  lcd.print(" PLEASE SELECT ");
  lcd.setCursor(0,1);
  lcd.print(" ITEM ");
  button(); <<<<===== yg ni tekan ade input, tp servo x jln
  delay(3000);
  lcd.clear();
NewCurrentCredit=0;
 setup();
  
}else
{
 lcd.setCursor(0,0);
  lcd.print("Total Credit: RM");
  lcd.setCursor(0,1);
  lcd.print(NewCurrentCredit);
 
}
}
 
void setup(){
  Serial.begin(9600);
  lcd.begin(16,2);
  Serial.println("WELCOME");
  Serial.println();
        lcd.setCursor(0,0);
  lcd.print("    WELCOME!!   ");
  delay(3000);
  
  pinMode(OpticalCountPin, INPUT);
  attachInterrupt(1, CoinPulse, RISING);
  Serial.begin(9600);
 myservoa.attach(5);
 myservob.attach(6);
  pinMode(buttonPin, INPUT_PULLUP);
}
 
void loop(){
    myservob.write(0);
 lcd.setCursor(0, 1); 
 if(CoinPulseCount > 0 && millis() - PulseTime > 200){
    NewCoinInserted = CoinPulseCount;
    CoinPulseCount = 0;
  }
        switch(NewCoinInserted){
          case 1:
            Serial.println(OnePulse + " inserted");
            CurrentCredit = 50;
            showCredit();
            NewCoinInserted = 0;
            break;
          case 2:
            Serial.println(TwoPulses + " inserted");
            CurrentCredit = 20;
            showCredit();
            NewCoinInserted = 0;
            break;
          case 3:
            Serial.println(ThreePulses + " inserted");
            CurrentCredit = 10;
            showCredit();
            NewCoinInserted = 0;
            break;
         
        
        }

        
}
 
void CoinPulse(){
  CoinPulseCount ++;
  PulseTime = millis();
}

void button(){ 
buttonState = digitalRead(buttonPin);

  //myservoa.write(90);
  myservob.write(0);

  if (buttonState == HIGH)//read when button is push
  {

    Serial.print("Buttonstte =   ");
    Serial.println(buttonState);

     

        myservoa.write(180);
        delay(1000);
        myservoa.write(90);
        delay(1000);
      myservob.write(90);
      delay(1000);
       k =0;

        
      }
      

    
  }
  else
  {
    Serial.print("Buttonstte =   ");
    Serial.println(buttonState);
  }

}

What should happen when the button is pressed ?

 if (buttonState == HIGH)//read when button is push

As you have the pinMode() of buttonPin set to INPUT_PULLUP it will be HIGH when it is NOT pressed if you have it wired normally.

How exactly is the button wired ?

What does it mean “nothing works”? Next time please explain and if it does not compile, post the error messages in the ‘result’ window of the IDE

After commenting out <<<<===== yg ni tekan ade input, tp servo x jln, your code does not compile because the ‘else’ is outside the button() function (should have a matching if). You also have one curly brace too many. I suggest that you use T in the IDE (that is, press the control key and the T at the same time) to get correct indentations; you could notice the additional curly immediately at the end of the code.

If you remove the ‘{’ before the offending else, you code compiles.

yes sir,my code is compile nicely, i also did what have u been told, for the the sub code when i test it , all are okay, but when i try to compile it together i didnt get the result i want, only the coin acceptor and LCD part is working.. sorry for the part that have different languages, i forgot to edit it before send the sketch here..

can anynone help me..im trying to build up a vending machine

You might use the forum search box in the upper right of this page to search for your project key words to see what others have done.

thank you for those who reply to my problem, i have solve the problem.

M_shahir:
thank you for those who reply to my problem, i have solve the problem.

It's always nice to share with others what was wrong and how you solved it.