I need help for code of vending machine

Hello friends. I do a vending machine with: coin acceptor, keypad 3x4, 7 servo motors, lcd i2c. I dont no how to do the code. can anyone help me?
i do that. is that right? @k1zzi

#include<Servo.h>
#include <Keypad.h>

const int coinInt = 1;
int money = 0;
int cents = 0;

int posi = 0;
int pos = 0;
int door = 0;

byte idx; // use as index into
int array[ 10 ]; // by default, all are 0 at start
Servo myservo[ 6 ]; // servos now in an array
int Value[ 6 ]; // by default all are = 0
int motor[ 6 ];
byte motorsRunning;

int total = 0;

boolean entered = false;

const byte ROWS = 3;
const byte COLS = 3;

char keys [ROWS] [COLS] = {
  {'1', '2', '3',},
  {'4', '5', '6',},
  {'*', '0', '#',}
};

byte rowPins[] = { 13, 12, 11 };
byte colPins[] = { 10, 9, 8 };

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  Serial.begin(9600);  // why is this less than 115200?

  attachInterrupt(coinInt, coinInserted, RISING);

  myservo[ 0 ].attach(4);
  myservo[ 1 ].attach(5);
  myservo[ 0 ].write(pos);
  myservo[ 1 ].write(pos);
}

void coinInserted()
{
  money = money + 10;
  showMeTheMoney( money );
}

void showMeTheMoney( int howMuch )
{
  Serial.print( F( "RM" ));           // print RM first
  Serial.print( howMuch / 100 );
  Serial.print( F( "." ));

  cents = howMuch % 100;
  if ( cents < 10 )
  {
    Serial.print( F( "0" ));
  }
  Serial.print( cents );
}

void loop()
{
  char key = kpd.getKey();
  if (key)
  {
    switch ( key )
    {
      case '1' :
        {
          if (posi < 6)
          {
            array[posi] = 10;//1st prodct price
            posi = posi + 1;
            Serial.println("Value 1: ");
            Serial.println(key);
            Serial.println("");
          }
          motor[ 0 ] += 1;
          motorsRunning = 1;
        }
        break;

      case '2' :
        {
          if (posi < 6)
          {
            array[posi] = 20;//2nd product price
            posi = posi + 1;
            Serial.println("Value 2: ");
            Serial.println(key);
            Serial.println("");
          }
          motor[ 1 ] += 1;
          motorsRunning = 1;
        }
        break;

      case '3' :
        {
          if (posi < 6)
          {
            array[posi] = 30;//3rd product price
            posi = posi + 1;
            Serial.println("Value 3: ");
            Serial.println(key);
            Serial.println("");
          }
        }
        break;

      case '4' :
        {
          if (posi < 6)
          {
            array[posi] = 40;//4th product price
            posi = posi + 1;
            Serial.println("Value 4: ");
            Serial.println(key);
            Serial.println("");
          }
        }
        break;

      case '5' :
        {
          if (posi < 6)
          {
            array[posi] = 50;//5th product price
            posi = posi + 1;
            Serial.println("Value 5: ");
            Serial.println(key);
            Serial.println("");
          }
        }
        break;

      case '6' :
        {
          if (posi < 6)
          {
            array[posi] = 60;//6th product price
            posi = posi + 1;
            Serial.println("Value 6: ");
            Serial.println(key);
            Serial.println("");
          }
        }
        break;

      case '#' : //enter key and total price
        {
          total = 0;
          for ( idx = 0; idx < 6; idx++ )
          {
            Value[ idx ] = array[ idx ];
            total += Value[ idx ];
          }

          Serial.println("Total:");
          Serial.println("TOTAL: RM ");// at here, it got some problem. the TOTAL show be RM 1.00 it keep show me RM100 without "."
          showMeTheMoney( total );
          entered = true;
        }
    }


    if (money >= total && entered == true)
    {

      Serial.println("OKAY");
      delay(2000);

      for ( idx = 0; idx < 6; idx++ )
      {
        if (motor[ idx ] != 0)
        {
          for ( byte x = 0; x < motor[ idx ]; x++ )
          {
            pos = 5;
            myservo[ idx ].write(pos);
            delay(3000);
            pos = 0;
            myservo[ idx ].write(pos);
            delay(3000);
            Serial.print( idx + 1 );
            Serial.println(": ");
          }
          motor[ idx ] = 0;
        }
      }

      door = 1;
//    if (( motorsRunning == 0 ) && ( door == 1 )) // silly, door just got set to 1
      if ( motorsRunning == 0 )
      {
        Serial.println("door open");
        digitalWrite(7, HIGH);
        analogWrite(6, 50);
        delay(4000);
        digitalWrite(6, LOW);
        delay(4000);
        digitalWrite(7, LOW);
        analogWrite(6, 50);
        delay(4000);
        digitalWrite(6, LOW);
        Serial.println("door close");
      }

      motorsRunning = 0;
      door = 0;
      posi = 0;

      for ( idx = 0; idx < 6; idx++ )
      {
        Value[ idx ] = 0;
      }
      total = 0;
      money = 0;
      for ( byte x = 0; x < 3; x++ ) // why only clear the 1st 3 elements?
      {
        array[x] = 0;
      }
      entered = false;

    }
  }
}
```[quote="roso_2020, post:1, topic:893185, full:true"]
Hello friends. I do a vending machine with: coin acceptor, keypad 3x4, 7 servo motors, lcd i2c. I dont no how to do the code. can anyone help me?

#include<Servo.h>
#include <Keypad.h>

const int coinInt = 1;
int money = 0;
int cents = 0;

int posi = 0;
int pos = 0;
int door = 0;

byte idx; // use as index into
int array[ 10 ]; // by default, all are 0 at start
Servo myservo[ 6 ]; // servos now in an array
int Value[ 6 ]; // by default all are = 0
int motor[ 6 ];
byte motorsRunning;

int total = 0;

boolean entered = false;

const byte ROWS = 3;
const byte COLS = 3;

char keys [ROWS] [COLS] = {
{'1', '2', '3',},
{'4', '5', '6',},
{'*', '0', '#',}
};

byte rowPins = { 13, 12, 11 };
byte colPins = { 10, 9, 8 };

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
Serial.begin(9600); // why is this less than 115200?

attachInterrupt(coinInt, coinInserted, RISING);

myservo[ 0 ].attach(4);
myservo[ 1 ].attach(5);
myservo[ 0 ].write(pos);
myservo[ 1 ].write(pos);
}

void coinInserted()
{
money = money + 10;
showMeTheMoney( money );
}

void showMeTheMoney( int howMuch )
{
Serial.print( F( "RM" )); // print RM first
Serial.print( howMuch / 100 );
Serial.print( F( "." ));

cents = howMuch % 100;
if ( cents < 10 )
{
Serial.print( F( "0" ));
}
Serial.print( cents );
}

void loop()
{
char key = kpd.getKey();
if (key)
{
switch ( key )
{
case '1' :
{
if (posi < 6)
{
array[posi] = 10;//1st prodct price
posi = posi + 1;
Serial.println("Value 1: ");
Serial.println(key);
Serial.println("");
}
motor[ 0 ] += 1;
motorsRunning = 1;
}
break;

  case '2' :
    {
      if (posi < 6)
      {
        array[posi] = 20;//2nd product price
        posi = posi + 1;
        Serial.println("Value 2: ");
        Serial.println(key);
        Serial.println("");
      }
      motor[ 1 ] += 1;
      motorsRunning = 1;
    }
    break;

  case '3' :
    {
      if (posi < 6)
      {
        array[posi] = 30;//3rd product price
        posi = posi + 1;
        Serial.println("Value 3: ");
        Serial.println(key);
        Serial.println("");
      }
    }
    break;

  case '4' :
    {
      if (posi < 6)
      {
        array[posi] = 40;//4th product price
        posi = posi + 1;
        Serial.println("Value 4: ");
        Serial.println(key);
        Serial.println("");
      }
    }
    break;

  case '5' :
    {
      if (posi < 6)
      {
        array[posi] = 50;//5th product price
        posi = posi + 1;
        Serial.println("Value 5: ");
        Serial.println(key);
        Serial.println("");
      }
    }
    break;

  case '6' :
    {
      if (posi < 6)
      {
        array[posi] = 60;//6th product price
        posi = posi + 1;
        Serial.println("Value 6: ");
        Serial.println(key);
        Serial.println("");
      }
    }
    break;

  case '#' : //enter key and total price
    {
      total = 0;
      for ( idx = 0; idx < 6; idx++ )
      {
        Value[ idx ] = array[ idx ];
        total += Value[ idx ];
      }

      Serial.println("Total:");
      Serial.println("TOTAL: RM ");// at here, it got some problem. the TOTAL show be RM 1.00 it keep show me RM100 without "."
      showMeTheMoney( total );
      entered = true;
    }
}


if (money >= total && entered == true)
{

  Serial.println("OKAY");
  delay(2000);

  for ( idx = 0; idx < 6; idx++ )
  {
    if (motor[ idx ] != 0)
    {
      for ( byte x = 0; x < motor[ idx ]; x++ )
      {
        pos = 5;
        myservo[ idx ].write(pos);
        delay(3000);
        pos = 0;
        myservo[ idx ].write(pos);
        delay(3000);
        Serial.print( idx + 1 );
        Serial.println(": ");
      }
      motor[ idx ] = 0;
    }
  }

  door = 1;

// if (( motorsRunning == 0 ) && ( door == 1 )) // silly, door just got set to 1
if ( motorsRunning == 0 )
{
Serial.println("door open");
digitalWrite(7, HIGH);
analogWrite(6, 50);
delay(4000);
digitalWrite(6, LOW);
delay(4000);
digitalWrite(7, LOW);
analogWrite(6, 50);
delay(4000);
digitalWrite(6, LOW);
Serial.println("door close");
}

  motorsRunning = 0;
  door = 0;
  posi = 0;

  for ( idx = 0; idx < 6; idx++ )
  {
    Value[ idx ] = 0;
  }
  total = 0;
  money = 0;
  for ( byte x = 0; x < 3; x++ ) // why only clear the 1st 3 elements?
  {
    array[x] = 0;
  }
  entered = false;

}

}
}

[/quote][quote="roso_2020, post:1, topic:893185, full:true"]
Hello friends. I do a vending machine with: coin acceptor, keypad 3x4, 7 servo motors, lcd i2c. I dont no how to do the code. can anyone help me?

#include<Servo.h>
#include <Keypad.h>

const int coinInt = 1;
int money = 0;
int cents = 0;

int posi = 0;
int pos = 0;
int door = 0;

byte idx; // use as index into
int array[ 10 ]; // by default, all are 0 at start
Servo myservo[ 6 ]; // servos now in an array
int Value[ 6 ]; // by default all are = 0
int motor[ 6 ];
byte motorsRunning;

int total = 0;

boolean entered = false;

const byte ROWS = 3;
const byte COLS = 3;

char keys [ROWS] [COLS] = {
{'1', '2', '3',},
{'4', '5', '6',},
{'*', '0', '#',}
};

byte rowPins = { 13, 12, 11 };
byte colPins = { 10, 9, 8 };

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
Serial.begin(9600); // why is this less than 115200?

attachInterrupt(coinInt, coinInserted, RISING);

myservo[ 0 ].attach(4);
myservo[ 1 ].attach(5);
myservo[ 0 ].write(pos);
myservo[ 1 ].write(pos);
}

void coinInserted()
{
money = money + 10;
showMeTheMoney( money );
}

void showMeTheMoney( int howMuch )
{
Serial.print( F( "RM" )); // print RM first
Serial.print( howMuch / 100 );
Serial.print( F( "." ));

cents = howMuch % 100;
if ( cents < 10 )
{
Serial.print( F( "0" ));
}
Serial.print( cents );
}

void loop()
{
char key = kpd.getKey();
if (key)
{
switch ( key )
{
case '1' :
{
if (posi < 6)
{
array[posi] = 10;//1st prodct price
posi = posi + 1;
Serial.println("Value 1: ");
Serial.println(key);
Serial.println("");
}
motor[ 0 ] += 1;
motorsRunning = 1;
}
break;

  case '2' :
    {
      if (posi < 6)
      {
        array[posi] = 20;//2nd product price
        posi = posi + 1;
        Serial.println("Value 2: ");
        Serial.println(key);
        Serial.println("");
      }
      motor[ 1 ] += 1;
      motorsRunning = 1;
    }
    break;

  case '3' :
    {
      if (posi < 6)
      {
        array[posi] = 30;//3rd product price
        posi = posi + 1;
        Serial.println("Value 3: ");
        Serial.println(key);
        Serial.println("");
      }
    }
    break;

  case '4' :
    {
      if (posi < 6)
      {
        array[posi] = 40;//4th product price
        posi = posi + 1;
        Serial.println("Value 4: ");
        Serial.println(key);
        Serial.println("");
      }
    }
    break;

  case '5' :
    {
      if (posi < 6)
      {
        array[posi] = 50;//5th product price
        posi = posi + 1;
        Serial.println("Value 5: ");
        Serial.println(key);
        Serial.println("");
      }
    }
    break;

  case '6' :
    {
      if (posi < 6)
      {
        array[posi] = 60;//6th product price
        posi = posi + 1;
        Serial.println("Value 6: ");
        Serial.println(key);
        Serial.println("");
      }
    }
    break;

  case '#' : //enter key and total price
    {
      total = 0;
      for ( idx = 0; idx < 6; idx++ )
      {
        Value[ idx ] = array[ idx ];
        total += Value[ idx ];
      }

      Serial.println("Total:");
      Serial.println("TOTAL: RM ");// at here, it got some problem. the TOTAL show be RM 1.00 it keep show me RM100 without "."
      showMeTheMoney( total );
      entered = true;
    }
}


if (money >= total && entered == true)
{

  Serial.println("OKAY");
  delay(2000);

  for ( idx = 0; idx < 6; idx++ )
  {
    if (motor[ idx ] != 0)
    {
      for ( byte x = 0; x < motor[ idx ]; x++ )
      {
        pos = 5;
        myservo[ idx ].write(pos);
        delay(3000);
        pos = 0;
        myservo[ idx ].write(pos);
        delay(3000);
        Serial.print( idx + 1 );
        Serial.println(": ");
      }
      motor[ idx ] = 0;
    }
  }

  door = 1;

// if (( motorsRunning == 0 ) && ( door == 1 )) // silly, door just got set to 1
if ( motorsRunning == 0 )
{
Serial.println("door open");
digitalWrite(7, HIGH);
analogWrite(6, 50);
delay(4000);
digitalWrite(6, LOW);
delay(4000);
digitalWrite(7, LOW);
analogWrite(6, 50);
delay(4000);
digitalWrite(6, LOW);
Serial.println("door close");
}

  motorsRunning = 0;
  door = 0;
  posi = 0;

  for ( idx = 0; idx < 6; idx++ )
  {
    Value[ idx ] = 0;
  }
  total = 0;
  money = 0;
  for ( byte x = 0; x < 3; x++ ) // why only clear the 1st 3 elements?
  {
    array[x] = 0;
  }
  entered = false;

}

}
}

Hello friends. I do a vending machine with: coin acceptor, keypad 3x4, 7 servo motors, lcd i2c. I dont no how to do the code. can anyone help me?

#include<Servo.h>
#include <Keypad.h>

const int coinInt = 1;
int money = 0;
int cents = 0;

int posi = 0;
int pos = 0;
int door = 0;

byte idx; // use as index into
int array[ 10 ]; // by default, all are 0 at start
Servo myservo[ 6 ]; // servos now in an array
int Value[ 6 ]; // by default all are = 0
int motor[ 6 ];
byte motorsRunning;

int total = 0;

boolean entered = false;

const byte ROWS = 3;
const byte COLS = 3;

char keys [ROWS] [COLS] = {
{'1', '2', '3',},
{'4', '5', '6',},
{'*', '0', '#',}
};

byte rowPins = { 13, 12, 11 };
byte colPins = { 10, 9, 8 };

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
Serial.begin(9600); // why is this less than 115200?

attachInterrupt(coinInt, coinInserted, RISING);

myservo[ 0 ].attach(4);
myservo[ 1 ].attach(5);
myservo[ 0 ].write(pos);
myservo[ 1 ].write(pos);
}

void coinInserted()
{
money = money + 10;
showMeTheMoney( money );
}

void showMeTheMoney( int howMuch )
{
Serial.print( F( "RM" )); // print RM first
Serial.print( howMuch / 100 );
Serial.print( F( "." ));

cents = howMuch % 100;
if ( cents < 10 )
{
Serial.print( F( "0" ));
}
Serial.print( cents );
}

void loop()
{
char key = kpd.getKey();
if (key)
{
switch ( key )
{
case '1' :
{
if (posi < 6)
{
array[posi] = 10;//1st prodct price
posi = posi + 1;
Serial.println("Value 1: ");
Serial.println(key);
Serial.println("");
}
motor[ 0 ] += 1;
motorsRunning = 1;
}
break;

  case '2' :
    {
      if (posi < 6)
      {
        array[posi] = 20;//2nd product price
        posi = posi + 1;
        Serial.println("Value 2: ");
        Serial.println(key);
        Serial.println("");
      }
      motor[ 1 ] += 1;
      motorsRunning = 1;
    }
    break;

  case '3' :
    {
      if (posi < 6)
      {
        array[posi] = 30;//3rd product price
        posi = posi + 1;
        Serial.println("Value 3: ");
        Serial.println(key);
        Serial.println("");
      }
    }
    break;

  case '4' :
    {
      if (posi < 6)
      {
        array[posi] = 40;//4th product price
        posi = posi + 1;
        Serial.println("Value 4: ");
        Serial.println(key);
        Serial.println("");
      }
    }
    break;

  case '5' :
    {
      if (posi < 6)
      {
        array[posi] = 50;//5th product price
        posi = posi + 1;
        Serial.println("Value 5: ");
        Serial.println(key);
        Serial.println("");
      }
    }
    break;

  case '6' :
    {
      if (posi < 6)
      {
        array[posi] = 60;//6th product price
        posi = posi + 1;
        Serial.println("Value 6: ");
        Serial.println(key);
        Serial.println("");
      }
    }
    break;

  case '#' : //enter key and total price
    {
      total = 0;
      for ( idx = 0; idx < 6; idx++ )
      {
        Value[ idx ] = array[ idx ];
        total += Value[ idx ];
      }

      Serial.println("Total:");
      Serial.println("TOTAL: RM ");// at here, it got some problem. the TOTAL show be RM 1.00 it keep show me RM100 without "."
      showMeTheMoney( total );
      entered = true;
    }
}


if (money >= total && entered == true)
{

  Serial.println("OKAY");
  delay(2000);

  for ( idx = 0; idx < 6; idx++ )
  {
    if (motor[ idx ] != 0)
    {
      for ( byte x = 0; x < motor[ idx ]; x++ )
      {
        pos = 5;
        myservo[ idx ].write(pos);
        delay(3000);
        pos = 0;
        myservo[ idx ].write(pos);
        delay(3000);
        Serial.print( idx + 1 );
        Serial.println(": ");
      }
      motor[ idx ] = 0;
    }
  }

  door = 1;

// if (( motorsRunning == 0 ) && ( door == 1 )) // silly, door just got set to 1
if ( motorsRunning == 0 )
{
Serial.println("door open");
digitalWrite(7, HIGH);
analogWrite(6, 50);
delay(4000);
digitalWrite(6, LOW);
delay(4000);
digitalWrite(7, LOW);
analogWrite(6, 50);
delay(4000);
digitalWrite(6, LOW);
Serial.println("door close");
}

  motorsRunning = 0;
  door = 0;
  posi = 0;

  for ( idx = 0; idx < 6; idx++ )
  {
    Value[ idx ] = 0;
  }
  total = 0;
  money = 0;
  for ( byte x = 0; x < 3; x++ ) // why only clear the 1st 3 elements?
  {
    array[x] = 0;
  }
  entered = false;

}

}
}

[/quote]
[/quote]

[quote="roso_2020, post:1, topic:893185, full:true"]
Hello friends. I do a vending machine with: coin acceptor, keypad 3x4, 7 servo motors, lcd i2c. I dont no how to do the code. can anyone help me?

#include<Servo.h>
#include <Keypad.h>

const int coinInt = 1;
int money = 0;
int cents = 0;

int posi = 0;
int pos = 0;
int door = 0;

byte idx; // use as index into
int array[ 10 ]; // by default, all are 0 at start
Servo myservo[ 6 ]; // servos now in an array
int Value[ 6 ]; // by default all are = 0
int motor[ 6 ];
byte motorsRunning;

int total = 0;

boolean entered = false;

const byte ROWS = 3;
const byte COLS = 3;

char keys [ROWS] [COLS] = {
{'1', '2', '3',},
{'4', '5', '6',},
{'*', '0', '#',}
};

byte rowPins = { 13, 12, 11 };
byte colPins = { 10, 9, 8 };

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
Serial.begin(9600); // why is this less than 115200?

attachInterrupt(coinInt, coinInserted, RISING);

myservo[ 0 ].attach(4);
myservo[ 1 ].attach(5);
myservo[ 0 ].write(pos);
myservo[ 1 ].write(pos);
}

void coinInserted()
{
money = money + 10;
showMeTheMoney( money );
}

void showMeTheMoney( int howMuch )
{
Serial.print( F( "RM" )); // print RM first
Serial.print( howMuch / 100 );
Serial.print( F( "." ));

cents = howMuch % 100;
if ( cents < 10 )
{
Serial.print( F( "0" ));
}
Serial.print( cents );
}

void loop()
{
char key = kpd.getKey();
if (key)
{
switch ( key )
{
case '1' :
{
if (posi < 6)
{
array[posi] = 10;//1st prodct price
posi = posi + 1;
Serial.println("Value 1: ");
Serial.println(key);
Serial.println("");
}
motor[ 0 ] += 1;
motorsRunning = 1;
}
break;

  case '2' :
    {
      if (posi < 6)
      {
        array[posi] = 20;//2nd product price
        posi = posi + 1;
        Serial.println("Value 2: ");
        Serial.println(key);
        Serial.println("");
      }
      motor[ 1 ] += 1;
      motorsRunning = 1;
    }
    break;

  case '3' :
    {
      if (posi < 6)
      {
        array[posi] = 30;//3rd product price
        posi = posi + 1;
        Serial.println("Value 3: ");
        Serial.println(key);
        Serial.println("");
      }
    }
    break;

  case '4' :
    {
      if (posi < 6)
      {
        array[posi] = 40;//4th product price
        posi = posi + 1;
        Serial.println("Value 4: ");
        Serial.println(key);
        Serial.println("");
      }
    }
    break;

  case '5' :
    {
      if (posi < 6)
      {
        array[posi] = 50;//5th product price
        posi = posi + 1;
        Serial.println("Value 5: ");
        Serial.println(key);
        Serial.println("");
      }
    }
    break;

  case '6' :
    {
      if (posi < 6)
      {
        array[posi] = 60;//6th product price
        posi = posi + 1;
        Serial.println("Value 6: ");
        Serial.println(key);
        Serial.println("");
      }
    }
    break;

  case '#' : //enter key and total price
    {
      total = 0;
      for ( idx = 0; idx < 6; idx++ )
      {
        Value[ idx ] = array[ idx ];
        total += Value[ idx ];
      }

      Serial.println("Total:");
      Serial.println("TOTAL: RM ");// at here, it got some problem. the TOTAL show be RM 1.00 it keep show me RM100 without "."
      showMeTheMoney( total );
      entered = true;
    }
}


if (money >= total && entered == true)
{

  Serial.println("OKAY");
  delay(2000);

  for ( idx = 0; idx < 6; idx++ )
  {
    if (motor[ idx ] != 0)
    {
      for ( byte x = 0; x < motor[ idx ]; x++ )
      {
        pos = 5;
        myservo[ idx ].write(pos);
        delay(3000);
        pos = 0;
        myservo[ idx ].write(pos);
        delay(3000);
        Serial.print( idx + 1 );
        Serial.println(": ");
      }
      motor[ idx ] = 0;
    }
  }

  door = 1;

// if (( motorsRunning == 0 ) && ( door == 1 )) // silly, door just got set to 1
if ( motorsRunning == 0 )
{
Serial.println("door open");
digitalWrite(7, HIGH);
analogWrite(6, 50);
delay(4000);
digitalWrite(6, LOW);
delay(4000);
digitalWrite(7, LOW);
analogWrite(6, 50);
delay(4000);
digitalWrite(6, LOW);
Serial.println("door close");
}

  motorsRunning = 0;
  door = 0;
  posi = 0;

  for ( idx = 0; idx < 6; idx++ )
  {
    Value[ idx ] = 0;
  }
  total = 0;
  money = 0;
  for ( byte x = 0; x < 3; x++ ) // why only clear the 1st 3 elements?
  {
    array[x] = 0;
  }
  entered = false;

}

}
}

Hello friends. I do a vending machine with: coin acceptor, keypad 3x4, 7 servo motors, lcd i2c. I dont no how to do the code. can anyone help me?

#include<Servo.h>
#include <Keypad.h>

const int coinInt = 1;
int money = 0;
int cents = 0;

int posi = 0;
int pos = 0;
int door = 0;

byte idx; // use as index into
int array[ 10 ]; // by default, all are 0 at start
Servo myservo[ 6 ]; // servos now in an array
int Value[ 6 ]; // by default all are = 0
int motor[ 6 ];
byte motorsRunning;

int total = 0;

boolean entered = false;

const byte ROWS = 3;
const byte COLS = 3;

char keys [ROWS] [COLS] = {
{'1', '2', '3',},
{'4', '5', '6',},
{'*', '0', '#',}
};

byte rowPins = { 13, 12, 11 };
byte colPins = { 10, 9, 8 };

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
Serial.begin(9600); // why is this less than 115200?

attachInterrupt(coinInt, coinInserted, RISING);

myservo[ 0 ].attach(4);
myservo[ 1 ].attach(5);
myservo[ 0 ].write(pos);
myservo[ 1 ].write(pos);
}

void coinInserted()
{
money = money + 10;
showMeTheMoney( money );
}

void showMeTheMoney( int howMuch )
{
Serial.print( F( "RM" )); // print RM first
Serial.print( howMuch / 100 );
Serial.print( F( "." ));

cents = howMuch % 100;
if ( cents < 10 )
{
Serial.print( F( "0" ));
}
Serial.print( cents );
}

void loop()
{
char key = kpd.getKey();
if (key)
{
switch ( key )
{
case '1' :
{
if (posi < 6)
{
array[posi] = 10;//1st prodct price
posi = posi + 1;
Serial.println("Value 1: ");
Serial.println(key);
Serial.println("");
}
motor[ 0 ] += 1;
motorsRunning = 1;
}
break;

  case '2' :
    {
      if (posi < 6)
      {
        array[posi] = 20;//2nd product price
        posi = posi + 1;
        Serial.println("Value 2: ");
        Serial.println(key);
        Serial.println("");
      }
      motor[ 1 ] += 1;
      motorsRunning = 1;
    }
    break;

  case '3' :
    {
      if (posi < 6)
      {
        array[posi] = 30;//3rd product price
        posi = posi + 1;
        Serial.println("Value 3: ");
        Serial.println(key);
        Serial.println("");
      }
    }
    break;

  case '4' :
    {
      if (posi < 6)
      {
        array[posi] = 40;//4th product price
        posi = posi + 1;
        Serial.println("Value 4: ");
        Serial.println(key);
        Serial.println("");
      }
    }
    break;

  case '5' :
    {
      if (posi < 6)
      {
        array[posi] = 50;//5th product price
        posi = posi + 1;
        Serial.println("Value 5: ");
        Serial.println(key);
        Serial.println("");
      }
    }
    break;

  case '6' :
    {
      if (posi < 6)
      {
        array[posi] = 60;//6th product price
        posi = posi + 1;
        Serial.println("Value 6: ");
        Serial.println(key);
        Serial.println("");
      }
    }
    break;

  case '#' : //enter key and total price
    {
      total = 0;
      for ( idx = 0; idx < 6; idx++ )
      {
        Value[ idx ] = array[ idx ];
        total += Value[ idx ];
      }

      Serial.println("Total:");
      Serial.println("TOTAL: RM ");// at here, it got some problem. the TOTAL show be RM 1.00 it keep show me RM100 without "."
      showMeTheMoney( total );
      entered = true;
    }
}


if (money >= total && entered == true)
{

  Serial.println("OKAY");
  delay(2000);

  for ( idx = 0; idx < 6; idx++ )
  {
    if (motor[ idx ] != 0)
    {
      for ( byte x = 0; x < motor[ idx ]; x++ )
      {
        pos = 5;
        myservo[ idx ].write(pos);
        delay(3000);
        pos = 0;
        myservo[ idx ].write(pos);
        delay(3000);
        Serial.print( idx + 1 );
        Serial.println(": ");
      }
      motor[ idx ] = 0;
    }
  }

  door = 1;

// if (( motorsRunning == 0 ) && ( door == 1 )) // silly, door just got set to 1
if ( motorsRunning == 0 )
{
Serial.println("door open");
digitalWrite(7, HIGH);
analogWrite(6, 50);
delay(4000);
digitalWrite(6, LOW);
delay(4000);
digitalWrite(7, LOW);
analogWrite(6, 50);
delay(4000);
digitalWrite(6, LOW);
Serial.println("door close");
}

  motorsRunning = 0;
  door = 0;
  posi = 0;

  for ( idx = 0; idx < 6; idx++ )
  {
    Value[ idx ] = 0;
  }
  total = 0;
  money = 0;
  for ( byte x = 0; x < 3; x++ ) // why only clear the 1st 3 elements?
  {
    array[x] = 0;
  }
  entered = false;

}

}
}

[/quote]
[/quote]

Please edit your post to add code tags, as described in the how to use the forum post.

Then tell us what goes wrong.

WTF?

How many programs did you post?

Why did you post so many programs?

Probably because he's new?
OP, what part of the planet are you located?

-jim lee

@roso_2020, your topic has been moved to a more suitable location on the forum. Introductory Tutorials is for tutorials that e.g. you write, not for questions. Feel free to write a tutorial once you have solved your problem :wink:

Please edit your post, select the code and click the </> button; next save your post. The prevents mangling of your code by the forum software (e.g. [] will not change to ), makes it easier to read and easier to copy.