Presentation code for PROJECT #1 - ES200 Fall 2014
Dependencies: Servo mbed Motor
main.cpp
- Committer:
- tsevcik08
- Date:
- 2014-11-03
- Revision:
- 9:8682923e9260
- Parent:
- 8:30eb49981a91
File content as of revision 9:8682923e9260:
//MIDN 3/C W. O'Brien, D. Thompson-Sevcik, C. Stabler //Candy scooper program for Project #1, ES200 Fall 2014 //Modifications: 9 OCT- Initial code #include "mbed.h" #include "Motor.h" #include "Servo.h" Motor kate(p26, p29, p30); Servo arm(p21); Servo scoop(p22); DigitalIn sw1(p16); //up DigitalIn sw2(p17); //down DigitalIn sw3(p18); //dump DigitalIn sw4(p19); DigitalIn sw5(p20); BusOut w(p5, p6, p7, p8, p11); //data bus for LEDs int main() { float armpos; float servopos; float mspeed; w = 16; while(1) { if( sw4 == 1 && sw5 == 0 && sw1 == 0 && sw2 == 0 ) {//while switch four is on mspeed = 0.40; kate.speed(mspeed); wait(.05);//structure move for .05 seconds mspeed = 0.0; kate.speed(mspeed); wait(.25);//structure stop for .25 seconds if(w < 1 || w > 16){ w=16; } w = w/2; //moves LED to the right by changing binary value } else if( sw5 == 1 && sw4 == 0 && sw1 == 0 && sw2 == 0) {//while switch five is on mspeed = -0.40; kate.speed(mspeed); wait(.05);//structure moves in reverse for .05 seconds mspeed = 0.0; kate.speed(mspeed); wait(.25);//structure stops moving for .25 seconds if(w < 1 || w > 16){ w=1; } w = w*2;//move LED to the left by changing the binary value } else if (sw3 == 1 && sw2 == 0 && sw1 == 0 && sw4 == 0 && sw5 == 0 ) {//while switch three is on for (servopos = 0; servopos <= 0.5; servopos += 0.5) {//closes the claw scoop = servopos; w = 8; // LED three is on } wait (1); } else if(sw1 == 1 && sw2 == 0 && sw5 == 0 && sw4 == 0 ) {//while switch one is on armpos += .02; arm = armpos;//arm position moves up by .02 wait(.05); w=31; wait(.05);//lights flicker between on and off w= 0; } else if(sw2 == 1 && sw1 == 0 && sw4 == 0 && sw5 == 0) {//while stich two is on armpos -= .08; arm = armpos;//arm position moves down by .08 wait(.05); w=3; wait(.25);//lights flicker between LED 1 and 2 on and LED 3, 4, and 5 on w=28; } else if (sw4 == 0 && sw1 == 0 && sw2 == 0 && sw3 == 0 && sw5 == 0) {//while all switches off mspeed = 0.0;// no movement of the structure kate.speed(mspeed); arm = armpos;// arm stays in the position wait(.1); for (servopos = 1.0; servopos >= 0; servopos -=1.0) { scoop = servopos;//claw opens up } } } }//end main