LED.h & Umwandeln.h

Dependencies:   m3pi_ng mbed

Files at this revision

API Documentation at this revision

Comitter:
spolak
Date:
Wed Jan 11 09:43:00 2017 +0000
Commit message:
Klassen zum Blinken und Umwandeln vom Text

Changed in this revision

Klassen/Beispiele/LED_umwandeln.h Show annotated file Show diff for this revision Revisions of this file
Klassen/LED.h Show annotated file Show diff for this revision Revisions of this file
Klassen/Umwandeln.h Show annotated file Show diff for this revision Revisions of this file
Runden_Anzeigen.h Show annotated file Show diff for this revision Revisions of this file
Runden_Anzeigen_cpp.h Show annotated file Show diff for this revision Revisions of this file
TEST.h Show annotated file Show diff for this revision Revisions of this file
basic.h Show annotated file Show diff for this revision Revisions of this file
basic2.h Show annotated file Show diff for this revision Revisions of this file
m3pi_ng.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r d453d7554981 Klassen/Beispiele/LED_umwandeln.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Klassen/Beispiele/LED_umwandeln.h	Wed Jan 11 09:43:00 2017 +0000
@@ -0,0 +1,24 @@
+  #include "mbed.h"
+  #include "m3pi_ng.h"
+  #include "LED.h" //für die Steuerung der LEDs
+  #include "Umwandeln.h" //für die Umwandlung von int/string für printf(*)
+
+
+m3pi pi;
+
+int main()
+{
+    LED A; //Klasseninstanz A für die LED-Anzeige
+    umwandeln B; //Klasseninstanz B für Bildschirmanzeige der Runden
+    int x=0;
+    string Satz="String umwandeln";
+    while (1)
+    {
+        A.Runden_LED(x); //Zeigt die Rundenanzahl mit den LEDs an
+        pi.printf(B.int_umwandeln(x)); //Zeichent die Rundenzahl auf dem Bildschirm
+        pi.printf(".Runde"); //test
+        wait(1); //test
+        pi.cls(); //test
+        x++;
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r d453d7554981 Klassen/LED.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Klassen/LED.h	Wed Jan 11 09:43:00 2017 +0000
@@ -0,0 +1,109 @@
+//LEDs ansteuern
+  #include "mbed.h"
+  #include "m3pi_ng.h"
+ 
+DigitalOut myled(LED1);
+DigitalOut myled2(LED2);
+DigitalOut myled3(LED3);
+DigitalOut myled4(LED4);
+m3pi rot;
+   
+class LED // Steuert die blauen und/oder roten LEDs an
+{
+public:
+int i;
+
+void Blau_Blinken(int Wie_oft, float Wartezeit) //Anzahl von blinkern, Wartezeit dazwischen
+{
+    for (i=Wie_oft; i>=1; i--)
+    {
+        myled = myled2 = myled3 = myled4 = 1;
+        wait(Wartezeit);
+        myled = myled2 = myled3 = myled4 = 0;
+        wait(Wartezeit);
+    }
+}
+
+void Rot_Blinken(int Wie_oft, float Wartezeit) //Anzahl von blinkern, Wartezeit dazwischen
+{
+    for (i=Wie_oft; i>=1; i--)
+    {
+        rot.leds(255);
+        wait(Wartezeit);
+        rot.leds(0);
+        wait(Wartezeit);
+    }
+}
+
+void Blau_Zahl(int Zahl) //eine Zahl zwischen 0 und 4
+{
+    if (Zahl>=4)    //alle 4 an
+    myled = myled2 = myled3 = myled4 = 1;
+    else if (Zahl==3)    //1-3 an, 4 aus
+    {
+    myled = myled2 = myled3 = 1;
+    myled4 = 0;
+    }
+    else if (Zahl==2)    //1-2 an, 3-4 aus
+    {
+    myled = myled2 = 1;
+    myled3 = myled4 = 0;
+    }
+    else if (Zahl==1)
+    {
+    myled = 1;
+    myled2 = myled3 = myled4 = 0;
+    }
+    else
+    myled = myled2 = myled3 = myled4 = 1;
+}
+
+void Rot_Zahl(int Zahl) //eine Zahl zwischen 0 und 8
+{
+    if (Zahl>=8) rot.leds(255);
+    if (Zahl==7) rot.leds(127);
+    if (Zahl==6) rot.leds(63);
+    if (Zahl==5) rot.leds(31);
+    if (Zahl==4) rot.leds(15);
+    if (Zahl==3) rot.leds(7);
+    if (Zahl==2) rot.leds(3);
+    if (Zahl==1) rot.leds(1);
+    if (Zahl==0) rot.leds(0);
+}
+
+void Runden_LED(int Zahl) //Rot zählt 1-4, bei 5 leuchtet ein blaues auf und rot geht aus
+{
+    if (Zahl>24) {Zahl=Zahl%24;}
+    
+    i=Zahl%5;
+    Zahl=(Zahl-i)/5;
+    
+    
+    
+    if (Zahl>=4)    //4 blaue LED an
+    myled = myled2 = myled3 = myled4 = 1;
+    else if (Zahl==3)
+    {
+    myled = myled2 = myled3 = 1;
+    myled4 = 0;
+    }
+    else if (Zahl==2)    //1-2 an, 3-4 aus
+    {
+    myled = myled2 = 1;
+    myled3 = myled4 = 0;
+    }
+    else if (Zahl==1)
+    {
+    myled = 1;
+    myled2 = myled3 = myled4 = 0;
+    }
+    else
+    myled = myled2 = myled3 = myled4 = 0;
+    
+    if (i==4) rot.leds(60);
+    else if (i==3) rot.leds(28);
+    else if (i==2) rot.leds(12);
+    else if (i==1) rot.leds(4);
+    else if (i==0) rot.leds(0);
+}
+};
\ No newline at end of file
diff -r 000000000000 -r d453d7554981 Klassen/Umwandeln.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Klassen/Umwandeln.h	Wed Jan 11 09:43:00 2017 +0000
@@ -0,0 +1,28 @@
+//wandelt int in const char* um. Kann dann mit printf(*) gemnutzt werden
+  #include "mbed.h"
+  #include "m3pi_ng.h"
+  #include <sstream>
+
+class umwandeln //Wandelt int oder string in const char* um
+{
+    public:
+    string str;     //für die Umwandlung in String
+    stringstream s; //für die Umwandlung in stringstram
+    const char * y;
+    
+    const char * int_umwandeln (int Zahl) //Eine ganze Zahl übergeben
+    {
+    s.str("");  //stringstream löschen
+    str = "";   //Löscht str
+    s << Zahl;   //Zahl hinzufügen, in Stringstram
+    str = s.str();  //stringstram in string umwandeln
+    y = str.c_str();   //Wandelt String in const char* um
+    return y;   //Gibt die Rundenzahl als const char* ab
+    }
+    
+    const char * string_umwandeln (string Satz) //Ein Satz/Wort übergeben
+    {
+    return Satz.c_str();
+    }
+
+};
\ No newline at end of file
diff -r 000000000000 -r d453d7554981 Runden_Anzeigen.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Runden_Anzeigen.h	Wed Jan 11 09:43:00 2017 +0000
@@ -0,0 +1,27 @@
+//LEDs ansteuern
+  #include "mbed.h"
+  #include "m3pi_ng.h"
+  #include "LED_ansteuern.h"
+  #include <sstream>
+
+class Runden_Anzeigen
+{
+    public:
+    LEDD A;         //Klasseninstanz A
+    string str;     //für die Umwandlung in String
+    stringstream s; //für die Umwandlung in stringstram
+    
+    const char * Runden (int Runden)
+    {
+    A.Runden_LED(Runden);
+    s << Runden;   //Zahl hinzufügen, in Stringstram
+    str = s.str();  //stringstram in string umwandeln
+    const char * y = str.c_str();   //Wandelt String in const char* um
+       
+    str = "";   //Löscht str
+    s.str("");  //stringstream löschen
+    
+    return y;   //Gibt die Rundenzahl als const char* ab
+    }
+    
+};
\ No newline at end of file
diff -r 000000000000 -r d453d7554981 Runden_Anzeigen_cpp.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Runden_Anzeigen_cpp.h	Wed Jan 11 09:43:00 2017 +0000
@@ -0,0 +1,35 @@
+//LEDs ansteuern
+  #include "mbed.h"
+  #include "m3pi_ng.h"
+  #include "LED_ansteuern.h"
+  #include <sstream>
+ 
+m3pi pi;
+
+int main()
+{
+    LEDD A; //Klasseninstanz A
+    int Runden=0;
+    string str; //für die Umwandlung in String
+    stringstream s; //für die Umwandlung in stringstram
+
+    while (1)
+    {
+    A.Runden(Runden);
+    
+    s << Runden;// Zahl hinzufügen, in Stringstram
+    str = s.str();  //stringstram in string umwandeln
+    const char * y = str.c_str();   //Wandelt String in const char* um
+    
+    pi.printf(y);   //Zeigt die Rundenzahl an
+    wait(0.5);
+    pi.cls();
+       
+    str = "";   //Löscht str
+    s.str("");      //stringstream löschen
+
+    Runden++;
+    }
+}
+//Ab 46? kommt die nächste Zeile
+//je 8 Zeichenfelder
\ No newline at end of file
diff -r 000000000000 -r d453d7554981 TEST.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TEST.h	Wed Jan 11 09:43:00 2017 +0000
@@ -0,0 +1,54 @@
+// Drive the m3pi forward, turn left, back, turn right, at half speed for half a second
+
+  #include "mbed.h"
+  #include "m3pi_ng.h"
+
+  m3pi pi;
+
+  int main() {
+
+    wait(0.5);
+    pi.right_motor(0.5);
+    pi.left_motor(0.2);
+    wait(0.5);
+    pi.left_motor(0.5);
+    pi.right_motor(0.2);
+    wait(0.5);
+  
+    pi.stop();
+    wait(0.5);
+      
+    int i=1, n=0;
+    while(n!=8)
+    {
+        pi.leds(i);
+        wait(0.2);
+        i=i*2;
+        n++;
+    }
+    
+    wait(1);
+
+    i=1, n=0;
+    while(n!=8)
+    {
+        pi.leds(i);
+        wait(0.2);
+        i=i*2;
+        n++;
+    }
+
+    pi.stop();
+    wait(0.5);
+    
+    pi.right_motor(-0.5);
+    pi.left_motor(-0.2);
+    wait(0.5);
+    pi.left_motor(-0.5);
+    pi.right_motor(-0.2);
+    wait(0.5);
+    
+    
+    pi.stop();
+
+}
diff -r 000000000000 -r d453d7554981 basic.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/basic.h	Wed Jan 11 09:43:00 2017 +0000
@@ -0,0 +1,42 @@
+#include "mbed.h"
+#include "m3pi_ng.h"
+ 
+m3pi pi;
+ 
+int main() {
+ 
+    // Parameters that affect the performance
+    float speed = 0.7; //geschw.
+    float correction = 0.5;   //korrektur links, rechts
+    float threshold = 0.5;  //schwelle, korrektur
+ 
+    pi.locate(0,1); //vorgefertigte position, ausrichten
+    pi.printf("Runde: ");
+ 
+    wait(2.0);
+    
+    pi.sensor_auto_calibrate();
+    
+    while (1) {
+ 
+        // -1.0 is far left, 1.0 is far right, 0.0 in the middle
+        float position_of_line = pi.line_position();
+ 
+        // Line is more than the threshold to the right, slow the left motor
+        if (position_of_line > threshold) {
+            pi.leftt_motor(speed);
+            pi.right_motor(speed-correction);
+        }
+ 
+        // Line is more than 50% to the left, slow the right motor
+        else if (position_of_line < -threshold) {
+            pi.right_motor(speed);
+            pi.left_motor(speed-correction);
+        }
+ 
+        // Line is in the middle
+        else {
+            pi.forward(speed);
+        }
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r d453d7554981 basic2.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/basic2.h	Wed Jan 11 09:43:00 2017 +0000
@@ -0,0 +1,70 @@
+#include "mbed.h"
+#include "m3pi_ng.h"
+ 
+m3pi m3pi;
+ 
+// Minimum and maximum motor speeds
+#define MAX 1.0
+#define MIN 0
+ 
+// PID terms
+#define P_TERM 1
+#define I_TERM 0
+#define D_TERM 20
+ 
+int main() {
+ 
+    m3pi.locate(0,1);
+    m3pi.printf("Line PID");
+ 
+    wait(2.0);
+ 
+    m3pi.sensor_auto_calibrate();
+ 
+    float right;
+    float left;
+    float current_pos_of_line = 0.0;
+    float previous_pos_of_line = 0.0;
+    float derivative,proportional,integral = 0;
+    float power;
+    float speed = MAX;
+    
+    while (1) {
+ 
+        // Get the position of the line.
+        current_pos_of_line = m3pi.line_position();        
+        proportional = current_pos_of_line;
+        
+        // Compute the derivative
+        derivative = current_pos_of_line - previous_pos_of_line;
+        
+        // Compute the integral
+        integral += proportional;
+        
+        // Remember the last position.
+        previous_pos_of_line = current_pos_of_line;
+        
+        // Compute the power
+        power = (proportional * (P_TERM) ) + (integral*(I_TERM)) + (derivative*(D_TERM)) ;
+        
+        // Compute new speeds   
+        right = speed+power;
+        left  = speed-power;
+        
+        // limit checks
+        if (right < MIN)
+            right = MIN;
+        else if (right > MAX)
+            right = MAX;
+            
+        if (left < MIN)
+            left = MIN;
+        else if (left > MAX)
+            left = MAX;
+            
+       // set speed 
+        m3pi.left_motor(left);
+        m3pi.right_motor(right);
+ 
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r d453d7554981 m3pi_ng.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m3pi_ng.lib	Wed Jan 11 09:43:00 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/ngoldin/code/m3pi_ng/#5589eef1f879
diff -r 000000000000 -r d453d7554981 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jan 11 09:43:00 2017 +0000
@@ -0,0 +1,39 @@
+#include "mbed.h"
+#include "m3pi_ng.h"
+//#include "Umwandeln.h"
+#include "LED.h"
+m3pi pi;
+
+
+int main()
+{
+    //umwandeln A;
+    LED B;
+    pi.sensor_auto_calibrate();
+    int sensors[5]={};
+    while (1){
+        pi.calibrated_sensor(sensors);
+        if ((sensors[0]>400) && (sensors[4]>400))
+        B.Blau_Blinken(2,0.2);
+    }
+}
+//0=weiß 1000=schwarz 
+/*
+int main()
+{
+
+    umwandeln A;
+    pi.sensor_auto_calibrate();
+    int sensors[5]={};
+    
+    
+    while (1)
+    {
+    pi.calibrated_sensor(sensors);
+    pi.printf(A.int_umwandeln(sensors[0]));
+    wait(0.1);
+    pi.cls();
+    }
+
+}
+*/
\ No newline at end of file
diff -r 000000000000 -r d453d7554981 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jan 11 09:43:00 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/99b5ccf27215
\ No newline at end of file