- greenlaser.jpg (61.85 KiB) Viewed 520 times
The lasers, steppers and MOM switches work great. The only stumbling point left is making the loop work that controls the fill valve. There are two electrodes that descend into the cup, and when the lemonade hits them, in theory, the contact is closed between fillSensor and ground, taking fillSensor ==LOW. This is supposed to stop the filling valve. I have tried using pull up or pull down resistors, and using both a 'while ' and 'do while' loop. The fill valve never opens. Is my ' do while' loop bad?
I know the valve works. The valve is open when fillRelay==LOW
Code: Select all
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
Adafruit_MotorShield AFMStop(0x60);// Default address- no jmpers.
Adafruit_MotorShield AFMSbot(0x61); // Rightmost jumper closed Adafruit_MotorShield AFMStop(0x60);
Adafruit_StepperMotor *myStepper1 = AFMStop.getStepper(200,1);
Adafruit_StepperMotor *myStepper2 = AFMStop.getStepper(200,2);
Adafruit_StepperMotor *myStepper3 = AFMSbot.getStepper(200,1);
Adafruit_StepperMotor *myStepper4 = AFMSbot.getStepper(200,2);
int greenLed = 1;
int redLed = 2;
int basicSwitch = 4;
int plainSwitch = 3;
int deluxeSwitch = 5;
int fillSensor = 6;
int fillRelay = 7;
int blueLaser = 8;
int greenLaser = 9;
int rightLight = 10;
int middleLight = 11;
int leftLight = 12;
int redLaser= 13;
int delayPeriod = 1000;
void setup ()
{
AFMSbot.begin(); // Start the bottom shield
AFMStop.begin(); // Start the top shield
Serial.begin(9600); //
myStepper1->setSpeed(30); //sensor speed
myStepper2->setSpeed(100); //conveyor speed
myStepper3->setSpeed(200); //laser horizontal
myStepper4->setSpeed(50); //laser vertical speed
Serial.begin(9600); // set up Serial library at 9600 bps Serial.println("Stepper test!");
pinMode(greenLed,OUTPUT); //green "OK" LED
pinMode(redLed,OUTPUT); //red "underway" LED
pinMode(basicSwitch,INPUT_PULLUP); //select basic lemonade
pinMode(plainSwitch,INPUT_PULLUP); //select the basic laser
pinMode(deluxeSwitch,INPUT_PULLUP); //select deluxe laser
pinMode(fillSensor,INPUT_PULLUP); // the fill sensor
pinMode(fillRelay,OUTPUT);//the valve filling the cup- relay #1
pinMode(blueLaser,OUTPUT);//the blue laser relay- relay #2
pinMode(greenLaser,OUTPUT);//the green laser- relay #3
pinMode(redLaser,OUTPUT);//the red laser- relay #4
pinMode(rightLight,OUTPUT); //the right switch light
pinMode(middleLight, OUTPUT);//the middle switch light
pinMode(leftLight,OUTPUT);//the left switch light
}
//relay #1 is fillRelay, relay #2 is greenLaser, relay #3 is blueLaser, relay# 4 is redLaser.
void loop()
{
bool plain = digitalRead(plainSwitch) == LOW; // the right switch for plain lemonade
bool basic = digitalRead(basicSwitch) == LOW; // the middle switch for basic laser treatment
bool deluxe = digitalRead(deluxeSwitch) == LOW; // the right switch for deluxe laser treatment
digitalWrite(greenLed,HIGH); //turns the green light on
digitalWrite(fillRelay,HIGH); //keeps the fill relay OFF
digitalWrite(blueLaser,HIGH); //keeps the blue laser relay OFF- this is LOW=ON relay
digitalWrite(greenLaser,HIGH); //keeps the green laser relay OFF-this is LOW=ON relay
digitalWrite(redLaser,HIGH); //keeps the red laser relay OFF-this is LOW=ON relay
digitalWrite(redLed ,LOW);//keeps red led low
if (plain) //This runs plain lemonade without laser treatment. What loser wants that? Lasers are the WAY.
{
digitalWrite(greenLed,LOW);// turns the green "ready" light off
digitalWrite(redLed,HIGH);// turns the red "underway" light on
digitalWrite(rightLight,HIGH); // turns on the right switchlight- this is the white adafruit MOM switch
myStepper2->step(2000, BACKWARD, DOUBLE);//move conveyor to the fill position
myStepper1->step(55, FORWARD, MICROSTEP);//put in the fill sensor
do
{
digitalWrite(fillRelay,LOW);// fillsensor using internal pull up
}
while (fillSensor == HIGH);
digitalWrite(fillRelay,HIGH);//closes the fill valve
myStepper1->step(55, BACKWARD, MICROSTEP);// moves the sensor out of the lemonade
delay(500);
myStepper2->step(2000 , FORWARD, DOUBLE);// moves drink back to the start
digitalWrite(greenLed,HIGH); //resets the ready green light
digitalWrite(redLed,LOW);// stops the red 'underway' light
digitalWrite(rightLight,LOW);// turns the right light off
}
else if ( basic) ...