{"size": 3093, "ext": "js", "max_stars_repo_path": "generators/arduino/TCS3200.js", "max_stars_repo_name": "logix5/Blockyduino-para-MRTDuino", "max_stars_repo_stars_event_min_datetime": "2021-03-10T23:10:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-10T23:10:49.000Z", "max_issues_repo_path": "generators/arduino/TCS3200.js", "max_issues_repo_name": "logix5/Blockyduino-para-MRTDuino", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "generators/arduino/TCS3200.js", "max_forks_repo_name": "logix5/Blockyduino-para-MRTDuino", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 34.7528089888, "max_line_length": 139, "alphanum_fraction": 0.6136437116}
/***************************************************************
 *
 *  This module was created by Oscar Ferruz. oferruz@logix5.com
 *
 ****************************************************************/

goog.provide('Blockly.Blocks.TCS3200');

goog.require('Blockly.Blocks');

Blockly.Arduino['Init_ColorSensor_TCS3200'] = function(block) {
  
  var number = this.getFieldValue('SC_NUMBER');
  var s0_pin = this.getFieldValue('S0');
  var s1_pin = this.getFieldValue('S1');
  var s2_pin = this.getFieldValue('S2');
  var s3_pin = this.getFieldValue('S3');
  var out_pin = this.getFieldValue('OUT');
  var escale = this.getFieldValue('ESCALE');
  
  
Blockly.Arduino.definitions_['colorvariables'+number] = 'int red_'+number+'=0;\n'+ 'int green_'+number+'=0;\n'+ 'int blue_'+number+'=0;\n';
  
Blockly.Arduino.definitions_['readcolor'+number] ='void readcolor_'+number+'()\n'+
'  { \n'+   
'  digitalWrite('+s2_pin+', LOW); \n'+ 
'  digitalWrite('+s3_pin+', LOW); \n'+  
'  red_'+number+' = pulseIn('+out_pin+', digitalRead('+out_pin+') == HIGH ? LOW : HIGH); \n'+ 
'  digitalWrite('+s3_pin+', HIGH); \n'+  
'  blue_'+number+' = pulseIn('+out_pin+', digitalRead('+out_pin+') == HIGH ? LOW : HIGH); \n'+ 
'  digitalWrite('+s2_pin+', HIGH); \n'+   
'  green_'+number+' = pulseIn('+out_pin+', digitalRead('+out_pin+') == HIGH ? LOW : HIGH); \n'+ 
'}\n';
      
  Blockly.Arduino.setups_['setup_output_'+s0_pin] = 'pinMode('+s0_pin+', OUTPUT);';  
  Blockly.Arduino.setups_['setup_output_'+s1_pin] = 'pinMode('+s1_pin+', OUTPUT);';  
  Blockly.Arduino.setups_['setup_output_'+s2_pin] = 'pinMode('+s2_pin+', OUTPUT);';  
  Blockly.Arduino.setups_['setup_output_'+s3_pin] = 'pinMode('+s3_pin+', OUTPUT);';  
  Blockly.Arduino.setups_['setup_output_'+out_pin] = 'pinMode('+out_pin+', INPUT);';  
  
  if (escale=='1')
    Blockly.Arduino.setups_['digital_write_color_'+out_pin] = 'digitalWrite('+s0_pin+',LOW);\ndigitalWrite('+s1_pin+',LOW);\n ';  
   else if (escale=='2')
	   Blockly.Arduino.setups_['digital_write_color_'+out_pin] = 'digitalWrite('+s0_pin+',LOW);\ndigitalWrite('+s1_pin+',HIGH);\n ';
    else if (escale=='3')
		Blockly.Arduino.setups_['digital_write_color_'+out_pin] = 'digitalWrite('+s0_pin+',HIGH);\ndigitalWrite('+s1_pin+',LOW);\n ';
	 else
		Blockly.Arduino.setups_['digital_write_color_'+out_pin] = 'digitalWrite('+s0_pin+',HIGH);\ndigitalWrite('+s1_pin+',HIGH);\n ';
   	 	 
  var code='';
  return code;
};


Blockly.Arduino['order_to_read_tcs3200_values'] = function(block) {
	
  var number = this.getFieldValue('SC_NUMBER');
    
  var code = 'readcolor_'+number+'();\n'
   
  return code;
};

Blockly.Arduino['tcs3200_values'] = function(block) {
  
  var number = this.getFieldValue('SC_NUMBER');
  var typeColor = this.getFieldValue('TypeColor');
  var code;
 
  switch (typeColor) {
    case '0':
      code = 'red_'+number+'';
      break;
    case '1':
      code = 'green_'+number+'';
      break;
    case '2':
      code = 'blue_'+number+'';
      break;
    default:
			code = 'red_'+number+'';
			break;
  }
return [code, Blockly.Arduino.ORDER_ATOMIC];
 
};


