ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Codigo para Arduino Maquina Expendedora


Enviado por   •  16 de Noviembre de 2019  •  Tutoriales  •  1.136 Palabras (5 Páginas)  •  1.432 Visitas

Página 1 de 5

#include <LiquidCrystal.h>

#include <Servo.h>

LiquidCrystal lcd(27, 26, 25, 24, 23, 22);

Servo servo1, servo2, servo3, servo4;

//Para el Motor Nema

#define dirPinVertical 0

#define stepPinVertical 1

#define dirPinHorizontal 2

#define stepPinHorizontal 3

//Para el Detector de movimiento

#define coinDetector 9

#define button1 13

#define button2 12

#define button3 11

#define button4 10

#define microSwitchV 15 //Microswitch vertical

#define microSwitchH 14 //Microswitch Horizontal

int buttonPressed;

void setup() {

lcd.begin(16, 2);

servo1.attach(4);

servo2.attach(5);

servo3.attach(6);

servo4.attach(7);

pinMode(dirPinVertical, OUTPUT);

pinMode(stepPinVertical, OUTPUT);

pinMode(dirPinHorizontal, OUTPUT);

pinMode(stepPinHorizontal, OUTPUT);

pinMode(coinDetector, INPUT);

// Activating the digital pins pull up resistors

pinMode(button1, INPUT_PULLUP);

pinMode(button2, INPUT_PULLUP);

pinMode(button3, INPUT_PULLUP);

pinMode(button4, INPUT_PULLUP);

pinMode(microSwitchV, INPUT_PULLUP);

pinMode(microSwitchH, INPUT_PULLUP);

// Vertical starting position

digitalWrite(dirPinVertical, HIGH); // Set the stepper to move in a particular direction

while (true) {

if (digitalRead(microSwitchV) == LOW) { // If the micro switch is pressed, move the platfor a little bit up and exit the while loop

moveUp(70);

break;

}

// Move the carrier up until the micro switch is pressed

digitalWrite(stepPinVertical, HIGH);

delayMicroseconds(300);

digitalWrite(stepPinVertical, LOW);

delayMicroseconds(300);

}

// Horizontal starting position

digitalWrite(dirPinHorizontal, LOW);

while (true) {

if (digitalRead(microSwitchH) == LOW) {

moveLeft(350);

break;

}

digitalWrite(stepPinHorizontal, HIGH);

delayMicroseconds(300);

digitalWrite(stepPinHorizontal, LOW);

delayMicroseconds(300);

}

}

void loop() {

// Print "Insert a coin!" on the LCD

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("Insert a coin!");

// Wait until a coin is detected

while (true) {

if (digitalRead(coinDetector) == LOW) { // If a coin is detected, exit the from the while loop

break;

}

}

delay(10);

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("Select your item");

lcd.setCursor(0, 1);

lcd.print(" 1, 2, 3 or 4?");

// eleccion del boton

while (true) {

if (digitalRead(button1) == LOW) {

buttonPressed = 1;

break;

}

if (digitalRead(button2) == LOW) {

buttonPressed = 2;

break;

}

if (digitalRead(button3) == LOW) {

buttonPressed = 3;

break;

}

if (digitalRead(button4) == LOW) {

buttonPressed = 4;

break;

}

}

// Print "Delivering..."

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("Delivering...");

...

Descargar como (para miembros actualizados)  txt (6 Kb)   pdf (40 Kb)   docx (11 Kb)  
Leer 4 páginas más »
Disponible sólo en Clubensayos.com