2 Motores + Joystick

Dependencies:   X_NUCLEO_IHM01A1 TextLCD

Fork of HelloWorld_IHM01A1_2Motors_mbedOS by ST

Files at this revision

API Documentation at this revision

Comitter:
leogrotti
Date:
Wed May 02 14:59:42 2018 +0000
Parent:
39:7e30bcc989d3
Child:
41:7f91e949ca88
Commit message:
3 motores + joystick + botao

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed May 02 13:39:56 2018 +0000
+++ b/main.cpp	Wed May 02 14:59:42 2018 +0000
@@ -68,6 +68,8 @@
 
 
 /* Variables -----------------------------------------------------------------*/
+DigitalIn button1(D2);
+
 /* Initialization parameters. */
 //L6474_init_t init = {
 //    160,                              /* Acceleration rate in pps^2. Range: (0..+inf). */
@@ -127,6 +129,24 @@
 L6474 *motor2;
 L6474 *motor3;
 
+void flag_irq_handler(void)
+{
+    /* Set ISR flag. */
+    motor3->isr_flag = TRUE;
+ 
+    /* Get the value of the status register. */
+    unsigned int status = motor3->get_status();
+ 
+    /* Check NOTPERF_CMD flag: if set, the command received by SPI can't be performed. */
+    /* This often occures when a command is sent to the L6474 while it is not in HiZ state. */
+    if ((status & L6474_STATUS_NOTPERF_CMD) == L6474_STATUS_NOTPERF_CMD) {
+        printf("    WARNING: \"FLAG\" interrupt triggered. Non-performable command detected when updating L6474's registers while not in HiZ state.\r\n");
+    }
+    
+    /* Reset ISR flag. */
+    motor3->isr_flag = FALSE;
+}
+
 
 /* Main ----------------------------------------------------------------------*/
 
@@ -168,21 +188,27 @@
 //motor2->set_parameter(L6474_STEP_MODE,L6474_STEP_SEL_1_2);
 
 
+    /* Attaching and enabling interrupt handlers. */
+    motor3->attach_flag_irq(&flag_irq_handler);
+    motor3->enable_flag_irq();
 
  
     while(true) {
         u = eixo_X.read();
         w = eixo_Y.read();
         
-  //      wait (1.5);
-  //      pc.printf ("X:   %f \r\n",u);
-  //      pc.printf ("Y:    %f  \r\n",w);
-  
+  if (button1.read() == 0){ 
+        
         motor3->run(StepperMotor::FWD);
-       // motor3->move(StepperMotor::BWD, 100);
-        //motor3->wait_while_active();
+            printf("button1 fwd \r\n\n");
         
- //    pc.printf ("bwd");
+     }
+    
+    else {
+        motor3->run(StepperMotor::BWD);
+            printf("button1 bwd \r\n\n");
+         
+     }
 
   
         if (u>0.740) {