Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: "Vending Simulation"
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-12-09 21:56:20
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The project aims to create an interactive Arduino */
- /* application that utilizes connected components for */
- /* sensor data collection and real-time feedback. The */
- /* code should efficiently manage input/output */
- /* operations and ensure reliable performance. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h> // Include Wire library for I2C communication
- #include <Servo.h> // Include Servo library for controlling servo motors
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // Define items, prices, and stock for the vending machine
- const char* items[] = {"Soda", "Chips", "Candy"}; // Example items
- float prices[] = {1.50, 1.00, 0.75}; // Example prices
- int stock[] = {5, 5, 5}; // Example stock levels
- void setup(void)
- {
- // Initialize serial communication for debugging
- Serial.begin(9600);
- // Initialize I2C communication
- Wire.begin();
- // Initialize servo motors (if used)
- // Servo myServo; // Uncomment and define your servo if needed
- // myServo.attach(9); // Attach to pin 9 (example)
- }
- void loop(void)
- {
- // Display available items and their prices
- Serial.println("Available items:");
- for (int i = 0; i < sizeof(items) / sizeof(items[0]); i++) {
- Serial.print(i + 1);
- Serial.print(". ");
- Serial.print(items[i]);
- Serial.print(" - $");
- Serial.print(prices[i]);
- Serial.print(" (Stock: ");
- Serial.print(stock[i]);
- Serial.println(")");
- }
- // Simulate user input for item selection
- int choice = 1; // Example choice (this should be replaced with actual input handling)
- if (choice < 1 || choice > sizeof(items) / sizeof(items[0])) {
- Serial.println("Invalid choice.");
- return;
- }
- if (stock[choice - 1] == 0) {
- Serial.println("Out of stock.");
- return;
- }
- int item_index = choice - 1;
- // Simulate payment
- float payment = 2.00; // Example payment (this should be replaced with actual input handling)
- if (payment < prices[item_index]) {
- Serial.println("Insufficient payment. Transaction cancelled.");
- return;
- }
- float change = payment - prices[item_index];
- Serial.print("Payment accepted. Change to return: $");
- Serial.println(change);
- // Dispense the selected item
- stock[item_index] -= 1;
- Serial.print("Dispensing ");
- Serial.println(items[item_index]);
- delay(5000); // Delay for 5 seconds before the next loop iteration
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement