Script om de servomotor uit te proberen
main.cpp@0:ebffc70ade24, 2016-10-20 (annotated)
- Committer:
- lisa96m
- Date:
- Thu Oct 20 07:31:33 2016 +0000
- Revision:
- 0:ebffc70ade24
- Child:
- 1:acd79b94fe6a
Servomotor start script
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lisa96m | 0:ebffc70ade24 | 1 | #include "mbed.h" |
lisa96m | 0:ebffc70ade24 | 2 | |
lisa96m | 0:ebffc70ade24 | 3 | #define SERIAL_BAUD 115200 |
lisa96m | 0:ebffc70ade24 | 4 | |
lisa96m | 0:ebffc70ade24 | 5 | Serial pc(USBTX, USBRX); |
lisa96m | 0:ebffc70ade24 | 6 | |
lisa96m | 0:ebffc70ade24 | 7 | PwmOut servo(A4); |
lisa96m | 0:ebffc70ade24 | 8 | double x = 0; |
lisa96m | 0:ebffc70ade24 | 9 | float pi = 3.14; |
lisa96m | 0:ebffc70ade24 | 10 | |
lisa96m | 0:ebffc70ade24 | 11 | |
lisa96m | 0:ebffc70ade24 | 12 | void loop() |
lisa96m | 0:ebffc70ade24 | 13 | { |
lisa96m | 0:ebffc70ade24 | 14 | double y = sin(x); |
lisa96m | 0:ebffc70ade24 | 15 | { |
lisa96m | 0:ebffc70ade24 | 16 | x++; |
lisa96m | 0:ebffc70ade24 | 17 | } |
lisa96m | 0:ebffc70ade24 | 18 | servo = abs(y); |
lisa96m | 0:ebffc70ade24 | 19 | pc.printf("grootte van sinus is %f.\r\n", abs(y)); |
lisa96m | 0:ebffc70ade24 | 20 | } |
lisa96m | 0:ebffc70ade24 | 21 | |
lisa96m | 0:ebffc70ade24 | 22 | int main() |
lisa96m | 0:ebffc70ade24 | 23 | { |
lisa96m | 0:ebffc70ade24 | 24 | pc.baud(SERIAL_BAUD); |
lisa96m | 0:ebffc70ade24 | 25 | while(true) { |
lisa96m | 0:ebffc70ade24 | 26 | loop(); |
lisa96m | 0:ebffc70ade24 | 27 | wait(10); |
lisa96m | 0:ebffc70ade24 | 28 | } |
lisa96m | 0:ebffc70ade24 | 29 | } |