TINF_6ABEL18 / TINF_BankomatPIN

Files at this revision

API Documentation at this revision

Comitter:
martwerl
Date:
Fri Jun 22 13:56:38 2018 +0000
Commit message:
TINF_BankomatPIN

Changed in this revision

Bankomat.cpp Show annotated file Show diff for this revision Revisions of this file
Bankomat.h 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
diff -r 000000000000 -r 465c627254e2 Bankomat.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Bankomat.cpp	Fri Jun 22 13:56:38 2018 +0000
@@ -0,0 +1,56 @@
+#include "mbed.h"
+#include "Bankomat.h"
+
+
+    void  Bankomat::random()           
+    {   
+        for(int i=0;i<4;i++)
+        {
+        Pincode =rand() % 9+1;
+        Pincheck[i]=Pincode+48;
+        // printf("\npincode: %i\n", Pincode);
+        //printf("\npincheck: %i\n", Pincheck[i]);
+        Zahl[i] = Pincode; 
+        //printf("\nZahl: %i\n", Zahl[i]);
+        clearleds();
+        wait_ms(1500);
+        showPin();
+        
+         // printf("P %i_",Pincode);
+         // printf("C %c\t",Pincheck[i]);    
+        }
+        printf("\n_\t_\t_\t_\t\n\n");
+    }
+    
+    void Bankomat::showPin()
+    {
+        _allleds=Pincode;
+        
+        wait_ms(1500);
+        clearleds();
+    }
+    
+    void Bankomat::eingabe() 
+    {
+        scanf("%i",&Pinzahl[0]);
+        scanf("%i",&Pinzahl[1]);
+        scanf("%i",&Pinzahl[2]);
+        scanf("%i",&Pinzahl[3]);
+    }
+    
+void Bankomat::ausgabe() 
+{
+    printf("\nEingegeben: \n%i\t%i\t%i\t%i\t\n\n",Pinzahl[0],Pinzahl[1],Pinzahl[2],Pinzahl[3]);
+    printf("\nPIN: \n%i\t%i\t%i\t%i\t\n\n",Zahl[0],Zahl[1],Zahl[2],Zahl[3]);
+    if(Pinzahl[0] != Zahl[0]||Pinzahl[1] != Zahl[1]||Pinzahl[2] != Zahl[2]||Pinzahl[3] != Zahl[3])
+        printf("\nPIN falsch!\n");
+    else
+        printf("\nPIN richtig! Trotzdem gibt's kein Geld!!!\n");
+}
+
+void Bankomat::clearleds()
+{   _led1=0;
+    _led2=0; 
+    _led3=0;
+    _led4=0;
+}   
diff -r 000000000000 -r 465c627254e2 Bankomat.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Bankomat.h	Fri Jun 22 13:56:38 2018 +0000
@@ -0,0 +1,31 @@
+#include "mbed.h"
+#ifndef BANKOMAT_H
+#define BANKOMAT_H
+
+class Bankomat{
+public:
+
+    Bankomat(PinName pin1, PinName pin2, PinName pin3, PinName pin4): 
+    _allleds(pin1,pin2,pin3,pin4),
+    _led1(pin1), _led2(pin2), _led3(pin3), _led4(pin4)
+    {
+    }
+    void  random();
+    void showPin();
+    void eingabe();
+    void ausgabe();
+    void clearleds();
+    
+private:
+    DigitalOut _led1;
+    DigitalOut _led2;
+    DigitalOut _led3;
+    DigitalOut _led4;
+    
+    BusOut _allleds;
+    int Pincode;
+    int Pincheck[4];
+    int Zahl[4];
+    int Pinzahl[4];
+};
+#endif
\ No newline at end of file
diff -r 000000000000 -r 465c627254e2 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jun 22 13:56:38 2018 +0000
@@ -0,0 +1,23 @@
+#include "mbed.h"
+#include "Bankomat.h"
+
+Bankomat  bankcode(LED1,LED2,LED3,LED4);
+
+int main() 
+{
+printf("PIN wird erstellt!\n\n");
+    wait_ms(1000);
+    
+printf("Ausgabe an LEDs!\n(Binaercode)\n\n");
+        wait_ms(1000);
+    
+    bankcode.random();
+    
+printf("Bitte 4-stelligen PIN eingeben!\n\n");
+        wait_ms(1000);
+    bankcode.eingabe();
+//    printf("\nEingabe erledigt\n");
+    bankcode.ausgabe();
+//    printf("\nAusgabe erledigt\n");
+        wait_ms(5000);
+}