control for robotic arm that can play chess using a granular gripper

Dependencies:   Encoder mbed HIDScope Servo MODSERIAL

Fork of chessRobot by a steenbeek

serialcom.cpp

Committer:
annesteenbeek
Date:
2015-10-29
Revision:
127:831f03471efb
Parent:
126:56866cefaa08
Child:
128:c583aff5a7bf

File content as of revision 127:831f03471efb:

#include "mbed.h"
#include "serialcom.h"
//#include "MODSERIAL.h"
#include "config.h"
#include "PID.h"
#include "buttons.h"
#include <string>

Serial pc(USBTX, USBRX);
char buf[128];

void serialInit(){
    const int baudrate = 9600;
    redLed.write(1); // dim the leds
    blueLed.write(1);
    greenLed.write(1);
    
    pc.baud(baudrate);
    }

void serialCom(){
    // Receiving
    pc.scanf("%s", buf);
    if(strcmp(buf,"ledRed")==0){
        redLed.write(!redLed.read());
        pc.printf("received data\n");
    }
    if(strcmp(buf,"ledBlue")==0){
        blueLed.write(!blueLed.read());
        pc.printf("received data\n");
    }
    if(strcmp(buf,"ledGreen")==0){
        greenLed.write(!greenLed.read());
        pc.printf("received data\n");
    }
    if(strcmp(buf, "switchPump")==0){
        enablePump = !enablePump;
        pc.printf("enablePump %d\n", enablePump);
    }
    if(strcmp(buf, "startCalibration")==0){
        startCalibration = true;
        pc.printf("startCalibration %d\n", startCalibration);
    }
    if(strcmp(buf, "enableEMG")==0){
        enableEMG = true;
        pc.printf("enableEMG %d\n", enableEMG);
    }
    if(strcmp(buf, "usePotmeters")==0){
        usePotmeters = true;
        pc.printf("usePotmeters %d\n", usePotmeters);
    }
    if(strcmp(buf, "controlAngle")==0){
        controlAngle = true;
        pc.printf("controlAngle %d\n", controlAngle);
    }
    if(strcmp(buf, "controlDirection")==0){
        controlDirection = true;
        pc.printf("controlDirection %d\n", controlDirection);
    }
}