Fa2018-es200-3321-project2-goatpong
/
motors
motor code works
motor.cpp@0:64c745fbdf05, 2018-10-19 (annotated)
- Committer:
- m215910
- Date:
- Fri Oct 19 14:37:17 2018 +0000
- Revision:
- 0:64c745fbdf05
motor code works
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
m215910 | 0:64c745fbdf05 | 1 | //Test Motor |
m215910 | 0:64c745fbdf05 | 2 | |
m215910 | 0:64c745fbdf05 | 3 | //Libraries and mechanical directives |
m215910 | 0:64c745fbdf05 | 4 | #include "Motor.h" //must change line 31 in Motor.cpp according to Lab |
m215910 | 0:64c745fbdf05 | 5 | #include "mbed.h" |
m215910 | 0:64c745fbdf05 | 6 | //#include "Servo.h" //need Servo library |
m215910 | 0:64c745fbdf05 | 7 | |
m215910 | 0:64c745fbdf05 | 8 | Motor m(p26, p30, p29); //designates the pins used by the motor |
m215910 | 0:64c745fbdf05 | 9 | DigitalIn sw1(p16); //switches or buttons |
m215910 | 0:64c745fbdf05 | 10 | int sw1state, bu1state, bu2state, bu3state, bu4state, bu5state; //the state of the switch |
m215910 | 0:64c745fbdf05 | 11 | int s=0.6; //speed of motor rotation - fairly slow so as to be exact |
m215910 | 0:64c745fbdf05 | 12 | |
m215910 | 0:64c745fbdf05 | 13 | int main() { |
m215910 | 0:64c745fbdf05 | 14 | while(1) { //do we need while? |
m215910 | 0:64c745fbdf05 | 15 | sw1state=sw1.read(); //read in switch state |
m215910 | 0:64c745fbdf05 | 16 | |
m215910 | 0:64c745fbdf05 | 17 | if (sw1state == 1) { //if bu4 is on rotate motor fwd |
m215910 | 0:64c745fbdf05 | 18 | m.speed(-s); |
m215910 | 0:64c745fbdf05 | 19 | s=1; |
m215910 | 0:64c745fbdf05 | 20 | printf("hi");} |
m215910 | 0:64c745fbdf05 | 21 | else { //if bu5 is on rotate motor rev |
m215910 | 0:64c745fbdf05 | 22 | m.speed(s); |
m215910 | 0:64c745fbdf05 | 23 | s=0;} |
m215910 | 0:64c745fbdf05 | 24 | } |
m215910 | 0:64c745fbdf05 | 25 | } |