Werkend motorscript met led feedback
Dependencies: Encoder MODSERIAL mbed
main.cpp@2:2b8a8be38c85, 2015-09-21 (annotated)
- Committer:
- Rvs94
- Date:
- Mon Sep 21 11:14:12 2015 +0000
- Revision:
- 2:2b8a8be38c85
- Parent:
- 1:4e65a72b622e
- Child:
- 3:051c91b04acd
Werkend motorscript
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rvs94 | 0:c8684fed9b61 | 1 | #include "mbed.h" |
Rvs94 | 0:c8684fed9b61 | 2 | #include "encoder.h" |
Rvs94 | 0:c8684fed9b61 | 3 | #include "MODSERIAL.h" |
Rvs94 | 0:c8684fed9b61 | 4 | |
Rvs94 | 0:c8684fed9b61 | 5 | Serial pc(USBTX, USBRX); // tx, rx |
Rvs94 | 2:2b8a8be38c85 | 6 | DigitalOut led1(LED_RED); |
Rvs94 | 2:2b8a8be38c85 | 7 | DigitalOut led2(LED_BLUE); |
Rvs94 | 0:c8684fed9b61 | 8 | DigitalOut motor2direction(D4); //D4 en D5 zijn motor 2 (op het motorshield) |
Rvs94 | 0:c8684fed9b61 | 9 | PwmOut motor2speed(D5); |
Rvs94 | 0:c8684fed9b61 | 10 | DigitalIn button1(SW3); |
Rvs94 | 2:2b8a8be38c85 | 11 | DigitalIn button2(SW2); |
Rvs94 | 2:2b8a8be38c85 | 12 | |
Rvs94 | 2:2b8a8be38c85 | 13 | const int ledOff = 1; |
Rvs94 | 2:2b8a8be38c85 | 14 | const int ledOn = 0; |
Rvs94 | 0:c8684fed9b61 | 15 | |
Rvs94 | 0:c8684fed9b61 | 16 | int main() |
Rvs94 | 0:c8684fed9b61 | 17 | { |
Rvs94 | 2:2b8a8be38c85 | 18 | motor2direction = 1; |
Rvs94 | 0:c8684fed9b61 | 19 | motor2speed = 0; |
Rvs94 | 2:2b8a8be38c85 | 20 | led1 = ledOff; |
Rvs94 | 2:2b8a8be38c85 | 21 | led2 = ledOff; |
Rvs94 | 0:c8684fed9b61 | 22 | pc.baud(9600); |
Rvs94 | 0:c8684fed9b61 | 23 | while(true) |
Rvs94 | 0:c8684fed9b61 | 24 | { |
Rvs94 | 2:2b8a8be38c85 | 25 | for(button1 == 0); |
Rvs94 | 0:c8684fed9b61 | 26 | { |
Rvs94 | 0:c8684fed9b61 | 27 | motor2speed = 0.5f; |
Rvs94 | 0:c8684fed9b61 | 28 | pc.printf("het werkt"); |
Rvs94 | 1:4e65a72b622e | 29 | wait(1); |
Rvs94 | 2:2b8a8be38c85 | 30 | led1 = ledOn; |
Rvs94 | 1:4e65a72b622e | 31 | wait(0.2f); |
Rvs94 | 1:4e65a72b622e | 32 | motor2speed = 0; |
Rvs94 | 2:2b8a8be38c85 | 33 | led1 = ledOff; |
Rvs94 | 0:c8684fed9b61 | 34 | } |
Rvs94 | 2:2b8a8be38c85 | 35 | for(button2 == 0); |
Rvs94 | 2:2b8a8be38c85 | 36 | { |
Rvs94 | 2:2b8a8be38c85 | 37 | motor2speed = 1; |
Rvs94 | 2:2b8a8be38c85 | 38 | led2 = ledOn; |
Rvs94 | 2:2b8a8be38c85 | 39 | wait(0.5f); |
Rvs94 | 2:2b8a8be38c85 | 40 | led2 = ledOff; |
Rvs94 | 2:2b8a8be38c85 | 41 | } |
Rvs94 | 2:2b8a8be38c85 | 42 | |
Rvs94 | 0:c8684fed9b61 | 43 | } |
Rvs94 | 0:c8684fed9b61 | 44 | } |