Andy Pomfret
/
UoY-32C-lab6
Template project for University of York ELE00032C Lab 6
Diff: main.cpp
- Revision:
- 1:ec2d05bb8112
- Parent:
- 0:77209603a6fe
- Child:
- 2:3eacc92b984b
--- a/main.cpp Mon Jan 11 11:28:11 2021 +0000 +++ b/main.cpp Thu Feb 04 16:39:47 2021 +0000 @@ -1,15 +1,30 @@ #include "mbed.h" -int main() -{ - int x = 4; - x = 6; - int y; - y = 2*x; - x = 7; - - printf("x:%d y:%d\n", x, y); - - // Do nothing, forever... - while (true); +DigitalOut dir1(D2); +DigitalOut dir2(D3); +PwmOut pwm(D4); + +void motor(float speed) { + if (speed > 0) { + dir1 = true; + dir2 = false; + pwm = speed; + } else { + dir1 = false; + dir2 = true; + pwm = -speed; + } } + +int main() { + while (true) { + motor(1.0); + thread_sleep_for(1000); + motor(0.0); + thread_sleep_for(1000); + motor(-0.5); + thread_sleep_for(1000); + motor(0); + thread_sleep_for(1000); + } +}