Package com.ardublock.translator.block

Examples of com.ardublock.translator.block.TranslatorBlock


  @Override
  public String toCode() throws SocketNullException, SubroutineNotDeclaredException {
    translator.addHeaderFile("Makeblock.h");
    translator.addHeaderFile("SoftwareSerial.h");
    translator.addHeaderFile("Wire.h");
    TranslatorBlock translatorBlock = this.getRequiredTranslatorBlockAtSocket(0);
    String ret = "MeUltrasonicSensor ultraSensor"+translatorBlock.toCode()+"(PORT_"+translatorBlock.toCode()+");";
    translator.addDefinitionCommand(ret);
    return codePrefix + "ultraSensor"+translatorBlock.toCode()+".distanceCm()" + codeSuffix;
  }
View Full Code Here


      String Pin ;
      String Pixel_Nb;
      String Red;
      String Blue;
      String Green;
      TranslatorBlock translatorBlock = this.getRequiredTranslatorBlockAtSocket(0);
      Pin = translatorBlock.toCode();
      translatorBlock = this.getRequiredTranslatorBlockAtSocket(1);
      Pixel_Nb = translatorBlock.toCode();
      translatorBlock = this.getRequiredTranslatorBlockAtSocket(2);
      Green = translatorBlock.toCode();
      translatorBlock = this.getRequiredTranslatorBlockAtSocket(3);
      Red = translatorBlock.toCode();
      translatorBlock = this.getRequiredTranslatorBlockAtSocket(4);
      Blue = translatorBlock.toCode();
     
     
      String ret = "strip_pin"+Pin+".setPixelColor("+Pixel_Nb+","+Green+" ,"+Red+" ,"+Blue+" );\n";
     
      return codePrefix + ret + codeSuffix;
View Full Code Here

  }

  public String toCode() throws SocketNullException, SubroutineNotDeclaredException
  {
       
    TranslatorBlock ChannelBlock = this.getRequiredTranslatorBlockAtSocket(0);
    TranslatorBlock SpeedBlock = this.getRequiredTranslatorBlockAtSocket(1);
    String ChannelNumber = ChannelBlock.toCode();
    String Speed = SpeedBlock.toCode();
    String MotorDeclare;
   
    if (Integer.parseInt(ChannelNumber) > 4 )
    {
      throw new BlockException(this.blockId, "the Channel# of DC Motor must be 1,2,3 or 4");
View Full Code Here

  @Override
  public String toCode() throws SocketNullException, SubroutineNotDeclaredException {
    translator.addHeaderFile("Makeblock.h");
    translator.addHeaderFile("SoftwareSerial.h");
    translator.addHeaderFile("Wire.h");
    TranslatorBlock block = this.getRequiredTranslatorBlockAtSocket(0);
    String ret = "MeBluetooth bluetooth"+block.toCode()+"(PORT_"+block.toCode()+");";
    translator.addDefinitionCommand(ret);
    translator.addSetupCommand("bluetooth"+block.toCode()+".begin(9600);");
    TranslatorBlock paramName = this.getRequiredTranslatorBlockAtSocket(1);
   
    return "bluetooth"+block.toCode()+".getParamValue(\""+paramName.toCode().replace("\"","")+"\")";
  }
View Full Code Here

  //@Override
    public String toCode() throws SocketNullException, SubroutineNotDeclaredException
    {
      String Pin ;

      TranslatorBlock translatorBlock = this.getRequiredTranslatorBlockAtSocket(0);
      Pin = translatorBlock.toCode();
     
     
      String ret = "strip_pin"+Pin+".show();\n";
     
      return codePrefix + ret + codeSuffix;
View Full Code Here

  //@Override
  public String toCode() throws SocketNullException, SubroutineNotDeclaredException
  {
   
    TranslatorBlock tb = this.getRequiredTranslatorBlockAtSocket(0);
    String I2C_addr = tb.toCode();
    String ret = "lcd_I2C_" + I2C_addr + ".cursor();\n";
    return ret;
  }
View Full Code Here

  @Override
  public String toCode() throws SocketNullException, SubroutineNotDeclaredException {
    translator.addHeaderFile("Makeblock.h");
    translator.addHeaderFile("SoftwareSerial.h");
    translator.addHeaderFile("Wire.h");
    TranslatorBlock port = this.getTranslatorBlockAtSocket(0);
    TranslatorBlock me = this.getTranslatorBlockAtSocket(1);
   
    int portNum = port==null?0:Integer.parseInt(port.toCode());
    TranslatorBlock block = portNum>0?port:me;
    String motor = "dcMotor"+block.toCode();
    String ret = "MeDCMotor "+motor+(portNum>0?"(PORT_":"(M")+block.toCode()+");";
    translator.addDefinitionCommand(ret);
    block = this.getRequiredTranslatorBlockAtSocket(2);
    if(block instanceof NumberBlock){
      int speed = Integer.parseInt(block.toCode());
      speed = speed>255?255:(speed<-255?-255:speed);
      if(speed==0){
        return motor+".stop();\n";
      }else{
        return motor+".run("+speed+");\n";
      }
    }else{
      return motor+".run("+block.toCode()+");\n";
    }
   
  }
View Full Code Here

  @Override
  public String toCode() throws SocketNullException, SubroutineNotDeclaredException {
    translator.addHeaderFile("Makeblock.h");
    translator.addHeaderFile("SoftwareSerial.h");
    translator.addHeaderFile("Wire.h");
    TranslatorBlock portBlock = this.getRequiredTranslatorBlockAtSocket(0);
    String ret = "MeStepperMotor stepper"+portBlock.toCode()+"(PORT_"+portBlock.toCode()+");";
    translator.addDefinitionCommand(ret);
    TranslatorBlock speedBlock = this.getRequiredTranslatorBlockAtSocket(1);
    TranslatorBlock accelerationBlock = this.getRequiredTranslatorBlockAtSocket(2);
    translator.addSetupCommand("stepper"+portBlock.toCode()+".begin(STP_SIXTEENTH,"+speedBlock.toCode()+","+accelerationBlock.toCode()+");");
    TranslatorBlock moveToBlock = this.getRequiredTranslatorBlockAtSocket(3);
    TranslatorBlock execBlock = getTranslatorBlockAtSocket(4);
    ret = "stepper"+portBlock.toCode()+".moveTo("+moveToBlock.toCode()+");\n";
    ret += "int distance = stepper"+portBlock.toCode()+".distanceToGo();\n";    
    ret += "if(distance==0){\n";
    String exec = "";
    while (execBlock != null)
    {
      exec += "\t"+ execBlock.toCode()+"\n";
      execBlock = execBlock.nextTranslatorBlock();
    }
    ret += exec+"\n}";
       
    return ret;
  }
View Full Code Here

  public String toCode() throws SocketNullException, SubroutineNotDeclaredException
  {
     
     
    TranslatorBlock ChannelBlock = this.getRequiredTranslatorBlockAtSocket(0);
    TranslatorBlock SpeedBlock = this.getRequiredTranslatorBlockAtSocket(1);
    String ChannelNumber = ChannelBlock.toCode();
    String Speed = SpeedBlock.toCode();
    String MotorDeclare;
   
    if (Integer.parseInt(ChannelNumber) > 4 )
    {
      throw new BlockException(this.blockId, "the Channel# of DC Motor must be 1,2,3 or 4");
View Full Code Here

        translator.addSetupCommand("Serial.begin(115200);");

        translator.addDefinitionCommand(midiFunctions);
    translator.addDefinitionCommand("#define MIDI_C 0\n#define MIDI_CS 1\n#define MIDI_D 2\n#define MIDI_DS 3\n#define MIDI_E 4\n#define MIDI_F 5\n#define MIDI_FS 6\n#define MIDI_G 7\n#define MIDI_GS 8\n#define MIDI_A 9\n#define MIDI_AS 10\n#define MIDI_B 11\n#define MIDI_OCTAVE 12");
   
    TranslatorBlock translatorBlock = getRequiredTranslatorBlockAtSocket(0);
        String note = translatorBlock.toCode();
    translatorBlock = getRequiredTranslatorBlockAtSocket(1);
        int octave = Integer.parseInt(translatorBlock.toCode());
    translatorBlock = getRequiredTranslatorBlockAtSocket(2);
        int channel = Integer.parseInt(translatorBlock.toCode());
    translatorBlock = getRequiredTranslatorBlockAtSocket(3);
        int velocity = Integer.parseInt(translatorBlock.toCode());


    return " midi_note_on(" + constrain(channel, 0, 16) + ", MIDI_" + note + " + " + constrain(octave, 0, 9) + " * MIDI_OCTAVE " + ", " + constrain(velocity, 0, 127) + ");\n";
    }
View Full Code Here

TOP

Related Classes of com.ardublock.translator.block.TranslatorBlock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.