Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Stepper.h>
- // A 200-step motor connected on pins 2-5
- Stepper stepper(200,3,4,5,6);
- const int buttonPin = 2;
- const int limitBottom = 8;
- const int limitTop = 7;
- const int LED1 = 11; // ready
- const int LED2 = 12; //brewing
- const int readyButton = 13;
- const int touchSensor = 10;
- const int limitSwitchActivated = HIGH;
- //variable
- volatile int buttonState = 0;
- //variables to keep track of the timing of recent interrupts
- unsigned long button_time = 0;
- unsigned long last_button_time = 0;
- void setup()
- {
- pinMode(limitBottom, INPUT);
- pinMode(limitTop, INPUT);
- pinMode(LED1, OUTPUT); //ignore for now
- pinMode(LED2, OUTPUT); // ignore for now
- pinMode(buttonPin, INPUT);
- pinMode(readyButton, INPUT);
- // Attach an interrupt to the ISR vector
- attachInterrupt(digitalPinToInterrupt(2),pin_ISR,RISING);
- stepper.setSpeed(60);
- }
- void loop() {
- /* ******* STEP 1 *******
- * on start check bottom limit, reach it if not active */
- while (digitalRead(limitBottom) != limitSwitchActivated) {
- stepper.step(-1); //check if bottom limit is hit
- //if not, lower until it's hit.
- }
- delay(50);
- /* ******* STEP 2 *******
- * check ready button after bottom limit is active.
- * if touch detected, Step CW until top limit
- * activated
- */
- while ((digitalRead(readyButton) == LOW)) {
- //do nothing while no touch detected
- }
- while(digitalRead(limitTop) != limitSwitchActivated) {
- stepper.step(1);
- }
- delay(5000);
- }
- /* ******* STEP 3 *******
- * Return to bottom position
- * Searching for either the top limit switch to be active
- * or interrupt program via button.
- */
- // Interrupt service routine for interrupt 0
- void pin_ISR() {
- button_time = millis();
- if (button_time - last_button_time > 250) {
- //check to see if increment() was called in the last 250 milliseconds
- // this is to avoid the button sensing more than one push accidentally, in case it screws with the code
- (digitalRead(limitBottom) != limitSwitchActivated);
- stepper.step(-1);
- }
- else {
- //nada
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement