Samenwerking Groep 12
Dependencies: Encoder MODSERIAL HIDScope mbed
Foo
main.cpp@12:af428d56b4eb, 2015-09-21 (annotated)
- Committer:
- ThomasBNL
- Date:
- Mon Sep 21 13:59:59 2015 +0000
- Revision:
- 12:af428d56b4eb
- Parent:
- 10:e923f51f18c4
- Child:
- 13:a0113cf2fc5f
Werkend waarde tussen -4200 en 4200 voor de positie
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ThomasBNL | 10:e923f51f18c4 | 1 | #include "mbed.h" |
ThomasBNL | 10:e923f51f18c4 | 2 | #include "HIDScope.h" |
ThomasBNL | 10:e923f51f18c4 | 3 | #include "encoder.h" |
ThomasBNL | 10:e923f51f18c4 | 4 | #include "MODSERIAL.h" |
ThomasBNL | 10:e923f51f18c4 | 5 | |
ThomasBNL | 10:e923f51f18c4 | 6 | //Motor 2 |
ThomasBNL | 10:e923f51f18c4 | 7 | DigitalOut motor2direction(D4); //D4 en D5 zijn motor 2 (op het motorshield) |
ThomasBNL | 10:e923f51f18c4 | 8 | PwmOut motor2speed(D5); |
ThomasBNL | 10:e923f51f18c4 | 9 | DigitalIn button(PTA4); |
ThomasBNL | 10:e923f51f18c4 | 10 | Encoder motor2(D13,D12); |
ThomasBNL | 10:e923f51f18c4 | 11 | MODSERIAL pc(USBTX,USBRX); |
ThomasBNL | 10:e923f51f18c4 | 12 | //AnalogIn potmeter2(A0); /NIEUW |
ThomasBNL | 10:e923f51f18c4 | 13 | int main() |
ThomasBNL | 10:e923f51f18c4 | 14 | { |
ThomasBNL | 10:e923f51f18c4 | 15 | pc.baud(9600); |
ThomasBNL | 10:e923f51f18c4 | 16 | motor2.setPosition(0); |
ThomasBNL | 10:e923f51f18c4 | 17 | while(true) { |
ThomasBNL | 10:e923f51f18c4 | 18 | if (button.read() < 0.5) { //if button pressed |
ThomasBNL | 12:af428d56b4eb | 19 | motor2direction = 0; |
ThomasBNL | 10:e923f51f18c4 | 20 | motor2speed = 0.5f; |
ThomasBNL | 10:e923f51f18c4 | 21 | pc.printf("positie = %d \r\n", motor2.getPosition()); |
ThomasBNL | 10:e923f51f18c4 | 22 | } else { // If button is not pressed |
ThomasBNL | 10:e923f51f18c4 | 23 | motor2direction = 0; |
ThomasBNL | 10:e923f51f18c4 | 24 | motor2speed = 0; |
ThomasBNL | 10:e923f51f18c4 | 25 | pc.printf("positie = %d \r\n", motor2.getPosition()); |
ThomasBNL | 10:e923f51f18c4 | 26 | } |
ThomasBNL | 12:af428d56b4eb | 27 | |
ThomasBNL | 12:af428d56b4eb | 28 | while ((motor2.getPosition()>4200) || (motor2.getPosition()<-4200)) // If value is outside -4200 and 4200 (number of counts equal to one revolution) reset to zero |
ThomasBNL | 12:af428d56b4eb | 29 | { |
ThomasBNL | 10:e923f51f18c4 | 30 | motor2.setPosition(0); |
ThomasBNL | 12:af428d56b4eb | 31 | pc.printf("HE \r\n LLO \r\n WO \r\n RLD \r\n !!! \r\n FOO! \r\n"); |
ThomasBNL | 10:e923f51f18c4 | 32 | break; |
ThomasBNL | 12:af428d56b4eb | 33 | } |
ThomasBNL | 10:e923f51f18c4 | 34 | } |
ThomasBNL | 12:af428d56b4eb | 35 | } |