tes ir atas semua

Dependencies:   mbed ADS1115 StepperMotor SRF05 TPA81new

main.cpp

Committer:
Ezeuz
Date:
2018-02-02
Revision:
4:9932af380e56
Parent:
1:ef90d942ce78
Child:
5:dae415fb4bad

File content as of revision 4:9932af380e56:

/*****************************************************
- Description: mbed to Dynamixel connection test using
    the library
- Requirements: 
    Dynamixel (i.e. DX116, RX28)
    MAX3088/MAX485 (RS485 transceiver)
- Connections:
    MAX3088     --  mbed
    ======================
    Pin 1       --  Pin 14
    Pin 2       --  Pin 15
    Pin 4       --  Pin 13
    
- Comments:
    See schematic for wiring details and class 
    documentation for available methods.
*****************************************************/

#include "mbed.h"
#include "Dynamixel.h"
#include "TextLCD.h"
#include "Uvtron.h"

// Defines
#define IR_CONST 1.229

// Settings
Dynamixel* servos[3*6];                             // Servo comm   : tx, rx, txEn, id, baud
TextLCD lcd(PB_2, PB_1, PB_15, PB_14, PB_13, PC_4); // LCD          : rs, e, d4-d7
AnalogIn ir(PA_5);                                  // Sharp IR     : analog
DigitalOut m2(PA_15);                               // extinguisher : 12V out M2
DigitalOut m1(PB_7);                                // extinguisher : 12V out M1, possibly broken
DigitalOut led1(PC_13);                             // GPIO high is 3V3
DigitalOut led2(PC_14);
DigitalIn sound(PA_6);                              // Sound act    : digital

Uvtron uv(PA_11);                                   // UVTron       : interrupt

/* About interrupt
Where are the interrupt pins on NUCLEO-F411RE?

If you use a recent version of the mbed lib (right mouse button, update in the online compiler):
Every unique numbered pin. That means you can use any pin as InterruptIn, but you cannot use multiple
pins with the same number on a different port as InterruptIn. So you can use PA_1, PB_2, PA_3, PC_4, etc.
But in this example you could not use also PE_1. */

int main()
{   
    float meas = 0;
    int snd = 0;
    
    // Servos
    for (int i = 1; i <= 20; i++) {
        servos[i] = new Dynamixel(PC_6, PC_7, PC_4, i, 1000000);
    }
    
    while (1) {
        // LCD
        lcd.printf("%.0f cm\n", meas);
        lcd.printf("sound %d | uv %d", snd, uv.Flag);
        
        // Servos
        for (int i = 1; i <= 20; i++) {
            servos[i]->setSpeed(100);
            servos[i]->move(512);    // Midddle, thus 90 deg position
        }
        
        // IR
        meas = ir.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
        meas = 5000000 / powf(meas, IR_CONST)+1;
        lcd.printf("%.0f cm\n", meas);
        
        // Extinguisher or 12V output
        m2 = 1;
        m1 = 1;
        
        // LED
        led1 = 1;
        led2 = 1;
        
        // Sound Activator
        snd = sound.read();
    }
}