Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.09 KB | None | 0 0
  1. /*
  2. Copyright 2020 Brandon Sherwin
  3. */
  4.  
  5. // initialize the library with the numbers of the interface pins
  6. #include <LiquidCrystal.h>
  7. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  8.  
  9. #include <Servo.h>
  10. Servo myservo;  // create servo object to control a servo
  11.  
  12. const int buttonPin = 6;     // the number of the pushbutton pin
  13. const int ledPin =  13;      // the number of the LED pin
  14.  
  15. // variables will change:
  16. int buttonState = 0;  // variable for reading the pushbutton status
  17. int pos = 0;    // variable to store the servo position
  18.  
  19. void setup() {
  20.   pinMode(ledPin, OUTPUT);  // initialize the LED pin as an output
  21.   pinMode(buttonPin, INPUT);  // initialize the pushbutton pin as an input
  22.   lcd.begin(16, 2);  // set up the LCD's number of columns and rows
  23.   myservo.attach(12);  // attaches the servo on pin 9 to the servo object
  24. }
  25.  
  26. void loop() {
  27.   lcd.display();  // Turns LCD on
  28.   buttonState = digitalRead(buttonPin);  // reads pushbutton state
  29.  
  30.   if (buttonState == HIGH) {  // check if the pushbutton is pressed
  31.     lcd.clear();
  32.     delay(10);
  33.     lcd.setCursor(0, 0);  // Display position
  34.     lcd.print("Vending.");
  35.     delay(1000);
  36.     pos = 180;
  37.   myservo.write(pos);  {            // tell servo to go to position in variable 'pos'
  38.   delay(15); }
  39.     lcd.setCursor(0, 0);
  40.     lcd.print("Vending..");
  41.     delay(1000);
  42.     lcd.setCursor(0, 0);
  43.     lcd.print("Vending...");
  44.     delay(1000);
  45.     lcd.clear();
  46.     delay(100);  // Use sensor to verify product was dispensed to display Enjoy
  47.     lcd.print("Enjoy!");
  48.     delay(1000);
  49.     for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
  50.     myservo.write(pos);
  51.     delay(20);     }            // tell servo to go to position in variable 'pos'
  52.     lcd.clear();
  53.     delay(100);
  54.   } else {
  55.     digitalWrite(9,HIGH);
  56.     lcd.setCursor(0, 0);  // Display position
  57.     lcd.print("Make a selection");
  58.     lcd.setCursor(0, 1);  // Display position
  59.     lcd.print("Credit:");
  60.     lcd.setCursor(8, 1);  // Display position
  61.     lcd.print("$2.00");  // Replace with system to take money
  62.     digitalWrite(ledPin, LOW);
  63.   }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement