Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of func_Bertl by
Revision 1:f2d7bec926ce, committed 2015-01-02
- Comitter:
- bulmecisco
- Date:
- Fri Jan 02 19:32:23 2015 +0000
- Parent:
- 0:0b7c22955b8c
- Child:
- 2:43547160ab56
- Commit message:
- ur_Karel with speed control
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Nov 13 18:19:47 2014 +0000
+++ b/main.cpp Fri Jan 02 19:32:23 2015 +0000
@@ -1,34 +1,113 @@
/***********************************
-name: BERTL_2014_TEST
-author: Gottfried Enenkel HTL BULME
-email: ene@bulme.at
+name: Karel
+author: PE HTL BULME
+email: pe@bulme.at
description:
- Der BERTL fährt 1 sec lang VORWÄRTS!
- Danach steht er für 1 sec
+ Funktionen von Karel The Robot
- Wenn an auf den Moter sieht, ist da + Zeichen
- immer LINKS OBEN zu sehen !
+
***********************************/
#include "mbed.h"
-// ************ DEKLARATIONEN **************
-DigitalOut MotorL_EN(p34);
-DigitalOut MotorL_FORWARD(P1_1);
-DigitalOut MotorL_REVERSE(P1_0);
+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);
+ 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() { // Start Hauptprogramm
- MotorR_EN=MotorL_EN=1; // Beide Motoren ENABLE
- while(1) { // Anfang der Schleife (ohne Abbruch)
- MotorR_FORWARD = MotorL_FORWARD = 1; // Beide Motoren vorwärts EIN
- wait (1); // warte 1 Sekunde
- MotorR_FORWARD = MotorL_FORWARD = 0; // Motoren AUS
- wait (1); // warte 1 Sekunde
- } // Springe zum Anfang der Schleife
-}
+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); //
-// ************** ENDE *************
+ 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;
+}
