do work
Dependencies: Motor Servo mbed
main.cpp
- Committer:
- JigglyPuff
- Date:
- 2014-10-03
- Revision:
- 1:040e30c39bee
- Parent:
- 0:41003e98eed8
File content as of revision 1:040e30c39bee:
// Dylan and Kate *We need to put more here* #include "mbed.h" #include "Motor.h" // Connect to the DC motor #include "Servo.h" // Connect to the Servo motors Motor kate(p26, p29, p30); // Establishing the pins for all of the motors. Servo dylan1(p21); Servo dylan2(p22); int main() { float servopos; // Establish variables for speeds and positions float mspeed; float nspeed; mspeed= 0.2; // Initialize the forward speed of the DC motor nspeed= -0.2; // Initialize the backward speed of the DC motor while (1) { for (servopos = 0; servopos <= 1.0; servopos += 0.02) { // if the servo is moving "forward" dylan1 = servopos; // Servo 1 is spinning clockwise dylan2 = 1.0 - servopos; // Servo 2 is spinning counterclockwise mspeed = mspeed; // establishes the speed at which the DC motor will spin forward kate.speed(mspeed); // makes the DC motor spin at mspeed wait(0.1); } for (servopos = 1.0; servopos >= 0; servopos -= 0.02) { // if the servo is moving "backward" dylan1 = servopos; // Servo 1 is spinning counterclockwise dylan2 = 1.0 - servopos; // Servo 2 is spinning clockwise nspeed = nspeed;// establishes the speed at which the DC motor will spin back kate.speed(nspeed); // makes the DC motor spin at nspeed wait(0.1); } mspeed = mspeed + 0.1; // increases the speed of the DC motor forward nspeed = nspeed - 0.1; // increases the speed of the DC motor back } }