Project 2
/
ES200_Project2_final
final
Fork of ES200_Project2_1 by
main.cpp@2:c23c90a74ac6, 2018-10-23 (annotated)
- Committer:
- m211656
- Date:
- Tue Oct 23 23:12:44 2018 +0000
- Revision:
- 2:c23c90a74ac6
- Parent:
- 1:852f86d263c8
- Child:
- 3:48d837d59ae7
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:852f86d263c8 | 9 | BusOut lights(p5,p6,p7,p10,p11); |
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 | 0:b6a454c0b00a | 16 | while(1) |
m211656 | 0:b6a454c0b00a | 17 | { |
m211656 | 1:852f86d263c8 | 18 | wait(0.5); |
m211656 | 2:c23c90a74ac6 | 19 | if(sw5==1) { //clamp open, dc motor off |
m211656 | 1:852f86d263c8 | 20 | lights=31; |
m211656 | 2:c23c90a74ac6 | 21 | printf("light 5 is on\n\r");//Prof said to leave this in to prove our code works |
m211656 | 2:c23c90a74ac6 | 22 | clamp=0.0; |
m211656 | 2:c23c90a74ac6 | 23 | m.speed(0.0); |
m211656 | 0:b6a454c0b00a | 24 | } |
m211656 | 2:c23c90a74ac6 | 25 | else if(sw4==1) { //dc motor off and reset toppings |
m211656 | 1:852f86d263c8 | 26 | lights=15; |
m211656 | 2:c23c90a74ac6 | 27 | printf("light 4 is on\n\r");//Prof said to leave this is to prove our code works |
m211656 | 1:852f86d263c8 | 28 | m.speed(0.0); |
m211656 | 2:c23c90a74ac6 | 29 | toppings=0.0; |
m211656 | 0:b6a454c0b00a | 30 | } |
m211656 | 2:c23c90a74ac6 | 31 | else if(sw3==1) { //toppings dump |
m211656 | 0:b6a454c0b00a | 32 | lights=7; |
m211656 | 2:c23c90a74ac6 | 33 | toppings=0.5; |
m211656 | 0:b6a454c0b00a | 34 | } |
m211656 | 1:852f86d263c8 | 35 | else if(sw2==1) { //dc motor on |
m211656 | 1:852f86d263c8 | 36 | lights=3; |
m211656 | 1:852f86d263c8 | 37 | m.speed(1.0); |
m211656 | 0:b6a454c0b00a | 38 | } |
m211656 | 2:c23c90a74ac6 | 39 | else if(sw1==1) { //clamp turns on |
m211656 | 1:852f86d263c8 | 40 | lights=1; |
m211656 | 0:b6a454c0b00a | 41 | } |
m211656 | 0:b6a454c0b00a | 42 | else { |
m211656 | 2:c23c90a74ac6 | 43 | lights=0; //no switches on = no lights, DC motor off |
m211656 | 2:c23c90a74ac6 | 44 | m.speed(0.0); |
m211656 | 2:c23c90a74ac6 | 45 | } |
m211656 | 0:b6a454c0b00a | 46 | |
m211656 | 0:b6a454c0b00a | 47 | } |
m211656 | 0:b6a454c0b00a | 48 | } |