Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- ekasinambela
- Date:
- 2016-06-16
- Revision:
- 0:29fc24ce612f
- Child:
- 1:8431b042a2eb
File content as of revision 0:29fc24ce612f:
#include "mbed.h" #include "DRV8825.h" #define MAX_SPEED 8000 #define MICROSTEPS_PER_STEP 32 // add boundaries //DigitalOut myled(LED1); int PULL = 1; int PUSH = 0; int SALT = 1; int PURE = 0; int PREVIOUS_DIRECTION_SALT = -1; int PREVIOUS_DIRECTION_PURE = -1; int POSITION_SALT = 14; int POSITION_PURE = 27; int MAX = 35; int MIN = 0; DRV8825 stpr_mtr(p21, p27, p28, p29, p22, p23); DRV8825 stpr_mtr2(p24, p27, p28, p29, p25, p26); void add_water(int type, int mililiters, int DIRECTION){ int MOVEMENT = 1800; //constant for 1 mL int STEP_EXTRA = 2500; //for the other mL's if (mililiters > 0){ if (type == SALT){ if (DIRECTION == PULL){ if (POSITION_SALT + mililiters >= MAX) mililiters = 0; else POSITION_SALT = POSITION_SALT + mililiters; }else{ if (POSITION_SALT - mililiters <= MIN) mililiters = 0; else POSITION_SALT = POSITION_SALT - mililiters; } }else { if (DIRECTION == PULL) if (POSITION_PURE + mililiters >= MAX) mililiters = 0; else POSITION_PURE = POSITION_PURE + mililiters; else if (POSITION_PURE - mililiters <= MIN) mililiters = 0; else POSITION_PURE = POSITION_PURE - mililiters; } //accelerate for (int i = 25; i < MAX_SPEED; i+=20) { if (type == SALT) stpr_mtr.settings(1/MICROSTEPS_PER_STEP, DIRECTION, i); else stpr_mtr2.settings(1/MICROSTEPS_PER_STEP, DIRECTION, i); } //fix the changing of directions for pure if (type == PURE){ mililiters = mililiters * 2.2; if (PREVIOUS_DIRECTION_PURE != DIRECTION) mililiters = mililiters + 1; } //fix the changing of directions for salt if (type == SALT){ mililiters = mililiters * 0.9; if (PREVIOUS_DIRECTION_PURE != DIRECTION) mililiters = mililiters + 1; //if (PREVIOUS_DIRECTION_SALT == PULL) //mililiters = mililiters + 0.5; } //move with constant speed for (int i = 1; i < (MOVEMENT + (mililiters - 1)*STEP_EXTRA); i+=1) { if (type == SALT) stpr_mtr.settings(1/MICROSTEPS_PER_STEP, DIRECTION, MAX_SPEED); else stpr_mtr2.settings(1/MICROSTEPS_PER_STEP, DIRECTION, MAX_SPEED); } //de-accelerate for (int i = MAX_SPEED; i > 0; i-=20) { if (type == SALT) stpr_mtr.settings(1/MICROSTEPS_PER_STEP, DIRECTION, i); else stpr_mtr2.settings(1/MICROSTEPS_PER_STEP, DIRECTION, i); } //remember previous direction if (type == SALT) PREVIOUS_DIRECTION_SALT = DIRECTION; else PREVIOUS_DIRECTION_PURE = DIRECTION; wait(2); } } int main() { //add_water(PURE, -1, PUSH); //add_water(SALT, -1, PUSH); add_water(SALT, 1, PULL); add_water(SALT, 1, PUSH); add_water(SALT, 2, PULL); add_water(SALT, 2, PUSH); add_water(SALT, 3, PULL); add_water(SALT, 3, PUSH); add_water(PURE, 1, PULL); add_water(PURE, 1, PUSH); add_water(PURE, 2, PULL); add_water(PURE, 2, PUSH); add_water(PURE, 3, PULL); add_water(PURE, 3, PUSH); }