sunday code for project. needs slight revision.

Dependencies:   Motor Servo22oct mbed

Committer:
alphasig
Date:
Thu Oct 23 17:49:36 2014 +0000
Revision:
5:a7c0a09a7c58
Parent:
4:4b093f9bd41c
project day changes, upped motspeed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
alphasig 5:a7c0a09a7c58 1 //Project X
alphasig 5:a7c0a09a7c58 2 // Jordan Kangwijaya, Gabe Collins, Kyle Schaff
alphasig 5:a7c0a09a7c58 3
KyleSchaff 0:db9e971c8ba6 4 #include "mbed.h"
KyleSchaff 0:db9e971c8ba6 5 #include "Servo.h"
KyleSchaff 0:db9e971c8ba6 6 #include "Motor.h"
KyleSchaff 0:db9e971c8ba6 7
jkangwi 3:b81a3d326aee 8 BusIn Switch(p16,p17,p18,p19);
KyleSchaff 0:db9e971c8ba6 9 BusOut LED(p5,p6,p7,p8,p11);
KyleSchaff 0:db9e971c8ba6 10
KyleSchaff 2:c95e4e33eaee 11 Motor m(p26,p29,p30);
jkangwi 3:b81a3d326aee 12 Servo servo1(p21); //top .39 to 1.02
jkangwi 3:b81a3d326aee 13 Servo servo2(p22); //bottom .38 to .93
KyleSchaff 0:db9e971c8ba6 14
KyleSchaff 2:c95e4e33eaee 15 float servopos;
alphasig 5:a7c0a09a7c58 16 float motorspeed=.35;
KyleSchaff 0:db9e971c8ba6 17 int counter=0;
KyleSchaff 0:db9e971c8ba6 18 int counter1=0;
KyleSchaff 0:db9e971c8ba6 19
KyleSchaff 0:db9e971c8ba6 20 int main()
KyleSchaff 0:db9e971c8ba6 21 {
jkangwi 3:b81a3d326aee 22 while(1) {
jkangwi 3:b81a3d326aee 23
jkangwi 3:b81a3d326aee 24
jkangwi 3:b81a3d326aee 25 while (Switch==1) {
jkangwi 3:b81a3d326aee 26
jkangwi 3:b81a3d326aee 27
alphasig 4:4b093f9bd41c 28 for(servopos=.40; servopos<=.60; servopos+=.03) {
alphasig 4:4b093f9bd41c 29 servo1=.7;
KyleSchaff 0:db9e971c8ba6 30 servo2=servopos;
alphasig 4:4b093f9bd41c 31 motorspeed=0;
alphasig 4:4b093f9bd41c 32 m.speed(motorspeed);
KyleSchaff 0:db9e971c8ba6 33 counter=counter+1;
KyleSchaff 0:db9e971c8ba6 34 counter1=counter%20;
KyleSchaff 0:db9e971c8ba6 35 if (counter1==17) {
KyleSchaff 0:db9e971c8ba6 36 LED=rand()%129;
KyleSchaff 0:db9e971c8ba6 37 }
jkangwi 3:b81a3d326aee 38 wait (.1);
KyleSchaff 0:db9e971c8ba6 39 }
alphasig 4:4b093f9bd41c 40 for(servopos=.60; servopos>=.40; servopos-=.03) {
alphasig 4:4b093f9bd41c 41 servo1=.7;
KyleSchaff 1:33ef833aae0b 42 servo2=servopos;
alphasig 4:4b093f9bd41c 43 motorspeed=0;
alphasig 4:4b093f9bd41c 44 m.speed(motorspeed);
KyleSchaff 1:33ef833aae0b 45 counter=counter+1;
KyleSchaff 1:33ef833aae0b 46 counter1=counter%20;
KyleSchaff 1:33ef833aae0b 47 if (counter1==17) {
KyleSchaff 1:33ef833aae0b 48 LED=rand()%129;
KyleSchaff 1:33ef833aae0b 49 }
jkangwi 3:b81a3d326aee 50 wait (.1);
KyleSchaff 1:33ef833aae0b 51 }
alphasig 4:4b093f9bd41c 52 }//Swartzwelder swartzwe.usna.edu
jkangwi 3:b81a3d326aee 53 while(Switch==2) {
jkangwi 3:b81a3d326aee 54
jkangwi 3:b81a3d326aee 55
alphasig 4:4b093f9bd41c 56 for(servopos=.40; servopos<=.60; servopos+=.03) {
alphasig 4:4b093f9bd41c 57 servo1=servopos+.2;
alphasig 4:4b093f9bd41c 58 servo2=.5;
alphasig 4:4b093f9bd41c 59 motorspeed=0;
alphasig 4:4b093f9bd41c 60 m.speed(motorspeed);
KyleSchaff 0:db9e971c8ba6 61 counter=counter+1;
KyleSchaff 0:db9e971c8ba6 62 counter1=counter%20;
KyleSchaff 0:db9e971c8ba6 63 if (counter1==17) {
KyleSchaff 0:db9e971c8ba6 64 LED=rand()%129;
KyleSchaff 0:db9e971c8ba6 65 }
jkangwi 3:b81a3d326aee 66 wait (.03);
KyleSchaff 0:db9e971c8ba6 67 }
alphasig 4:4b093f9bd41c 68 for(servopos=.60; servopos>=.40; servopos-=.03) {
alphasig 4:4b093f9bd41c 69 servo1=servopos+.2;
alphasig 4:4b093f9bd41c 70 servo2=.5;
alphasig 4:4b093f9bd41c 71 motorspeed=0;
alphasig 4:4b093f9bd41c 72 m.speed(motorspeed);
KyleSchaff 1:33ef833aae0b 73 counter=counter+1;
KyleSchaff 1:33ef833aae0b 74 counter1=counter%20;
KyleSchaff 1:33ef833aae0b 75 if (counter1==17) {
KyleSchaff 1:33ef833aae0b 76 LED=rand()%129;
KyleSchaff 1:33ef833aae0b 77 }
jkangwi 3:b81a3d326aee 78 wait (.03);
KyleSchaff 1:33ef833aae0b 79 }
KyleSchaff 0:db9e971c8ba6 80 }
jkangwi 3:b81a3d326aee 81 while(Switch==4) {
jkangwi 3:b81a3d326aee 82
alphasig 4:4b093f9bd41c 83 for(servopos=.40; servopos<=.60; servopos+=.03) {
alphasig 4:4b093f9bd41c 84 servo1=servopos+.2;
alphasig 4:4b093f9bd41c 85 servo2=servopos;
alphasig 4:4b093f9bd41c 86 counter=counter+1;
alphasig 4:4b093f9bd41c 87 counter1=counter%20;
alphasig 4:4b093f9bd41c 88 if (counter1==17) {
alphasig 4:4b093f9bd41c 89 LED=rand()%129;
alphasig 4:4b093f9bd41c 90 }
alphasig 4:4b093f9bd41c 91 wait (.02);
alphasig 4:4b093f9bd41c 92 }
alphasig 4:4b093f9bd41c 93 for(servopos=.60; servopos>=.40; servopos-=.03) {
alphasig 4:4b093f9bd41c 94 servo1=servopos+.2;
alphasig 4:4b093f9bd41c 95 servo2=servopos;
alphasig 4:4b093f9bd41c 96 counter=counter+1;
alphasig 4:4b093f9bd41c 97 counter1=counter%20;
alphasig 4:4b093f9bd41c 98 if (counter1==17) {
alphasig 4:4b093f9bd41c 99 LED=rand()%129;
alphasig 4:4b093f9bd41c 100 }
alphasig 4:4b093f9bd41c 101 wait (.02);
alphasig 4:4b093f9bd41c 102 }
alphasig 4:4b093f9bd41c 103 }
jkangwi 3:b81a3d326aee 104
alphasig 4:4b093f9bd41c 105 while(Switch==8) {
alphasig 5:a7c0a09a7c58 106 motorspeed=.35;
alphasig 4:4b093f9bd41c 107 m.speed(motorspeed);
alphasig 4:4b093f9bd41c 108 for(servopos=.40; servopos<=.60; servopos+=.03) {
alphasig 4:4b093f9bd41c 109 servo1=servopos+.2;
KyleSchaff 0:db9e971c8ba6 110 servo2=servopos;
alphasig 4:4b093f9bd41c 111 m.speed(motorspeed);
KyleSchaff 0:db9e971c8ba6 112 counter=counter+1;
KyleSchaff 0:db9e971c8ba6 113 counter1=counter%20;
KyleSchaff 0:db9e971c8ba6 114 if (counter1==17) {
KyleSchaff 0:db9e971c8ba6 115 LED=rand()%129;
KyleSchaff 0:db9e971c8ba6 116 }
jkangwi 3:b81a3d326aee 117 wait (.025);
KyleSchaff 0:db9e971c8ba6 118 }
alphasig 4:4b093f9bd41c 119 for(servopos=.60; servopos>=.40; servopos-=.03) {
alphasig 4:4b093f9bd41c 120 servo1=servopos+.2;
KyleSchaff 1:33ef833aae0b 121 servo2=servopos;
alphasig 4:4b093f9bd41c 122 m.speed(motorspeed);
KyleSchaff 1:33ef833aae0b 123 counter=counter+1;
KyleSchaff 1:33ef833aae0b 124 counter1=counter%20;
KyleSchaff 1:33ef833aae0b 125 if (counter1==17) {
KyleSchaff 1:33ef833aae0b 126 LED=rand()%129;
KyleSchaff 1:33ef833aae0b 127 }
jkangwi 3:b81a3d326aee 128 wait (.025);
KyleSchaff 1:33ef833aae0b 129 }
KyleSchaff 0:db9e971c8ba6 130 }
alphasig 4:4b093f9bd41c 131
alphasig 4:4b093f9bd41c 132 while(Switch==0) {
alphasig 4:4b093f9bd41c 133 servo1=.7;
alphasig 4:4b093f9bd41c 134 servo2=.5;
alphasig 4:4b093f9bd41c 135 motorspeed=0;
KyleSchaff 2:c95e4e33eaee 136 m.speed(motorspeed);
KyleSchaff 0:db9e971c8ba6 137 }
KyleSchaff 0:db9e971c8ba6 138 }
KyleSchaff 0:db9e971c8ba6 139 }