final

Dependencies:   Servo1 mbed

Fork of ES200_Project2_1 by Project 2

Committer:
m211656
Date:
Thu Oct 25 00:36:27 2018 +0000
Revision:
3:48d837d59ae7
Parent:
2:c23c90a74ac6
Final code-everything should work fine

Who changed what in which revision?

UserRevisionLine numberNew contents of line
m211656 0:b6a454c0b00a 1 #include "mbed.h"
m211656 0:b6a454c0b00a 2 #include "Servo.h"
m211656 0:b6a454c0b00a 3 #include "Motor.h"
m211656 0:b6a454c0b00a 4
m211656 2:c23c90a74ac6 5 Servo clamp(p21);
m211656 2:c23c90a74ac6 6 Servo toppings(p22);
m211656 0:b6a454c0b00a 7 Motor m(p26,p30,p29);
m211656 1:852f86d263c8 8 DigitalIn sw1(p15), sw2(p16), sw3(p17), sw4(p18), sw5(p19);
m211656 3:48d837d59ae7 9 BusOut lights(p5,p6,p7,p8,p9);
m211656 0:b6a454c0b00a 10
m211656 0:b6a454c0b00a 11
m211656 0:b6a454c0b00a 12 int main()
m211656 0:b6a454c0b00a 13 {
m211656 2:c23c90a74ac6 14 clamp.calibrate(0.0009,90);
m211656 2:c23c90a74ac6 15 toppings.calibrate(0.0009, 90);
m211656 3:48d837d59ae7 16 toppings=1.0;
m211656 0:b6a454c0b00a 17 while(1)
m211656 0:b6a454c0b00a 18 {
m211656 1:852f86d263c8 19 wait(0.5);
m211656 2:c23c90a74ac6 20 if(sw5==1) { //clamp open, dc motor off
m211656 1:852f86d263c8 21 lights=31;
m211656 2:c23c90a74ac6 22 printf("light 5 is on\n\r");//Prof said to leave this in to prove our code works
m211656 2:c23c90a74ac6 23 m.speed(0.0);
m211656 3:48d837d59ae7 24 wait(0.02);
m211656 3:48d837d59ae7 25 clamp=0.5;
m211656 0:b6a454c0b00a 26 }
m211656 3:48d837d59ae7 27 else if(sw4==1) { //dc motor on
m211656 1:852f86d263c8 28 lights=15;
m211656 2:c23c90a74ac6 29 printf("light 4 is on\n\r");//Prof said to leave this is to prove our code works
m211656 3:48d837d59ae7 30 m.speed(0.5);
m211656 0:b6a454c0b00a 31 }
m211656 3:48d837d59ae7 32 else if(sw3==1) { //toppings return
m211656 0:b6a454c0b00a 33 lights=7;
m211656 3:48d837d59ae7 34 toppings=1.0;
m211656 0:b6a454c0b00a 35 }
m211656 3:48d837d59ae7 36 else if(sw2==1) { //toppings dump
m211656 1:852f86d263c8 37 lights=3;
m211656 3:48d837d59ae7 38 toppings=0.8;
m211656 3:48d837d59ae7 39
m211656 0:b6a454c0b00a 40 }
m211656 2:c23c90a74ac6 41 else if(sw1==1) { //clamp turns on
m211656 1:852f86d263c8 42 lights=1;
m211656 3:48d837d59ae7 43 clamp=0.12;
m211656 0:b6a454c0b00a 44 }
m211656 0:b6a454c0b00a 45 else {
m211656 2:c23c90a74ac6 46 lights=0; //no switches on = no lights, DC motor off
m211656 2:c23c90a74ac6 47 m.speed(0.0);
m211656 2:c23c90a74ac6 48 }
m211656 0:b6a454c0b00a 49
m211656 0:b6a454c0b00a 50 }
m211656 0:b6a454c0b00a 51 }