Arduino - INCREMENTO Y DECREMENTO LCD Y BOTONNES

 
Vista:
sin imagen de perfil

INCREMENTO Y DECREMENTO LCD Y BOTONNES

Publicado por adrian (1 intervención) el 17/10/2017 12:41:47
BUENO DIAS GENTE,, LES VENGO CON ESTE PROBLEMITA , PARA USTEDES SIMPLE PARA MI ME ROMPI LA CABEZA SOY PRINCIPIANTE AMO ARDUINO Y PROYECTOS PERO NO CUENTO CON DINERO PARA ESTUDIO PERO LE PONGO LA MEJOR PA45RA TRATAR DE HACER HOY ME ENCONTRE CON LAS GANAS DE REALIZAR UN PROYECTO PARA ME PAPA DE SU TRABAJO ES COMO UNA CORTADORA DE CABLES LA CUESTION ES QUE QUIERO ANEXARLE A ESTE PROGRAMITA CON SENSOR QUE CORTA EL CAMBLE FRENA EL MOTOR Y CUANDO LE PONGO 20 EN EL PROGRAMA SE FINALIZA PERO LO TENGO QUE HACER CON LA CONPUTADORA LE QUERIA AGREGAR 2 BOTONES PARA ENCREMENTAR LA CUENTA Y DECREMENTARN Y QUE DONDE PUSE EL IF PARA QUE AL LLEGAR A ESA CUENTA SE PARE,, DISCULPENME ME IGNORANCIA EXPLICO COMO PUEDO ESPERO SE ENTIENDAN MIL DISCULPAS ANEXO PROGRAMA



#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>

#include <Stepper.h>

/* Pines del Arduino al integrado */
int motorPin3 = 10;
int motorPin4 = 11;
int led = 0;
int leds = 13;
const int stepsPerRevolution = 48; // cambie este valor por el numero de pasos de su motor
const int pin = 5;
// inicializa la libreria 'stepper' en los pines 8 a 11
Stepper myStepper(stepsPerRevolution, 8,9,10,11);

//Programa: Contador com sensor indutivo e Arduino
//Autor: Arduino e Cia

#include <Wire.h>


LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
boolean estadoAnterior = LOW;
boolean estadoActual = LOW;

int pino_sensor = 7;
int valor = 1; //Variavel leitura sensor
int contador = 0;

void setup()
{
pinMode(leds, OUTPUT);
pinMode(7, INPUT);
pinMode(6, OUTPUT);
pinMode(pin, OUTPUT);
// establece la velocidad en 60rpm
myStepper.setSpeed(60);
// inicializa el puerto serial
Serial.begin(9600);


Serial.begin(9600);
//Define o pino do sensor como entrada
pinMode(pino_sensor, INPUT);
//Inicializa o display LCD 16x2 I2C
lcd.begin (16, 2);
//informacoes iniciais
lcd.setCursor(4, 1);
lcd.print("CONTADOR");
lcd.setCursor(1, 0);
lcd.print("CORTACABLES");
lcd.setCursor(14, 1);
lcd.print("0");
}
boolean rebote(boolean eAnterior)
{
boolean eActual = digitalRead(pino_sensor);
if (eAnterior != eActual)
{
delay(5);
eActual = digitalRead(pino_sensor);
}
return eActual;
}

void loop()
{

{

if(contador < 20){
digitalWrite(pin, HIGH);


}

else if( contador >= 20){
digitalWrite(pin,LOW);


}

led = digitalRead (7);
if(led == HIGH){
digitalWrite(6, LOW);
}
else {
digitalWrite(6, HIGH);
delay(2000);
}


digitalWrite(leds, HIGH);





// gira una vuelta en una direccion
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);

if ( contador < 20) {
estadoActual = rebote(estadoAnterior);
if (estadoAnterior == LOW && estadoActual == HIGH)
contador++;

{

//Mostra o valor do contador no display
lcd.setCursor(14, 1);
lcd.print(contador);
}
estadoAnterior = estadoActual;
if(contador > 20){
lcd.clear();
lcd.print("Num. de objetos");
contador =0;
}
}
}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder