ecoder motor semaforo

Dependencies:   mbed ssd1306_library SLCD

Files at this revision

API Documentation at this revision

Comitter:
20172573073
Date:
Wed Jun 24 23:39:49 2020 +0000
Commit message:
motor_RTOS

Changed in this revision

SLCD.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-os.lib 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
ssd1306_library.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r fb45c2082cb8 SLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SLCD.lib	Wed Jun 24 23:39:49 2020 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/SLCD/#ef2b3b7f1b01
diff -r 000000000000 -r fb45c2082cb8 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jun 24 23:39:49 2020 +0000
@@ -0,0 +1,213 @@
+#include "mbed.h"
+#include "rtos.h"
+#include "ssd1306.h"
+#include "SLCD.h"
+
+SLCD slcd;
+SSD1306 lcd (D7,D6);
+InterruptIn botoncito(PTC12);
+InterruptIn botoncito2(PTC3);
+InterruptIn botoncito3(D2);
+PwmOut pwm1(D5);
+PwmOut pwm2(D8);
+DigitalOut mo(D9);
+int contador=0,a=1,c=0,r,h,q;
+bool s=0,k=0;
+Serial pc(USBTX,USBRX);
+Semaphore one_slot(1);
+Mutex mutex1;
+
+
+Thread thread;
+Thread thread1;
+Thread thread2;
+Thread thread3;
+Thread thread4;
+
+
+void herra()
+{
+    one_slot.release();
+    one_slot.wait();
+    r=r+1;
+    one_slot.release();
+}
+
+void boton1()
+{
+    one_slot.release();
+    one_slot.wait();
+    //one_slot.try_acquire();
+    s=!s;
+    mo=s;
+    one_slot.release();
+}
+void boton2()
+{
+    one_slot.release();
+    one_slot.wait();
+    NVIC_SystemReset ();
+    one_slot.release();
+}
+
+
+
+void motor1()
+{
+    while(1) {
+        if(s==1) {
+            c++;
+            switch(c) {
+                case 1:
+                    pwm2=0.3;
+                    q=30;
+                    mo=s;
+                    Thread::wait(2000);
+                    break;
+                case 2:
+                    pwm2=0.5;
+                    q=50;
+                    mo=s;
+                    Thread::wait(2000);
+                    break;
+                case 3:
+                    pwm2=0.7;
+                    q=70;
+                    mo=s;
+                    Thread::wait(2000);
+                    break;
+                case 4:
+                    pwm2=1;
+                    q=100;
+                    mo=s;
+                    Thread::wait(6000);
+                    break;
+                case 5:
+                    pwm2=0.7;
+                    q=70;
+                    mo=s;
+                    Thread::wait(2000);
+                    break;
+                case 6:
+                    pwm2=0.5;
+                    q=50;
+                    mo=s;
+                    Thread::wait(2000);
+                    break;
+                case 7:
+                    q=30;
+                    pwm2=0.3;
+                    mo=s;
+                    Thread::wait(2000);
+                    c=0;
+                    break;
+
+            }
+        }
+    }
+}
+
+void oled()
+{
+    while(1) {
+        
+
+        if(k==0){
+        lcd.init();
+        lcd.speed (SSD1306::Fast);
+        lcd.cls();
+        lcd.locate (1,0);
+        time_t seconds = time(NULL);
+        lcd.printf("Fecha= %s", ctime(&seconds));
+        lcd.locate (4,1);
+        lcd.printf ("nivel: %d ",q);
+        lcd.locate (5,1);
+        lcd.printf ("rpm: %d ",h);
+        lcd.redraw();
+        
+        }else if(k==1){
+        lcd.init();
+        lcd.speed (SSD1306::Fast);
+        lcd.cls();    
+        lcd.locate (2,1);
+        lcd.printf ("error"); 
+        lcd.locate (5,0);
+        lcd.printf ("por favor revise el sistema"); 
+          lcd.redraw();  
+            }
+        
+        Thread::wait(300);
+    }
+}
+void s7()
+{
+    while(1) {
+        if(s==1 && r==0){
+            k=1;
+            
+        slcd.Home();
+        slcd.putc('e');
+        slcd.putc('r');
+        r=0;
+        Thread::wait(1000);
+        slcd.clear();
+        
+            }else{
+                k=0;
+        slcd.Home();
+        h=r*60;
+        h=h/4;
+        slcd.printf("%d",h);
+        r=0;
+        Thread::wait(1000);
+        slcd.clear();
+                
+                }
+    }
+}
+void serial()
+{
+    while(1) {
+
+        one_slot.release();
+        one_slot.wait();
+
+        time_t seconds = time(NULL);
+
+        char buffer2[32];
+        strftime(buffer2, 32, "%m/%d/%y", localtime(&seconds));
+        pc.printf("%s", buffer2);
+
+        char buffer1[32];
+        strftime(buffer1, 32, "%H:%M:%S", localtime(&seconds));
+        pc.printf(" , %s", buffer1);
+        if(k==1) {
+            pc.printf(" , %d ciclo, %d rpm, error",q,h);
+            
+        } else {
+            pc.printf(" , %d ciclo, %d rpm, ok",q,h);
+        }
+        pc.printf("\n\r");
+        
+        Thread::wait(100);
+        one_slot.release();
+
+    }
+}
+int main()
+{
+
+    set_time(1593041944);
+    botoncito.mode(PullUp);
+    botoncito.fall(&boton1);
+    botoncito2.mode(PullUp);
+    botoncito2.fall(&boton2);
+    botoncito3.mode(PullUp);
+    botoncito3.fall(&herra);
+
+    thread1.start(oled);
+    thread2.start(s7);
+    thread3.start(serial);
+    thread4.start((motor1));
+    thread4.join();
+}
\ No newline at end of file
diff -r 000000000000 -r fb45c2082cb8 mbed-os.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Wed Jun 24 23:39:49 2020 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#c9e63f14085f5751ff5ead79a7c0382d50a813a2
diff -r 000000000000 -r fb45c2082cb8 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jun 24 23:39:49 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file
diff -r 000000000000 -r fb45c2082cb8 ssd1306_library.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ssd1306_library.lib	Wed Jun 24 23:39:49 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/rodriguj/code/ssd1306_library/#57209a7e9cba