{"id":384,"date":"2023-05-12T08:45:26","date_gmt":"2023-05-12T08:45:26","guid":{"rendered":"https:\/\/blogsaverroes.juntadeandalucia.es\/industria4\/?p=384"},"modified":"2023-05-12T08:45:26","modified_gmt":"2023-05-12T08:45:26","slug":"codigo-de-la-maqueta-de-picasso","status":"publish","type":"post","link":"https:\/\/blogsaverroes.juntadeandalucia.es\/industria4\/2023\/05\/12\/codigo-de-la-maqueta-de-picasso\/","title":{"rendered":"C\u00f3digo de la maqueta de Picasso"},"content":{"rendered":"<p>Este es el c\u00f3digo de la placa desarrollada:<\/p>\n<p><code>#include \"DFRobotDFPlayerMini.h\"<\/code><br \/>\n<code>#include \"SoftwareSerial.h\"<\/code><\/p>\n<p><code>const int PIN_SENSOR = A0;<\/code><br \/>\n<code>SoftwareSerial mySoftwareSerial(D1, D2); \/\/ RX, TX<\/code><br \/>\n<code>DFRobotDFPlayerMini myDFPlayer;<\/code><\/p>\n<p><code>\/\/ Configuraciones de sensor<\/code><br \/>\n<code>const int UMBRAL = 300; \/\/ Umbral para que active o no<\/code><br \/>\n<code>unsigned int lecturaSENSOR = 0; \/\/ Estado inicial<\/code><\/p>\n<p><code>const int ANTIRREBOTE = 1000;<\/code><\/p>\n<p><code>boolean sensor_on = false; \/\/ Booleano para detectar activacion de sensor<\/code><br \/>\n<code>boolean play = false; \/\/ Booleano para saber si se esta reproduciendo<\/code><\/p>\n<p><code>void leerSENSOR() \/\/ Para realice lectura del sensor constantemente.<\/code><br \/>\n<code>{<\/code><br \/>\n<code>&nbsp; lecturaSENSOR = analogRead(PIN_SENSOR);<\/code><\/p>\n<p><code>&nbsp; if (lecturaSENSOR &gt; UMBRAL) {<\/code><br \/>\n<code>&nbsp; &nbsp; sensor_on = true;<\/code><br \/>\n<code>&nbsp; }<\/code><br \/>\n<code>}<\/code><\/p>\n<p><code>void setup() {<\/code><br \/>\n<code>&nbsp; pinMode(PIN_SENSOR, INPUT);<\/code><br \/>\n<code>&nbsp; mySoftwareSerial.begin(9600);<\/code><br \/>\n<code>&nbsp; Serial.begin(115200);<\/code><\/p>\n<p><code>&nbsp; Serial.println(\"SETUP\");<\/code><br \/>\n<code>&nbsp; Serial.println(F(\"Initializing DFPlayer ... (May take 3~5 seconds)\"));<\/code><\/p>\n<p><code>&nbsp; if (!myDFPlayer.begin(<\/code><code>mySoftwareSerial)) { \/\/ Use softwareSerial to communicate with mp3.<\/code><br \/>\n<code>&nbsp; &nbsp; Serial.println(F(\"Unable to begin:\"));<\/code><br \/>\n<code>&nbsp; &nbsp; Serial.println(F(\"1.Please recheck the connection!\"));<\/code><br \/>\n<code>&nbsp; &nbsp; Serial.println(F(\"2.Please insert the SD card!\"));<\/code><br \/>\n<code>&nbsp; &nbsp; while (true)<\/code><code>;<\/code><br \/>\n<code>&nbsp; }<\/code><br \/>\n<code>&nbsp; Serial.println(F(\"DFPlayer Mini online.\"));<\/code><\/p>\n<p><code>&nbsp; myDFPlayer.setTimeOut(500); \/\/ Set serial communication time out 500ms<\/code><\/p>\n<p><code>&nbsp; \/\/----Set volume----<\/code><br \/>\n<code>&nbsp; myDFPlayer.volume(25); \/\/ Set volume value (0~30).<\/code><br \/>\n<code>&nbsp; \/\/----Set different EQ----<\/code><br \/>\n<code>&nbsp; myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);<\/code><br \/>\n<code>&nbsp; \/\/----Set device we use SD as default----<\/code><br \/>\n<code>&nbsp; \/\/ myDFPlayer.outputDevice(DFPLAYER_DEVICE_U_DISK);<\/code><br \/>\n<code>&nbsp; myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);<\/code><br \/>\n<code>}<\/code><\/p>\n<p><code><\/code><br \/>\n<code>void loop() {<\/code><br \/>\n<code>&nbsp; leerSENSOR();<\/code><br \/>\n<code>&nbsp; if (sensor_on) {<\/code><br \/>\n<code>&nbsp; sensor_on = false;<\/code><br \/>\n<code>&nbsp; if (!play) {<\/code><br \/>\n<code>&nbsp; &nbsp; play = true;<\/code><br \/>\n<code>&nbsp; &nbsp; myDFPlayer.play(1); \/\/ Play the first mp3<\/code><br \/>\n<code>&nbsp; } else {<\/code><br \/>\n<code>&nbsp; &nbsp; play = false;<\/code><br \/>\n<code>&nbsp; &nbsp; myDFPlayer.pause(); \/\/ Pause mp3<\/code><br \/>\n<code>&nbsp; }<\/code><br \/>\n<code>&nbsp; &nbsp; delay(ANTIRREBOTE);<\/code><br \/>\n<code>&nbsp; }<\/code><br \/>\n<code>}<\/code><\/p>\n<!--themify_builder_content-->\n<div id=\"themify_builder_content-384\" data-postid=\"384\" class=\"themify_builder_content themify_builder_content-384 themify_builder tf_clear\">\n    <\/div>\n<!--\/themify_builder_content-->\n","protected":false},"excerpt":{"rendered":"<p>Este es el c\u00f3digo de la placa desarrollada: #include \u00abDFRobotDFPlayerMini.h\u00bb #include \u00abSoftwareSerial.h\u00bb const int PIN_SENSOR = A0; SoftwareSerial mySoftwareSerial(D1, D2); \/\/ RX, TX DFRobotDFPlayerMini myDFPlayer; \/\/ Configuraciones de sensor const int UMBRAL = 300; \/\/ Umbral para que active o no unsigned int lecturaSENSOR = 0; \/\/ Estado inicial const int ANTIRREBOTE = 1000; boolean [&hellip;]<\/p>\n","protected":false},"author":13840,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[1],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blogsaverroes.juntadeandalucia.es\/industria4\/wp-json\/wp\/v2\/posts\/384"}],"collection":[{"href":"https:\/\/blogsaverroes.juntadeandalucia.es\/industria4\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogsaverroes.juntadeandalucia.es\/industria4\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogsaverroes.juntadeandalucia.es\/industria4\/wp-json\/wp\/v2\/users\/13840"}],"replies":[{"embeddable":true,"href":"https:\/\/blogsaverroes.juntadeandalucia.es\/industria4\/wp-json\/wp\/v2\/comments?post=384"}],"version-history":[{"count":2,"href":"https:\/\/blogsaverroes.juntadeandalucia.es\/industria4\/wp-json\/wp\/v2\/posts\/384\/revisions"}],"predecessor-version":[{"id":386,"href":"https:\/\/blogsaverroes.juntadeandalucia.es\/industria4\/wp-json\/wp\/v2\/posts\/384\/revisions\/386"}],"wp:attachment":[{"href":"https:\/\/blogsaverroes.juntadeandalucia.es\/industria4\/wp-json\/wp\/v2\/media?parent=384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogsaverroes.juntadeandalucia.es\/industria4\/wp-json\/wp\/v2\/categories?post=384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogsaverroes.juntadeandalucia.es\/industria4\/wp-json\/wp\/v2\/tags?post=384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}