/* Lemon Squeezer machine V_4 */ //============ DC motor================================ int EN1=6; int EN2=7; int motor1=10; // motor triturador int motor2=11; // motor limon int PWM1; // motor triturador int PWM2; // motor limon //=================================================== int valorpoten1=200; int valorpoten2=190; //====================pistones=========== int piston_afuera=9; int piston_adentro=8; //======================================= const int InfraredSensorPin = 4; const int pinSensor1 = 2; //container const int pinSensor2 = 3; // botador //===================================================== const int buttonPin = 5; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin //====================================================== const int sensor_container=0; const int sensor_botador=0; //====================================================== // Variables will change: int ledState = HIGH; // the current state of the output pin int buttonState; // the current reading from the input pin int lastButtonState = LOW; // the previous reading from the input pin // the following variables are long's because the time, measured in miliseconds, // will quickly become a bigger number than can be stored in an int. long lastDebounceTime = 0; // the last time the output pin was toggled long debounceDelay = 50; // the debounce time; increase if the output flickers void setup() { //================================================ pinMode(buttonPin, INPUT); pinMode(ledPin, OUTPUT); // set initial LED state digitalWrite(ledPin, ledState); Serial.begin(57600); Serial.println("Start!"); //============================================== //BOTTON START pinMode(InfraredSensorPin,INPUT); pinMode(buttonPin, INPUT); pinMode(ledPin, OUTPUT); //================================ //EFECT SENSOR HALL pinMode(pinSensor1, INPUT_PULLUP); pinMode(pinSensor2, INPUT_PULLUP); //=============================================== //Motores pinMode(EN1, OUTPUT); pinMode(EN2, OUTPUT); pinMode(motor1, OUTPUT); pinMode(motor2, OUTPUT); //=============================================== // Pistones pinMode(piston_afuera, OUTPUT); pinMode(piston_adentro, OUTPUT); } void loop() { // read the state of the switch into a local variable: int reading = digitalRead(buttonPin); // check to see if you just pressed the button // (i.e. the input went from LOW to HIGH), and you've waited // long enough since the last press to ignore any noise: // If the switch changed, due to noise or pressing: if (reading != lastButtonState) { // reset the debouncing timer lastDebounceTime = millis(); } if ((millis() - lastDebounceTime) > debounceDelay) { // whatever the reading is at, it's been there for longer // than the debounce delay, so take it as the actual current state: // if the button state has changed: if (reading != buttonState) { buttonState = reading; // only toggle the LED if the new button state is HIGH if (buttonState == HIGH) { ledState = !ledState; } } } // set the LED: digitalWrite(ledPin, ledState); // save the reading. Next time through the loop, // it'll be the lastButtonState: lastButtonState = reading; //if ((ledState == HIGH) && (digitalRead(pinSensor1) == LOW) && ( digitalRead(pinSensor2) == LOW)) if ((ledState == HIGH) && (digitalRead(pinSensor1) == LOW) && ( digitalRead(pinSensor2) == LOW)) //if (( digitalRead(pinSensor1) == LOW ) ) { digitalWrite(ledPin, LOW); motor_on (); //pinton_inicio(); // pinton_trabajo(); if (digitalRead(InfraredSensorPin) == LOW) { piston_pasa(); } pinton_trabajo(); delay(500); } else { motor_off(); pinton_inicio(); delay(200); } } void motor_on() { digitalWrite(EN1, LOW); digitalWrite(EN2, LOW); PWM1= map(valorpoten1,0,1023,0,255); PWM2= map(valorpoten2,0,1023,0,255); analogWrite(motor1,PWM1); analogWrite(motor2,PWM2); delay(100); } void motor_off() { analogWrite(motor1,0); analogWrite(motor2,0); delay(100); } void piston_afuera1() { digitalWrite(piston_afuera, LOW); digitalWrite(piston_adentro, HIGH); delay(1000); delay(1000); } void piston_pasa() { digitalWrite(ledPin, HIGH); digitalWrite(piston_afuera, HIGH); digitalWrite(piston_adentro, LOW); delay(1000); delay(1000); } void pinton_trabajo() { digitalWrite(piston_afuera, LOW); //D4 digitalWrite(piston_adentro, HIGH); //D5 delay(1000); delay(1000); delay(1000); } void pinton_inicio() { digitalWrite(piston_afuera, LOW); digitalWrite(piston_adentro, LOW); delay(500); }