Схема
Код
/*--------------------VenDuino V0_31------(c) 2016 Ryan Bates, RetroBuiltgames.com--------- Vending machine using FULL ROTATION servos. I/O PIN# ServoA ~11 ServoB ~10 ServoC ~9 ServoD ~6 ButtonA 8 ButtonB 7 ButtonC 5 ButtonD 4 LEDready 13 LEDdispense 12 coinInsert - 3 A0-A4 Nokia5110 LCD */ #include <LCD5110_Graph.h> LCD5110 myGLCD(A0,A1,A2,A3,A4); extern uint8_t SmallFont[]; const int ServoA = 11; const int ServoB = 10; const int ServoC = 9; const int ServoD = 6; const int clockwise = 1700; const int counterclockwise = 1300; const int ButtonA = 8; const int ButtonB = 7; const int ButtonC = 5; const int ButtonD = 4; const int LEDready = 13; const int coinInsert = 12; long previousMillis = 0; long intervalIdle = 500; int LEDreadyState = LOW; int y1= 0; int y2= 10; //position shifters for LCd txt void setup() { myGLCD.InitLCD(); myGLCD.setFont(SmallFont); myGLCD.setContrast(70); pinMode(ButtonA, INPUT_PULLUP); pinMode(ButtonB, INPUT_PULLUP); pinMode(ButtonC, INPUT_PULLUP); pinMode(ButtonD, INPUT_PULLUP); pinMode(LEDready, OUTPUT); pinMode(coinInsert, INPUT_PULLUP); myGLCD.invert(true); myGLCD.print("VenDuino", CENTER, 1); myGLCD.print("by Ryan", CENTER, 10); myGLCD.print("(c) 2016", CENTER, 30); myGLCD.drawRoundRect(13, 0, 70, 8); myGLCD.drawRect(0, 20, 83, 47); myGLCD.update(); delay(1000); myGLCD.clrScr(); myGLCD.update(); } void loop() { //--Blink Ready LED--------------------------------------------------- unsigned long currentMillis = millis(); if(currentMillis - previousMillis >= intervalIdle) { // save the last time you blinked the LED previousMillis = currentMillis; if (LEDreadyState == LOW){ // if the LED is off turn it on and vice-versa: LEDreadyState = HIGH; myGLCD.clrScr(); myGLCD.print("Please insert", CENTER, y1); myGLCD.print(" $0.25. ", CENTER, y2); myGLCD.invert(false); myGLCD.update(); } else LEDreadyState = LOW; digitalWrite(LEDready, LEDreadyState);// set the LED with the ledState of the variable: y1=y1 +5; y2=y2+5; //shift the text position down if ((y1==35) && (y2== 45)) //when the text almost goes off-screen, move it back up {y1=0; y2=10; } } //---Wait for Coin/Credit--------------------------------------------------------------- while (digitalRead(coinInsert)==LOW) { //if coin inserted stay in servo enable loop digitalWrite(LEDready, HIGH); myGLCD.clrScr(); myGLCD.update(); myGLCD.print("Please make", CENTER, 0); myGLCD.print(" a selection. ", CENTER, 10); myGLCD.drawRect(20, 20, 63, 47); myGLCD.drawRect(20, 20, 41, 47); myGLCD.drawRect(20, 20, 63, 34); myGLCD.update(); servoEnable(); } } void servoEnable(){ while (digitalRead(ButtonA) == HIGH || digitalRead(ButtonB) == HIGH || digitalRead(ButtonC) == HIGH || digitalRead(ButtonD) == HIGH) { //---------Servo A---------------------------------------------------- if ((digitalRead(ButtonA) == LOW) ) { for(int i=0; i<2; i++) {digitalWrite(LEDready, HIGH); delay(50); digitalWrite(LEDready, LOW); delay(50); } myGLCD.clrScr(); myGLCD.print("Vending", CENTER, 0); myGLCD.drawRect(20, 20, 63, 47); myGLCD.drawRect(20, 20, 41, 47); myGLCD.drawRect(20, 20, 63, 34); myGLCD.print("A1", 25, 24); myGLCD.update(); for(int i=0; i<57; i++) // change this to adjust +- full revolution { digitalWrite(ServoA,HIGH); delayMicroseconds(clockwise); // 1.7ms digitalWrite(ServoA,LOW); delay(18.5); // 18.5ms //delay(50); enable this line to slow the angular velcity of the servo rotation } break; } // when item is dispensed exit loop and return to wait for coin //---------Servo B---------------------------------------------------- if ((digitalRead(ButtonB) == LOW) ) { for(int i=0; i<2; i++) {digitalWrite(LEDready, HIGH); delay(50); digitalWrite(LEDready, LOW); delay(50); } myGLCD.clrScr(); myGLCD.print("Vending", CENTER, 0); myGLCD.drawRect(20, 20, 63, 47); myGLCD.drawRect(20, 20, 41, 47); myGLCD.drawRect(20, 20, 63, 34); myGLCD.print("B1", 46, 24); myGLCD.update(); for(int i=0; i<57; i++) { digitalWrite(ServoB,HIGH); delayMicroseconds(counterclockwise); // 1.7ms digitalWrite(ServoB,LOW); delay(18.5); // 18.5ms //delay(50); } break; } //---------Servo C---------------------------------------------------- if ((digitalRead(ButtonC) == LOW) ) { for(int i=0; i<2; i++) {digitalWrite(LEDready, HIGH); delay(50); digitalWrite(LEDready, LOW); delay(50); } myGLCD.clrScr(); myGLCD.print("Vending", CENTER, 0); myGLCD.drawRect(20, 20, 63, 47); myGLCD.drawRect(20, 20, 41, 47); myGLCD.drawRect(20, 20, 63, 34); myGLCD.print("C2", 25, 37); myGLCD.update(); for(int i=0; i<57; i++) { digitalWrite(ServoC,HIGH); delayMicroseconds(clockwise); // 1.7ms digitalWrite(ServoC,LOW); delay(18.5); // 18.5ms //delay(50); } break; } //---------Servo D---------------------------------------------------- if ((digitalRead(ButtonD) == LOW) ) { for(int i=0; i<2; i++) {digitalWrite(LEDready, HIGH); delay(50); digitalWrite(LEDready, LOW); delay(50); } myGLCD.clrScr(); myGLCD.print("Vending", CENTER, 0); myGLCD.drawRect(20, 20, 63, 47); myGLCD.drawRect(20, 20, 41, 47); myGLCD.drawRect(20, 20, 63, 34); myGLCD.print("D2", 46, 37); myGLCD.update(); for(int i=0; i<57; i++) { digitalWrite(ServoD,HIGH); delayMicroseconds(clockwise); // 1.7ms digitalWrite(ServoD,LOW); delay(18.5); // 18.5ms //delay(50); } break; } } }
Ссылки
Venduino
По теме
Arduino для автоматизации кофейного автомата
Arduino для автоматизации снекового автомата
Вендинговый автомат с Arduino!
Arduino как фреймворк
Ардуино что это и зачем?
Arduino, термины, начало работы
Разновидности плат Arduino, а также про клоны, оригиналы и совместимость
КМБ для начинающих ардуинщиков