ultra sonic sensor asdded

Dependencies:   HCSR mbed

Fork of func_Bertl by BULME_BERTL14

main.cpp

Committer:
bulmecisco
Date:
2015-01-02
Revision:
1:f2d7bec926ce
Parent:
0:0b7c22955b8c
Child:
2:43547160ab56

File content as of revision 1:f2d7bec926ce:

/***********************************
name:   Karel
author: PE HTL BULME
email:  pe@bulme.at
description:
    Funktionen von Karel The Robot 
    
      
***********************************/
#include "mbed.h"

void move()
{  
    DigitalOut MotorL_EN(p34);
    DigitalOut MotorL_FORWARD(P1_1);
    //DigitalOut MotorL_REVERSE(P1_0);

    DigitalOut MotorR_EN(p36);
    DigitalOut MotorR_FORWARD(P1_3);
    //DigitalOut MotorR_REVERSE(P1_4);

    MotorR_EN=MotorL_EN=1;                 // Beide Motoren ENABLE

    MotorR_FORWARD = MotorL_FORWARD = 1;   // Beide Motoren vorwärts EIN
    wait_ms(250);                           // warte 0,25 Sekunde
    MotorR_FORWARD = MotorL_FORWARD = 0;    // Motoren AUS
    //wait_ms(250);            
}

void moveSpeed(float speedy)
{  
    DigitalOut MotorL_EN(p34);
    DigitalOut MotorL_FORWARD(P1_1);
    //DigitalOut MotorL_REVERSE(P1_0);

    DigitalOut MotorR_EN(p36);
    DigitalOut MotorR_FORWARD(P1_3);
    //DigitalOut MotorR_REVERSE(P1_4);
    PwmOut mg1(p34);             //PWM Ausgang zum Motor
    PwmOut mg2(p36);
    mg1=mg2=speedy;
    
    MotorR_EN=MotorL_EN=1;                 // Beide Motoren ENABLE

    MotorR_FORWARD = MotorL_FORWARD = 1;   // Beide Motoren vorwärts EIN
    wait_ms(2000);                           // warte 0,25 Sekunde
    MotorR_FORWARD = MotorL_FORWARD = 0;    // Motoren AUS
    MotorR_EN=MotorL_EN=0;                 // Beide Motoren ENABLE
    wait_ms(500);            
}
void move(int anzahl)
{
  
    for(int i=0; i < anzahl; i++)
        move();
    
}

void turnLeft()
{
//    DigitalOut MotorL_EN(p34);
//    DigitalOut MotorL_FORWARD(P1_1);
//    DigitalOut MotorL_REVERSE(P1_0);

    DigitalOut MotorR_EN(p36);
    DigitalOut MotorR_FORWARD(P1_3);
//    DigitalOut MotorR_REVERSE(P1_4);
//  MotorL_EN=1;

    MotorR_EN=1;      // rechten Motor ENABLE

    MotorR_FORWARD = 1;  // rechter Motor vorwärts EIN 
    wait_ms(750);        // warte (90°)
    MotorR_FORWARD = 0;  // Motoren AUS
}

// *************  Hauptprogramm ************
int main()
{
    //move();
    //turnLeft();
    DigitalOut LED_D10(P1_8);    // LED D10 und D13 definieren
    DigitalOut LED_D11(P1_9);    // LED D10 und D13 definieren
    DigitalOut LED_D12(P1_10);    // LED D10 und D13 definieren
    DigitalOut LED_D13(P1_11);   //

    moveSpeed(0.25);
    LED_D10 = 1;
    moveSpeed(0.3);
    LED_D11 = 1;
    moveSpeed(0.4);
    LED_D12 = 1;
    moveSpeed(0.5);
    LED_D13 = 1;
    moveSpeed(0.6);
    LED_D10 = LED_D11 = LED_D12 = LED_D13 = 0;
    moveSpeed(0.7);
    LED_D10 = 1;
    moveSpeed(0.8);
    LED_D11 = 1;
    moveSpeed(0.9);
    LED_D12 = 1;
    moveSpeed(1.0);
    LED_D10 = LED_D11 = LED_D12 = LED_D13 = 1;
    //wait(2);
    //turnLeft();
    //move();
    //turnLeft();
    //move(5);

    //wait(2);
    return 0;
}