tes ir atas semua

Dependencies:   mbed ADS1115 StepperMotor SRF05 TPA81new

main.cpp

Committer:
Ezeuz
Date:
2018-02-09
Revision:
5:dae415fb4bad
Parent:
4:9932af380e56
Child:
6:69c59bcab6ea

File content as of revision 5:dae415fb4bad:

/*****************************************************
- 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                                         // Servo comm   : tx, rx, txEn, id, baud
TextLCD lcd(PA_5, PA_11, PA_6, PB_12, PA_7, PB_6);  // LCD          : rs, e, d4-d7
AnalogIn ir(PC_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_12);                              // Sound act    : digital, active low
DigitalIn uv(PB_8);                                 // UVTron       : digital, pin 2 = active low
Serial pc(USBTX, USBRX); // tx, rx


/* 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()
{   
    // Servos
    for (int i = 1; i <= 18; i++) {
        Dynamixel servo(PC_6, PC_7, PC_4, i, 1000000);
        servo.setSpeed(100);
        servo.move(512);        // Midddle, thus 90 deg position
    }
    
    float meas = 0;
    int snd = 0;
    int uvo = 0;
    
    while (1) {
        // LCD
        lcd.printf("%.2fcm\n", meas);
        pc.printf("%.2fcm ", meas);

        lcd.printf("s%d u%d\n", snd, uvo);
        pc.printf("s%d u%d\n", snd, uvo);
        
        // IR
        meas = ir.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
        meas = ((1-meas)*26+4);
        
        // Extinguisher or 12V output
        m2 = 1;
        m1 = 1;
        
        // LED
        led1 = 1;
        led2 = 1;
        
        // Sound Activator
        snd = sound.read();
        
        // UV
        uvo = uv.read();
    }
}