add soundsensor

This commit is contained in:
Mario 2020-12-21 11:22:54 +01:00
parent c52e9db4c8
commit 842b4522f0
5 changed files with 109 additions and 0 deletions

View File

@ -391,4 +391,39 @@ Blockly.Blocks['sensebox_sensor_watertemperature'] = {
this.setOutput(true, Types.NUMBER.typeName);
this.setTooltip(Blockly.Msg.senseBox_watertemperature_tip);
}
};
/**
* Windspeed
* removed for now
Blockly.Blocks['sensebox_windspeed'] = {
init: function () {
this.setColour(getColour().sensebox);
this.appendDummyInput()
.appendField(Blockly.Msg.senseBox_windspeed)
.appendField("Pin:")
.appendField(new Blockly.FieldDropdown(selectedBoard().analogPins), "PIN")
this.setOutput(true, Types.DECIMAL.typeName);
}
};
*/
/**
* DF Robot Soundsensor
*/
Blockly.Blocks['sensebox_soundsensor_dfrobot'] = {
init: function () {
var dropdownOptions = [[Blockly.Msg.senseBox_ultrasonic_port_A, 'A'],
[Blockly.Msg.senseBox_ultrasonic_port_B, 'B'], [Blockly.Msg.senseBox_ultrasonic_port_C, 'C']];
this.setColour(getColour().sensebox);
this.appendDummyInput()
.appendField(Blockly.Msg.senseBox_soundsensor_dfrobot)
.appendField("Port:")
.appendField(new Blockly.FieldDropdown(dropdownOptions), "Port")
this.setOutput(true, Types.DECIMAL.typeName);
}
};

View File

@ -398,4 +398,64 @@ Blockly.Arduino.sensebox_sensor_watertemperature = function () {
Blockly.Arduino.codeFunctions_['sensebox_requestTemp'] = 'float getWaterTemp(){\nsensors.requestTemperatures();\nsensors.getTempCByIndex(0);\n}';
var code = 'getWaterTemp()';
return [code, Blockly.Arduino.ORDER_ATOMIC];
};
/**
* Windspeed
* remove for now
Blockly.Arduino.sensebox_windspeed = function () {
var dropdown_pin = this.getFieldValue('PIN');
Blockly.Arduino.codeFunctions_['windspeed'] = `
float getWindspeed(){
float voltageWind = analogRead(`+ dropdown_pin + `) * (3.3 / 1024.0);
float windspeed = 0.0;
if (voltageWind >= 0.018){
float poly1 = pow(voltageWind, 3);
poly1 = 17.0359801998299 * poly1;
float poly2 = pow(voltageWind, 2);
poly2 = 47.9908168343362 * poly2;
float poly3 = 122.899677524413 * voltageWind;
float poly4 = 0.657504127272728;
windspeed = poly1 - poly2 + poly3 - poly4;
windspeed = windspeed * 0.2777777777777778; //conversion in m/s
}
return windspeed;
}`
var code = 'getWindspeed()';
return [code, Blockly.Arduino.ORDER_ATOMIC];
};
*/
/**
* DF Robot Soundsensor
*/
/**
*
*
*/
Blockly.Arduino.sensebox_soundsensor_dfrobot = function () {
var dropdown_port = this.getFieldValue('Port');
var dropdown_pin = 1;
if (dropdown_port === 'A') {
dropdown_pin = 1;
}
if (dropdown_port === 'B') {
dropdown_pin = 3;
}
if (dropdown_port === 'C') {
dropdown_pin = 5;
}
Blockly.Arduino.codeFunctions_['soundsensor'] = `
float getSoundValue(){
float v = analogRead(`+ dropdown_pin + `) * (3.3 / 1024.0);
float decibel = v * 50;
return decibel;
}`
var code = 'getSoundValue()';
return [code, Blockly.Arduino.ORDER_ATOMIC];
};

View File

@ -760,6 +760,12 @@ Blockly.Msg.senseBox_LoRa_sensor_tip = "Sende eine Sensorwert mit einer bestimmt
Blockly.Msg.senseBox_LoRa_init_abp_tip = "Initialisiere die LoRa übertragung. Kopiere die ID's im lsb Format";
Blockly.Msg.senseBox_LoRa_init_otaa_tip = "Initialisiere die LoRa übertragung. Kopiere die ID's im lsb Format";
//Windspeed
Blockly.Msg.senseBox_windspeed = "Windgeschwindigkeitssensor";
//Soundsensor
Blockly.Msg.senseBox_soundsensor_dfrobot = "Soundsensor (DF Robot)";
//BME680
Blockly.Msg.senseBox_bme680 = "Umweltsensor (BME680)";
Blockly.Msg.senseBox_bme_iaq = "Innenraumluftqualität (IAQ)";

View File

@ -782,6 +782,12 @@ Blockly.Msg.senseBox_mqtt_password = "Password";
Blockly.Msg.sensebox_mqtt_subscribe = "Subscribe to Feed"
Blockly.Msg.senseBox_mqtt_publish = "Publish to Feed/Topic";
//Windspeed
Blockly.Msg.senseBox_windspeed = "Windspeedsensor"
//Soundsensor
Blockly.Msg.senseBox_soundsensor_dfrobot = "Soundsensor (DF Robot)";
/**
* Add Translation for Blocks above
* ---------------------------------------------------------------

View File

@ -52,6 +52,8 @@ class Toolbox extends React.Component {
<Block type="sensebox_button" />
<Block type="sensebox_sensor_truebner_smt50" />
<Block type="sensebox_sensor_watertemperature" />
{/* <Block type="sensebox_windspeed" /> */}
<Block type="sensebox_soundsensor_dfrobot" />
</Category >
<Category name="WIFI" colour={getColour().sensebox}>
<Block type="sensebox_wifi" />