Package com.ardublock.translator.block

Examples of com.ardublock.translator.block.TranslatorBlock


      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);
      Red = translatorBlock.toCode();
      translatorBlock = this.getRequiredTranslatorBlockAtSocket(3);
      Green = 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


  @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 = "MeShutter shutter"+translatorBlock.toCode()+"(PORT_"+translatorBlock.toCode()+");";
    translator.addDefinitionCommand(ret);
    TranslatorBlock state = this.getRequiredTranslatorBlockAtSocket(1);
    int stateId = Integer.parseInt(state.toCode());
    return "\tshutter"+translatorBlock.toCode()+(stateId==1?".shotOn()":(stateId==2?".shotOff()":(stateId==3?".focusOn()":".focusOff()")))+";\n";
  }
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);
      Red = translatorBlock.toCode();
      translatorBlock = this.getRequiredTranslatorBlockAtSocket(3);
      Green = translatorBlock.toCode();
      translatorBlock = this.getRequiredTranslatorBlockAtSocket(4);
      Blue = translatorBlock.toCode();
     
     
      String ret = "strip_pin"+Pin+".setPixelColor("+Pixel_Nb+","+Red+" ,"+Green+" ,"+Blue+" );\n";
     
      return codePrefix + ret + codeSuffix;
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 dataBlock = this.getRequiredTranslatorBlockAtSocket(1);
    return "bluetooth"+block.toCode()+".write("+dataBlock.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 block = this.getRequiredTranslatorBlockAtSocket(0);
    String servo = "servoDriver"+block.toCode();
   
    block = this.getRequiredTranslatorBlockAtSocket(1);
    String device = block.toCode();
    if(block instanceof NumberBlock){
      int deviceId = Integer.parseInt(block.toCode());
      if(deviceId>2||deviceId<1){
        throw new BlockException(this.blockId, "the Device Id of Servo must be in Range(1,2)");
      }
      deviceId = deviceId>2?2:(deviceId<1?1:deviceId);
      device = ""+deviceId;
    }else{
      device = "1";
    }
    String ret = "MeServo "+servo+"(PORT_"+block.toCode()+","+device+");";
    translator.addDefinitionCommand(ret);
    String output = "";
    block = this.getRequiredTranslatorBlockAtSocket(2);
    if(block instanceof NumberBlock){
      int angle = Integer.parseInt(block.toCode());
      if(angle>180||angle<0){
        throw new BlockException(this.blockId, "the angle of Servo must be in Range(0,180)");
      }
      angle = angle>180?180:(angle<0?0:angle);
      output+= servo+".write("+angle+");\n";
    }else{
      output+= servo+".write("+block.toCode()+");\n";
    }
    return output;
  }
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 translatorBlock = this.getRequiredTranslatorBlockAtSocket(0);
    String ret = "MeLineFinder lineFinder"+translatorBlock.toCode()+"(PORT_"+translatorBlock.toCode()+");";
    translator.addDefinitionCommand(ret);
    return "lineFinder"+translatorBlock.toCode()+".readSensors()";
  }
View Full Code Here

    public String toCode() throws SocketNullException, SubroutineNotDeclaredException
    {
      String Pin ;
      String Brightness;

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

    {
      String Pin ;
      String NbLed;
      String NEO_KHZ800;
      String NEO_RGB;
      TranslatorBlock translatorBlock = this.getRequiredTranslatorBlockAtSocket(0);
      Pin = translatorBlock.toCode();
      translatorBlock = this.getRequiredTranslatorBlockAtSocket(1);
      NbLed = translatorBlock.toCode();
      translatorBlock = this.getRequiredTranslatorBlockAtSocket(2);
      NEO_KHZ800 = translatorBlock.toCode();
      translatorBlock = this.getRequiredTranslatorBlockAtSocket(3);
      NEO_RGB = translatorBlock.toCode();
     
      translator.addHeaderFile("Adafruit_NeoPixel.h");
      translator.addDefinitionCommand("Adafruit_NeoPixel strip_pin"+Pin+" = Adafruit_NeoPixel("+NbLed+","+ Pin +", " +NEO_RGB+ " + "+NEO_KHZ800 +");");
      translator.addSetupCommand("strip_pin"+Pin+".begin();\n" +
      "strip_pin"+Pin+".show();");
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 dataBlock = this.getRequiredTranslatorBlockAtSocket(1);
    TranslatorBlock execBlock = this.getTranslatorBlockAtSocket(2);
    String exec = "";
    if(execBlock!=null){
      while (execBlock != null)
      {
        exec += "\t"+ execBlock.toCode()+"\n";
        execBlock = execBlock.nextTranslatorBlock();
      }
    }
    return dataBlock.toCode()+"= bluetooth"+block.toCode()+".read();\nif("+dataBlock.toCode()+">-1){\n\t"+exec+"\n}\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.