Georg Jonak
/
_B16_lLichtsensor
zum Lieniennachfahren
Fork of BertlLichtsensor by
main.cpp@0:5a3252c331b4, 2016-06-06 (annotated)
- Committer:
- georgjonak
- Date:
- Mon Jun 06 11:35:37 2016 +0000
- Revision:
- 0:5a3252c331b4
Lichtsensor zum Liniennachfahren;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
georgjonak | 0:5a3252c331b4 | 1 | #include "mbed.h" |
georgjonak | 0:5a3252c331b4 | 2 | |
georgjonak | 0:5a3252c331b4 | 3 | DigitalOut Von (P2_13); // 12 V ON |
georgjonak | 0:5a3252c331b4 | 4 | DigitalOut LineON (P2_5); // Line Sensor aktivieren |
georgjonak | 0:5a3252c331b4 | 5 | DigitalIn ISO1 (P1_9); // ISO1 |
georgjonak | 0:5a3252c331b4 | 6 | DigitalIn ISO2 (P0_16); |
georgjonak | 0:5a3252c331b4 | 7 | DigitalIn ISO3 (P0_23); |
georgjonak | 0:5a3252c331b4 | 8 | DigitalIn ISO4 (P0_15); |
georgjonak | 0:5a3252c331b4 | 9 | DigitalIn ISO5 (P1_3); |
georgjonak | 0:5a3252c331b4 | 10 | |
georgjonak | 0:5a3252c331b4 | 11 | DigitalOut LedD1 (P1_10); |
georgjonak | 0:5a3252c331b4 | 12 | DigitalOut LedD2 (P1_11); |
georgjonak | 0:5a3252c331b4 | 13 | DigitalOut LedD4 (P1_12); |
georgjonak | 0:5a3252c331b4 | 14 | DigitalOut LedD5 (P1_13); |
georgjonak | 0:5a3252c331b4 | 15 | DigitalOut LedD6 (P1_14); |
georgjonak | 0:5a3252c331b4 | 16 | DigitalOut LedD7 (P1_15); |
georgjonak | 0:5a3252c331b4 | 17 | DigitalOut LedD8 (P1_16); |
georgjonak | 0:5a3252c331b4 | 18 | DigitalOut LedD9 (P1_17); |
georgjonak | 0:5a3252c331b4 | 19 | DigitalOut LedD10 (P1_18); |
georgjonak | 0:5a3252c331b4 | 20 | DigitalOut LedD11 (P2_16); |
georgjonak | 0:5a3252c331b4 | 21 | DigitalOut LedD12 (P1_20); |
georgjonak | 0:5a3252c331b4 | 22 | DigitalOut LedD13 (P1_21); |
georgjonak | 0:5a3252c331b4 | 23 | |
georgjonak | 0:5a3252c331b4 | 24 | PwmOut MotorL_EN(P1_19); |
georgjonak | 0:5a3252c331b4 | 25 | DigitalOut MotorL_FORWARD(P2_15); // Forwerts |
georgjonak | 0:5a3252c331b4 | 26 | DigitalOut MotorL_REVERSE(P2_14); // Rückwerts |
georgjonak | 0:5a3252c331b4 | 27 | |
georgjonak | 0:5a3252c331b4 | 28 | PwmOut MotorR_EN(P2_19); |
georgjonak | 0:5a3252c331b4 | 29 | DigitalOut MotorR_FORWARD(P2_20); |
georgjonak | 0:5a3252c331b4 | 30 | DigitalOut MotorR_REVERSE(P2_21); |
georgjonak | 0:5a3252c331b4 | 31 | |
georgjonak | 0:5a3252c331b4 | 32 | int main() { |
georgjonak | 0:5a3252c331b4 | 33 | Von=1; |
georgjonak | 0:5a3252c331b4 | 34 | LineON=1; |
georgjonak | 0:5a3252c331b4 | 35 | MotorL_EN=1; |
georgjonak | 0:5a3252c331b4 | 36 | MotorR_EN=1; |
georgjonak | 0:5a3252c331b4 | 37 | |
georgjonak | 0:5a3252c331b4 | 38 | |
georgjonak | 0:5a3252c331b4 | 39 | while (1) { |
georgjonak | 0:5a3252c331b4 | 40 | MotorL_FORWARD = 1; |
georgjonak | 0:5a3252c331b4 | 41 | MotorR_FORWARD = 1; |
georgjonak | 0:5a3252c331b4 | 42 | MotorL_EN.period_ms (10); |
georgjonak | 0:5a3252c331b4 | 43 | MotorR_EN.period_ms (10); |
georgjonak | 0:5a3252c331b4 | 44 | MotorL_EN = 0.3f; |
georgjonak | 0:5a3252c331b4 | 45 | MotorR_EN.pulsewidth_ms(3); |
georgjonak | 0:5a3252c331b4 | 46 | MotorR_EN = 0.3f; |
georgjonak | 0:5a3252c331b4 | 47 | MotorL_EN.pulsewidth_ms(3); |
georgjonak | 0:5a3252c331b4 | 48 | |
georgjonak | 0:5a3252c331b4 | 49 | |
georgjonak | 0:5a3252c331b4 | 50 | if(ISO1 ==1){ |
georgjonak | 0:5a3252c331b4 | 51 | LedD1 =1; |
georgjonak | 0:5a3252c331b4 | 52 | MotorL_EN = 1.0f; |
georgjonak | 0:5a3252c331b4 | 53 | MotorR_EN.pulsewidth_ms(10); |
georgjonak | 0:5a3252c331b4 | 54 | MotorR_EN = 1.0f; |
georgjonak | 0:5a3252c331b4 | 55 | MotorL_EN.pulsewidth_ms(10); |
georgjonak | 0:5a3252c331b4 | 56 | |
georgjonak | 0:5a3252c331b4 | 57 | MotorR_FORWARD=0; |
georgjonak | 0:5a3252c331b4 | 58 | MotorL_FORWARD=0; |
georgjonak | 0:5a3252c331b4 | 59 | |
georgjonak | 0:5a3252c331b4 | 60 | MotorR_FORWARD=1; |
georgjonak | 0:5a3252c331b4 | 61 | MotorL_REVERSE=1; |
georgjonak | 0:5a3252c331b4 | 62 | } |
georgjonak | 0:5a3252c331b4 | 63 | |
georgjonak | 0:5a3252c331b4 | 64 | if(ISO4 ==1){ |
georgjonak | 0:5a3252c331b4 | 65 | LedD1 =1; |
georgjonak | 0:5a3252c331b4 | 66 | MotorL_EN = 1.0f; |
georgjonak | 0:5a3252c331b4 | 67 | MotorR_EN.pulsewidth_ms(10); |
georgjonak | 0:5a3252c331b4 | 68 | MotorR_EN = 1.0f; |
georgjonak | 0:5a3252c331b4 | 69 | MotorL_EN.pulsewidth_ms(10); |
georgjonak | 0:5a3252c331b4 | 70 | |
georgjonak | 0:5a3252c331b4 | 71 | MotorR_FORWARD=0; |
georgjonak | 0:5a3252c331b4 | 72 | MotorL_FORWARD=0; |
georgjonak | 0:5a3252c331b4 | 73 | MotorL_FORWARD=1; |
georgjonak | 0:5a3252c331b4 | 74 | MotorR_REVERSE=1; |
georgjonak | 0:5a3252c331b4 | 75 | |
georgjonak | 0:5a3252c331b4 | 76 | } |
georgjonak | 0:5a3252c331b4 | 77 | wait (0.01); |
georgjonak | 0:5a3252c331b4 | 78 | MotorL_FORWARD=0; |
georgjonak | 0:5a3252c331b4 | 79 | MotorR_REVERSE=0; |
georgjonak | 0:5a3252c331b4 | 80 | MotorR_FORWARD=0; |
georgjonak | 0:5a3252c331b4 | 81 | MotorL_REVERSE=0; |
georgjonak | 0:5a3252c331b4 | 82 | }} |
georgjonak | 0:5a3252c331b4 | 83 | |
georgjonak | 0:5a3252c331b4 | 84 | |
georgjonak | 0:5a3252c331b4 | 85 | |
georgjonak | 0:5a3252c331b4 | 86 |