#include <Servo.h>

const int coinSensorPin = 2;
const int teaButtonPin = 3;
const int coffeeButtonPin = 4;
const int milkButtonPin = 5;
const int sugarButtonPin = 6;

Servo hotWaterServo;
Servo milkServo;
Servo sugarServo;

bool teaSelected = false;
bool coffeeSelected = false;
bool milkSelected = false;
bool sugarSelected = false;
bool coinInserted = false;

void setup() {
  pinMode(coinSensorPin, INPUT);
  pinMode(teaButtonPin, INPUT);
  pinMode(coffeeButtonPin, INPUT);
  pinMode(milkButtonPin, INPUT);
  pinMode(sugarButtonPin, INPUT);

  hotWaterServo.attach(9);
  milkServo.attach(10);
  sugarServo.attach(11);

  Serial.begin(9600);
}

void loop() {
  // Check if a coin is inserted
  if (digitalRead(coinSensorPin) == HIGH) {
    coinInserted = true;
    Serial.println("Coin inserted. Select your options.");
    delay(1000); // Debouncing delay
  }

  // If a coin is inserted, allow user selections
  if (coinInserted) {
    // Check for tea selection
    if (digitalRead(teaButtonPin) == HIGH) {
      teaSelected = true;
      Serial.println("Tea selected.");
      delay(1000); // Debouncing delay
    }

    // Check for coffee selection
    if (digitalRead(coffeeButtonPin) == HIGH) {
      coffeeSelected = true;
      Serial.println("Coffee selected.");
      delay(1000); // Debouncing delay
    }

    // Check for milk selection
    if (digitalRead(milkButtonPin) == HIGH) {
      milkSelected = true;
      Serial.println("Milk selected.");
      delay(1000); // Debouncing delay
    }

    // Check for sugar selection
    if (digitalRead(sugarButtonPin) == HIGH) {
      sugarSelected = true;
      Serial.println("Sugar selected.");
      delay(1000); // Debouncing delay
    }

    // Dispense drink based on selections
    if (teaSelected || coffeeSelected) {
      dispenseHotWater();
    }

    if (milkSelected) {
      dispenseMilk();
    }

    if (sugarSelected) {
      dispenseSugar();
    }

    // Reset selections and coin status for the next customer
    teaSelected = false;
    coffeeSelected = false;
    milkSelected = false;
    sugarSelected = false;
    coinInserted = false;
  }
}

void dispenseHotWater() {
  Serial.println("Dispensing hot water...");
  hotWaterServo.write(90); // Adjust the servo angle based on your setup
  delay(5000); // Adjust the delay based on the time needed to dispense hot water
  hotWaterServo.write(0); // Return the servo to the initial position
}

void dispenseMilk() {
  Serial.println("Dispensing milk...");
  milkServo.write(90); // Adjust the servo angle based on your setup
  delay(3000); // Adjust the delay based on the time needed to dispense milk
  milkServo.write(0); // Return the servo to the initial position
}

void dispenseSugar() {
  Serial.println("Dispensing sugar...");
  sugarServo.write(90); // Adjust the servo angle based on your setup
  delay(2000); // Adjust the delay based on the time needed to dispense sugar
  sugarServo.write(0); // Return the servo to the initial position
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5