Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Copyright 2020 Brandon Sherwin
- */
- // initialize the library with the numbers of the interface pins
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- #include <Servo.h>
- Servo myservo; // create servo object to control a servo
- const int buttonPin = 6; // the number of the pushbutton pin
- const int ledPin = 13; // the number of the LED pin
- // variables will change:
- int buttonState = 0; // variable for reading the pushbutton status
- int pos = 0; // variable to store the servo position
- void setup() {
- pinMode(ledPin, OUTPUT); // initialize the LED pin as an output
- pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input
- lcd.begin(16, 2); // set up the LCD's number of columns and rows
- myservo.attach(12); // attaches the servo on pin 9 to the servo object
- }
- void loop() {
- lcd.display(); // Turns LCD on
- buttonState = digitalRead(buttonPin); // reads pushbutton state
- if (buttonState == HIGH) { // check if the pushbutton is pressed
- lcd.clear();
- delay(10);
- lcd.setCursor(0, 0); // Display position
- lcd.print("Vending.");
- delay(1000);
- pos = 180;
- myservo.write(pos); { // tell servo to go to position in variable 'pos'
- delay(15); }
- lcd.setCursor(0, 0);
- lcd.print("Vending..");
- delay(1000);
- lcd.setCursor(0, 0);
- lcd.print("Vending...");
- delay(1000);
- lcd.clear();
- delay(100); // Use sensor to verify product was dispensed to display Enjoy
- lcd.print("Enjoy!");
- delay(1000);
- for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
- myservo.write(pos);
- delay(20); } // tell servo to go to position in variable 'pos'
- lcd.clear();
- delay(100);
- } else {
- digitalWrite(9,HIGH);
- lcd.setCursor(0, 0); // Display position
- lcd.print("Make a selection");
- lcd.setCursor(0, 1); // Display position
- lcd.print("Credit:");
- lcd.setCursor(8, 1); // Display position
- lcd.print("$2.00"); // Replace with system to take money
- digitalWrite(ledPin, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement