coding for the sub
Dependencies: mbed Motor Servo
main.cpp
- Committer:
- ewingswim
- Date:
- 2018-10-16
- Revision:
- 7:2a445f634f19
- Parent:
- 5:9825fb56de59
- Child:
- 8:ef878ee3f536
File content as of revision 7:2a445f634f19:
#include "mbed.h" #include "stdio.h" #include "stdlib.h" #include "Motor.h" #include "Servo.h" /* this is the code for the sub */ DigitalIn sw(p20); Motor m(p26,p30,p29); int main(){ while(1){ sw.read(); if (sw==1) { printf("motor on"); m.speed(0.5); } else{ printf("motor off"); m.speed(0.0); } wait(0.1); } } DigitalIn sw2(p19); Servo t(p22); float pos = 0.0; int main(){ t.calibrate(0.0009, 90.0); t = pos; while(1){ sw2.read(); if (sw2.read()==1) { printf("servo on"); for(int x=0; x<50; x++) { t=x/100.0; wait(0.10); } for(int x=50;x>0;x--){ t = x/100.0; wait(0.10); } } else{ printf("servo off"); } wait(0.1); } }