limit

Dependencies:   Motor mbed

Committer:
danielgoodies
Date:
Sun Jun 11 19:20:35 2017 +0000
Revision:
0:fd1d9eb5ab5f
LImit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
danielgoodies 0:fd1d9eb5ab5f 1 #include "Motor.h"
danielgoodies 0:fd1d9eb5ab5f 2 #include "mbed.h"
danielgoodies 0:fd1d9eb5ab5f 3
danielgoodies 0:fd1d9eb5ab5f 4 DigitalIn limitAtasLifter(PB_3, PullUp); // Vertikal Atas: Lifter
danielgoodies 0:fd1d9eb5ab5f 5 DigitalIn limitAtasSaucer(PB_2, PullUp); // Vertikal Atas: Saucer
danielgoodies 0:fd1d9eb5ab5f 6 DigitalIn limitBawah(PB_10, PullUp); // Vertikal Bawah
danielgoodies 0:fd1d9eb5ab5f 7 DigitalIn limitKiri(PA_5, PullUp); // Horizontal Kiri
danielgoodies 0:fd1d9eb5ab5f 8 DigitalIn limitTengah(PC_9, PullUp);// Horizontal Tengah
danielgoodies 0:fd1d9eb5ab5f 9 DigitalIn limitKanan(PC_8, PullUp); // Horizontal Kanan (Frisbee keluar)
danielgoodies 0:fd1d9eb5ab5f 10
danielgoodies 0:fd1d9eb5ab5f 11 Motor powerScrew(PA_8, PC_1, PC_2); // pwm, fwd, rev
danielgoodies 0:fd1d9eb5ab5f 12 Motor pulley(PA_10, PC_3, PC_0);
danielgoodies 0:fd1d9eb5ab5f 13
danielgoodies 0:fd1d9eb5ab5f 14 int state = 0;
danielgoodies 0:fd1d9eb5ab5f 15 int up = 0;
danielgoodies 0:fd1d9eb5ab5f 16
danielgoodies 0:fd1d9eb5ab5f 17 int main()
danielgoodies 0:fd1d9eb5ab5f 18 {
danielgoodies 0:fd1d9eb5ab5f 19 float pwmPower = -1.0;
danielgoodies 0:fd1d9eb5ab5f 20 while(1) {
danielgoodies 0:fd1d9eb5ab5f 21 /* limit switch atas */
danielgoodies 0:fd1d9eb5ab5f 22 if ((!limitAtasLifter) && (up)){
danielgoodies 0:fd1d9eb5ab5f 23 if(state == 0){
danielgoodies 0:fd1d9eb5ab5f 24 state = 1;
danielgoodies 0:fd1d9eb5ab5f 25 }
danielgoodies 0:fd1d9eb5ab5f 26 up = 0;
danielgoodies 0:fd1d9eb5ab5f 27 pwmPower = -1.0;
danielgoodies 0:fd1d9eb5ab5f 28 }
danielgoodies 0:fd1d9eb5ab5f 29
danielgoodies 0:fd1d9eb5ab5f 30 /* limit switch bawah */
danielgoodies 0:fd1d9eb5ab5f 31 if (!limitBawah){
danielgoodies 0:fd1d9eb5ab5f 32 if(state == 0){
danielgoodies 0:fd1d9eb5ab5f 33 state = 1;
danielgoodies 0:fd1d9eb5ab5f 34 }
danielgoodies 0:fd1d9eb5ab5f 35 else if ((state == 1)||(up == 0)){
danielgoodies 0:fd1d9eb5ab5f 36 state = 0;
danielgoodies 0:fd1d9eb5ab5f 37 }
danielgoodies 0:fd1d9eb5ab5f 38
danielgoodies 0:fd1d9eb5ab5f 39 up = 1;
danielgoodies 0:fd1d9eb5ab5f 40 pwmPower = 1.0;
danielgoodies 0:fd1d9eb5ab5f 41 }
danielgoodies 0:fd1d9eb5ab5f 42
danielgoodies 0:fd1d9eb5ab5f 43 /* limit switch saucer */
danielgoodies 0:fd1d9eb5ab5f 44 if ((!limitAtasSaucer) && (up)){
danielgoodies 0:fd1d9eb5ab5f 45 state = 0;
danielgoodies 0:fd1d9eb5ab5f 46 pwmPower = 1.0;
danielgoodies 0:fd1d9eb5ab5f 47 }
danielgoodies 0:fd1d9eb5ab5f 48 /*
danielgoodies 0:fd1d9eb5ab5f 49 else if ((limitAtasSaucer) && (up))
danielgoodies 0:fd1d9eb5ab5f 50 {
danielgoodies 0:fd1d9eb5ab5f 51 state = 1;
danielgoodies 0:fd1d9eb5ab5f 52 pwmPower = 1.0;
danielgoodies 0:fd1d9eb5ab5f 53 }
danielgoodies 0:fd1d9eb5ab5f 54 */
danielgoodies 0:fd1d9eb5ab5f 55
danielgoodies 0:fd1d9eb5ab5f 56 /* motor */
danielgoodies 0:fd1d9eb5ab5f 57 if (state == 1){
danielgoodies 0:fd1d9eb5ab5f 58 powerScrew.speed(pwmPower);
danielgoodies 0:fd1d9eb5ab5f 59 }
danielgoodies 0:fd1d9eb5ab5f 60 else if (state == 0){
danielgoodies 0:fd1d9eb5ab5f 61 powerScrew.brake(1);
danielgoodies 0:fd1d9eb5ab5f 62 }
danielgoodies 0:fd1d9eb5ab5f 63 }
danielgoodies 0:fd1d9eb5ab5f 64 }