tag:blogger.com,1999:blog-30959183355019544412024-03-13T00:25:22.595-07:00Seven EmbeddedBlog dedicado al desarrollo de proyectos de hardware distintas plataformas micro-controladas y sistemas embebidosMaryori Sabalzahttp://www.blogger.com/profile/13211307381591319962noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-3095918335501954441.post-39047964162809863142016-11-11T14:15:00.002-08:002016-11-11T14:21:05.942-08:00<h2>
<b><br /></b><b>Tiva C Launchpad & Sensor ultrasonic HC-SR04</b></h2>
<div>
<b><br /></b></div>
<div>
<b>Materiales:</b></div>
<div>
<span style="background-color: white; color: #333333; font-family: "roboto" , "arial" , sans-serif; font-size: 13px;">-Tiva C serie TM4C123G</span><br />
<span style="background-color: white; color: #333333; font-family: "roboto" , "arial" , sans-serif; font-size: 13px;">-Ultrasonic Sensor HC-SR04</span></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<b>Conexiones necesarias entre el sensor y la tarjeta:</b><br />
<span style="background-color: white; color: #333333; font-family: "roboto" , "arial" , sans-serif; font-size: 13px;">-Pin 9: PA6</span><br />
<span style="background-color: white; color: #333333; font-family: "roboto" , "arial" , sans-serif; font-size: 13px;">-Pin 8: PA5</span><br />
<span style="background-color: white; color: #333333; font-family: "roboto" , "arial" , sans-serif; font-size: 13px;">-VCC</span><br />
<span style="background-color: white; color: #333333; font-family: "roboto" , "arial" , sans-serif; font-size: 13px;">-GND</span></div>
<div>
<b><br /></b></div>
<div>
<b><br /></b></div>
<div>
<b>Código:</b></div>
<div>
<b><br /></b></div>
<div>
<div style="font-weight: bold;">
/*</div>
<div style="font-weight: bold;">
Editado por Maryori Sabalza</div>
<div style="font-weight: bold;">
28 de Diciembre de 2015</div>
<div style="font-weight: bold;">
<br /></div>
<div style="font-weight: bold;">
*/</div>
<div style="font-weight: bold;">
<br /></div>
<div>
long distancia;</div>
<div>
long tiempo;</div>
<div>
void setup(){</div>
<div>
Serial.begin(9600);</div>
<div>
pinMode(9, OUTPUT); </div>
<div>
pinMode(8, INPUT); </div>
<div>
}</div>
<div>
<br /></div>
<div>
void loop(){</div>
<div>
digitalWrite(9,LOW); </div>
<div>
delayMicroseconds(5);</div>
<div>
digitalWrite(9, HIGH); </div>
<div>
delayMicroseconds(10);</div>
<div>
<br /></div>
<div>
tiempo=pulseIn(8, HIGH); /*Medicionde la longitud del pulso entrante. Mide el tiempo que transcurrido entre el envío del pulso ultrasónico y cuando el sensor recibe el rebote, es decir: desde que el pin 12 empieza a recibir el rebote, HIGH, hasta que deja de hacerlo, LOW, la longitud del pulso entrante*/</div>
<div>
<br /></div>
<div>
distancia= int(0.017*tiempo); /*fórmula para calcular la distancia obteniendo un valor entero*/</div>
<div>
/*Monitorización en centímetros por el monitor serial*/</div>
<div>
<br /></div>
<div>
Serial.println("Distancia ");</div>
<div>
Serial.println(distancia);</div>
<div>
Serial.println(" cm");</div>
<div>
delay(1000);</div>
<div>
}</div>
</div>
<div>
<b><br /></b></div>
<div>
<b><br /></b></div>
<div>
<b><br /></b></div>
<div>
<b><br /></b></div>
<div>
<b>Resultado:</b></div>
<div>
<b><br /></b></div>
<div>
<b><br /></b></div>
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/HVTYmqRnFtY/0.jpg" frameborder="0" height="266" src="https://www.youtube.com/embed/HVTYmqRnFtY?feature=player_embedded" width="320"></iframe></div>
Maryori Sabalzahttp://www.blogger.com/profile/13211307381591319962noreply@blogger.com0tag:blogger.com,1999:blog-3095918335501954441.post-29823220933100877322016-08-11T17:34:00.001-07:002016-08-11T17:40:36.057-07:00Max II EPM240T100C5 CPLD Altera- Music BuzzerHola!<br />
<br />
Decidí continuar probando el pequeño CPLD MAX II de Altera, hace algún tiempo probé con un blink de leds (aqui: <a href="http://maryorisabalza730.blogspot.com.co/2015/06/cpld-max-ii-blink-led.html">CPLDblinkled</a>) aprovechando los recursos web me encontré con un mega tutorial de fpga4fun, quienes con una pequeña FPGA realizan diferentes proyectos.<br />
<br />
Aprovechando los códigos de verilog del tutorial <a href="http://www.fpga4fun.com/MusicBox.html">MusicBox</a>, quise probarlos usando el MAX II.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhkWhAxCoJhE9dNQgrdrDGKXqv3Ar6rE09sBrnSL30Mga6XgzrrdfuhCu5nI0luAOQ7Ht99XVFdxGSuevW6x-lToB_Fw9QIJRNOraocFpyAtX2Hp8YG2QHHso7PYj6gyVtDvG1ZvzUvuw/s1600/epm240.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhkWhAxCoJhE9dNQgrdrDGKXqv3Ar6rE09sBrnSL30Mga6XgzrrdfuhCu5nI0luAOQ7Ht99XVFdxGSuevW6x-lToB_Fw9QIJRNOraocFpyAtX2Hp8YG2QHHso7PYj6gyVtDvG1ZvzUvuw/s320/epm240.jpg" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="background-color: white; color: #444444; font-family: "arial" , "tahoma" , "helvetica" , "freesans" , sans-serif; font-size: 13px; line-height: 18.2px;">Figura 1. MAX II EPM240T100C5, Altera</span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="background-color: white; color: #444444; font-family: "arial" , "tahoma" , "helvetica" , "freesans" , sans-serif; font-size: 13px; line-height: 18.2px;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="color: #444444; font-family: "arial" , "tahoma" , "helvetica" , "freesans" , sans-serif;"><span style="background-color: white; font-size: 13px; line-height: 18.2px;">Materiales: </span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="color: #444444; font-family: "arial" , "tahoma" , "helvetica" , "freesans" , sans-serif;"><span style="background-color: white; font-size: 13px; line-height: 18.2px;">-</span></span><span style="background-color: white; color: #444444; font-family: "arial" , "tahoma" , "helvetica" , "freesans" , sans-serif; font-size: 13px; line-height: 18.2px;">Buzzer</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="color: #444444; font-family: "arial" , "tahoma" , "helvetica" , "freesans" , sans-serif;"><span style="background-color: white; font-size: 13px; line-height: 18.2px;">-CPLD</span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="color: #444444; font-family: "arial" , "tahoma" , "helvetica" , "freesans" , sans-serif;"><span style="background-color: white; font-size: 13px; line-height: 18.2px;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="color: #444444; font-family: "arial" , "tahoma" , "helvetica" , "freesans" , sans-serif;"><span style="background-color: white;"><span style="font-size: 13px; line-height: 18.2px;">El resultado en el vídeo, a continuación:</span></span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="color: #444444; font-family: "arial" , "tahoma" , "helvetica" , "freesans" , sans-serif;"><span style="background-color: white;"><span style="font-size: 13px; line-height: 18.2px;"><br /></span></span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="color: #444444; font-family: "arial" , "tahoma" , "helvetica" , "freesans" , sans-serif;"><span style="background-color: white;"><span style="font-size: 13px; line-height: 18.2px;"><br /></span></span></span><iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/08HJfjhUbpY/0.jpg" frameborder="0" height="266" src="https://www.youtube.com/embed/08HJfjhUbpY?feature=player_embedded" width="320"></iframe></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="color: #444444; font-family: "arial" , "tahoma" , "helvetica" , "freesans" , sans-serif;"><span style="background-color: white; font-size: 13px; line-height: 18.2px;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="color: #444444; font-family: "arial" , "tahoma" , "helvetica" , "freesans" , sans-serif;"><span style="background-color: white; font-size: 13px; line-height: 18.2px;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="color: #444444; font-family: "arial" , "tahoma" , "helvetica" , "freesans" , sans-serif;"><span style="background-color: white; font-size: 13px; line-height: 18.2px;">Exitos!</span></span></div>
<br />Maryori Sabalzahttp://www.blogger.com/profile/13211307381591319962noreply@blogger.com0tag:blogger.com,1999:blog-3095918335501954441.post-11047462649234938172015-07-08T17:57:00.001-07:002015-07-08T17:58:01.101-07:00Tiva C launchpad Playing MusicHola!<br />
<br />
<br />
En este tutorial conectaremos a la Tiva C series TM4C123G un piezo eléctrico (Buzzer) para hacer sonar divertidas melodías.<br />
<br />
Materiales:<br />
<br />
-Buzzer<br />
-Tiva C launchpad<br />
-Resistencia de 220 ohm o aproximado<br />
<br />
Se interconectara el piezo de la siguiente manera a la tiva:<br />
<br />
La positiva a la resistencia y esta al pin PF2 que viene siendo el pin digital 40 y el otro lado se conecta a tierra, si al conectar no sabes cual es la tierra simple no sonara al cambiar la posición sonara.<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixjJNpi6uYRFaAUXmHf31PFdP_BVAGnafnAQMCdpoTn9m6TMIt2bszcLzlvO0R7H6Q6Zav0RPofF_e-bS8pw3kame5qadWA1fN3JEMxRz0OO6ruIoou5edq_4TttRsIeM13UdC5mW6VuU/s1600/piezo.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="170" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixjJNpi6uYRFaAUXmHf31PFdP_BVAGnafnAQMCdpoTn9m6TMIt2bszcLzlvO0R7H6Q6Zav0RPofF_e-bS8pw3kame5qadWA1fN3JEMxRz0OO6ruIoou5edq_4TttRsIeM13UdC5mW6VuU/s400/piezo.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="text-align: start;">Figura 1. Esquema de </span>conexión</div>
<br />
En este caso escucharemos las melodías:<br />
<br />
HBD- Cumpleaños feliz<br />
Konami contra- soundtrack videogame<br />
Imperial March- Star Wars<br />
Let It Be- The Beatles<br />
<br />
De los códigos 3 puedes encontrarlos en los ejemplos que trae el software Energía los cuales podrán modificar a su gusto<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkMYAlSPcLLeYJt-Nh8qP4xvg7wIuYdC4P1jKMJ8W-wKim2WRrGbV-c8BZi_m9zUZcQ344ngr0mofUuZuI5_djNeyHHoMnMjQR3n6o_6wvQbikul6PdDkzB8-tR6zH_peHaJBIlQkktFI/s1600/libreria.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="223" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkMYAlSPcLLeYJt-Nh8qP4xvg7wIuYdC4P1jKMJ8W-wKim2WRrGbV-c8BZi_m9zUZcQ344ngr0mofUuZuI5_djNeyHHoMnMjQR3n6o_6wvQbikul6PdDkzB8-tR6zH_peHaJBIlQkktFI/s400/libreria.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
Figura 2. Energía Examples</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
Y Let it be puedes hacer una adaptacion del tradicional hecho para Arduino <a href="http://forum.arduino.cc/index.php?topic=3309.0">http://forum.arduino.cc/index.php?topic=3309.0</a><br />
<br />
A continuación les dejo los que use y al final el vídeo de como funciona!<br />
<br />
<b>HBD</b><br />
<br />
<i>#include "pitches.h"</i><br />
<i>#define NOTE_C4_1 260</i><br />
<i><br /></i>
<i>int buzzerPin = 40;</i><br />
<i><br /></i>
<i>// notes in the melody:</i><br />
<i>int melody[] = {</i><br />
<i> NOTE_C4_1,NOTE_C4, NOTE_D4, NOTE_C4,NOTE_F4,NOTE_E4,</i><br />
<i> NOTE_C4_1,NOTE_C4,NOTE_D4,NOTE_C4,NOTE_G4,NOTE_F4,</i><br />
<i> NOTE_C4_1,NOTE_C4,NOTE_C5,NOTE_A4,NOTE_F4,NOTE_F4, NOTE_E4,NOTE_D4,</i><br />
<i> NOTE_AS4,NOTE_AS4,NOTE_A4,NOTE_F4,NOTE_G4,NOTE_F4};</i><br />
<i> </i><br />
<i>// note durations: 4 = quarter note, 8 = eighth note, etc.:</i><br />
<i>int noteDurations[] = {</i><br />
<i> 4, 4, 2, 2,2,1,</i><br />
<i> 4, 4, 2, 2,2,1,</i><br />
<i> 4, 4, 2, 2,4,4,2,1, </i><br />
<i> 4, 4, 2, 2,2,1};</i><br />
<i><br /></i>
<i>void setup() </i><br />
<i>{</i><br />
<i>pinMode(buzzerPin,OUTPUT);</i><br />
<i>}</i><br />
<i>void loop() </i><br />
<i>{</i><br />
<i> for (int thisNote = 0; thisNote < 26; thisNote++) {</i><br />
<i><br /></i>
<i> // to calculate the note duration, take one second </i><br />
<i> // divided by the note type.</i><br />
<i> //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.</i><br />
<i> int noteDuration = 1000/noteDurations[thisNote];</i><br />
<i> tone(buzzerPin, melody[thisNote],noteDuration);</i><br />
<i><br /></i>
<i> int pauseBetweenNotes = noteDuration + 50; //delay between pulse</i><br />
<i> delay(pauseBetweenNotes);</i><br />
<i> </i><br />
<i> noTone(buzzerPin); // stop the tone playing</i><br />
<i> }</i><br />
<i>}</i><br />
<div>
<br /></div>
<div>
<br /></div>
<br />
<b>Konami contra:</b><br />
<br />
<i>#include "pitches.h"</i><br />
<i><br /></i>
<i><br /></i>
<i>int buzzerPin = 40;</i><br />
<i><br /></i>
<br />
<i>// notes in the melody:</i><br />
<i>int melody[] = {</i><br />
<i> NOTE_F2, NOTE_C6, NOTE_B5, NOTE_G5, NOTE_A5, NOTE_E1, NOTE_B1, NOTE_E1, NOTE_B1, NOTE_E1, NOTE_B1, </i><br />
<i> </i><br />
<i> </i><br />
<i> NOTE_G6, NOTE_F6, NOTE_DS6, NOTE_C6, NOTE_AS5, NOTE_C6, NOTE_AS5, NOTE_GS5, NOTE_G5, NOTE_GS5, </i><br />
<i> NOTE_G5, NOTE_F5, NOTE_DS5, NOTE_F5, NOTE_AS4, NOTE_C5, NOTE_DS5, NOTE_F5,</i><br />
<i> </i><br />
<i> NOTE_C6, NOTE_NOTONE, NOTE_AS5, NOTE_C6, NOTE_D6, NOTE_DS6, NOTE_F5,</i><br />
<i> NOTE_C6, NOTE_NOTONE, NOTE_AS5, NOTE_C6, NOTE_D6, NOTE_GS5, NOTE_F5,</i><br />
<i><br /></i>
<i>// Repeat once </i><br />
<i> NOTE_C6, NOTE_NOTONE, NOTE_AS5, NOTE_C6, NOTE_D6, NOTE_DS6, NOTE_F5,</i><br />
<i> NOTE_C6, NOTE_NOTONE, NOTE_AS5, NOTE_C6, NOTE_D6, NOTE_GS5, NOTE_F5,</i><br />
<i><br /></i>
<i> NOTE_C6, NOTE_NOTONE, NOTE_C6, NOTE_D6, NOTE_DS6, NOTE_NOTONE, NOTE_DS6, NOTE_NOTONE,</i><br />
<i> NOTE_G5, NOTE_AS5, NOTE_C6, NOTE_D6, NOTE_NOTONE, NOTE_D6, NOTE_DS6,</i><br />
<i> </i><br />
<i> NOTE_C6, NOTE_NOTONE, NOTE_C6, NOTE_NOTONE, NOTE_DS6, NOTE_F6</i><br />
<i> </i><br />
<i> </i><br />
<i>};</i><br />
<i> </i><br />
<i>// note durations: 4 = quarter note, 8 = eighth note, etc.:</i><br />
<i>int noteDurations[] = {</i><br />
<i>2, 2, 2, 2,1, 2, 2, 2, 2, 2, 1, // 11 start screen notes</i><br />
<i><br /></i>
<i><br /></i>
<i><br /></i>
<i>16, 16, 16, 16, 16, 16, 16, 16, 16, 16, // 20 notes</i><br />
<i>16, 16, 16, 16, 16, 16, 16, 2, // for both lines </i><br />
<i><br /></i>
<i>16, 16, 16, 8, 16, 2, 2, // 7</i><br />
<i>16, 16, 16, 8, 16, 2, 2, // 7</i><br />
<i><br /></i>
<i>// Repeat once</i><br />
<i>16, 16, 16, 8, 16, 2, 2, // 7</i><br />
<i>16, 16, 16, 8, 16, 2, 2, // 7</i><br />
<i><br /></i>
<i>16, 16, 4, 4, 16, 16, 16, 8, // 8</i><br />
<i>16, 16, 16, 16, 16, 4, 4, // 7</i><br />
<i><br /></i>
<i>16, 16, 16, 16, 16, 4 // 6 </i><br />
<i><br /></i>
<i>};</i><br />
<i><br /></i>
<i>void setup() </i><br />
<i>{</i><br />
<i>pinMode(buzzerPin,OUTPUT);</i><br />
<i>}</i><br />
<i>void loop() </i><br />
<i>{</i><br />
<i> for (int thisNote = 0; thisNote < 80; thisNote++) {</i><br />
<i><br /></i>
<i> // to calculate the note duration, take one second </i><br />
<i> // divided by the note type.</i><br />
<i> //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.</i><br />
<i> // Had to down tempo to 100/150 </i><br />
<i> int noteDuration = 1500/noteDurations[thisNote];</i><br />
<i> tone(buzzerPin, melody[thisNote],noteDuration);</i><br />
<i><br /></i>
<i> int pauseBetweenNotes = noteDuration + 50; //delay between pulse</i><br />
<i> delay(pauseBetweenNotes);</i><br />
<i> </i><br />
<i> noTone(buzzerPin); // stop the tone playing</i><br />
<i> }</i><br />
<i>}</i><br />
<br />
<b>Star Wars</b><br />
<br />
<i><br /></i>
<i>#include "pitches.h"</i><br />
<i>#define cc 261</i><br />
<i>#define dd 294</i><br />
<i>#define ee 329</i><br />
<i>#define ff 349</i><br />
<i>#define g 391</i><br />
<i>#define gS 415</i><br />
<i>#define a 440</i><br />
<i>#define aS 455</i><br />
<i>#define b 466</i><br />
<i>#define cH 523</i><br />
<i>#define cSH 554</i><br />
<i>#define dH 587</i><br />
<i>#define dSH 622</i><br />
<i>#define eH 659</i><br />
<i>#define fH 698</i><br />
<i>#define fSH 740</i><br />
<i>#define gH 784</i><br />
<i>#define gSH 830</i><br />
<i>#define aH 880</i><br />
<i><br /></i>
<i>int buzzerPin = 40;</i><br />
<i><br /></i>
<i>void beep(int note, int duration)</i><br />
<i>{</i><br />
<i> tone(buzzerPin, note, duration/2);</i><br />
<i> delay(duration/2);</i><br />
<i> noTone(buzzerPin);</i><br />
<i> delay(duration/2 + 20); </i><br />
<i>}</i><br />
<i>void setup() </i><br />
<i>{</i><br />
<i>pinMode(buzzerPin,OUTPUT);</i><br />
<i>}</i><br />
<i>void loop() </i><br />
<i>{</i><br />
<i> beep(a, 500);</i><br />
<i>beep(a, 500);</i><br />
<i>beep(a, 500);</i><br />
<i>beep(ff, 350);</i><br />
<i>beep(cH, 150); </i><br />
<i>beep(a, 500);</i><br />
<i>beep(ff, 350);</i><br />
<i>beep(cH, 150);</i><br />
<i>beep(a, 650);</i><br />
<br />
<i> delay(150);</i><br />
<i> //end of first bit </i><br />
<br />
<i>beep(eH, 500);</i><br />
<i>beep(eH, 500);</i><br />
<i>beep(eH, 500); </i><br />
<i>beep(fH, 350);</i><br />
<i>beep(cH, 150);</i><br />
<i>beep(gS, 500);</i><br />
<i>beep(ff, 350);</i><br />
<i>beep(cH, 150);</i><br />
<i>beep(a, 650);</i><br />
<br />
<i> delay(150);</i><br />
<i> //end of second bit... </i><br />
<br />
<i>beep(aH, 500);</i><br />
<i>beep(a, 300);</i><br />
<i>beep(a, 150);</i><br />
<i>beep(aH, 400);</i><br />
<i>beep(gSH, 200);</i><br />
<i>beep(gH, 200); </i><br />
<i>beep(fSH, 125);</i><br />
<i>beep(fH, 125); </i><br />
<i>beep(fSH, 250);</i><br />
<br />
<i> delay(250);</i><br />
<br />
<i>beep(aS, 250); </i><br />
<i>beep(dSH, 400); </i><br />
<i>beep(dH, 200); </i><br />
<i>beep(cSH, 200); </i><br />
<i>beep(cH, 125); </i><br />
<i>beep(b, 125); </i><br />
<i>beep(cH, 250); </i><br />
<br />
<i> delay(250);</i><br />
<br />
<i>beep(ff, 125); </i><br />
<i>beep(gS, 500); </i><br />
<i>beep(ff, 375); </i><br />
<i>beep(a, 125);</i><br />
<i>beep(cH, 500);</i><br />
<i>beep(a, 375); </i><br />
<i>beep(cH, 125);</i><br />
<i>beep(eH, 650);</i><br />
<i><br /></i>
<br />
<i>beep(aH, 500);</i><br />
<i>beep(a, 300);</i><br />
<i>beep(a, 150);</i><br />
<i>beep(aH, 400);</i><br />
<i>beep(gSH, 200);</i><br />
<i>beep(gH, 200);</i><br />
<i>beep(fSH, 125);</i><br />
<i>beep(fH, 125); </i><br />
<i>beep(fSH, 250);</i><br />
<br />
<i> delay(250);</i><br />
<br />
<i>beep(aS, 250); </i><br />
<i>beep(dSH, 400); </i><br />
<i>beep(dH, 200); </i><br />
<i>beep(cSH, 200); </i><br />
<i>beep(cH, 125); </i><br />
<i>beep(b, 125); </i><br />
<i>beep(cH, 250); </i><br />
<br />
<i> delay(250);</i><br />
<br />
<i>beep(ff, 250); </i><br />
<i>beep(gS, 500); </i><br />
<i>beep(ff, 375); </i><br />
<i>beep(cH, 125);</i><br />
<i>beep(a, 500); </i><br />
<i>beep(ff, 375); </i><br />
<i>beep(cH, 125); </i><br />
<i>beep(a, 650); </i><br />
<i> //end of the song</i><br />
<i> //end of the song</i><br />
<i>}</i><br />
<div>
<br /></div>
<div>
<b>Let it Be</b></div>
<div>
<br /></div>
<div>
<div>
<i><br /></i></div>
<div>
<i>int speakerPin = 40;</i></div>
<div>
<i><br /></i></div>
<div>
<i>int length = 56; // the number of notes</i></div>
<div>
<i>char notes[] = "ggaeggCDEEEDDCC gEEFEED EDDC EDCEGAGGEDCagE EEEFEED EDDC"; // a space represents a rest</i></div>
<div>
<i>int beats[] = { 2, 1, 2, 2, 3, 2, 1, 2, 1, 1, 4, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 1, 1, 2, 2, 8, 1, 2, 5, 1, 2, 5, 1, 1, 1, 1, 4, 1, 2, 5, 5, 1, 1, 1, 2, 1, 1, 4, 1, 1, 1, 2, 2};</i></div>
<div>
<i>int tempo = 200;</i></div>
<div>
<i><br /></i></div>
<div>
<i>void playTone(int tone, int duration) {</i></div>
<div>
<i> for (long i = 0; i < duration * 1000L; i += tone * 2) {</i></div>
<div>
<i> digitalWrite(speakerPin, HIGH);</i></div>
<div>
<i> delayMicroseconds(tone);</i></div>
<div>
<i> digitalWrite(speakerPin, LOW);</i></div>
<div>
<i> delayMicroseconds(tone);</i></div>
<div>
<i> }</i></div>
<div>
<i>}</i></div>
<div>
<i><br /></i></div>
<div>
<i>void playNote(char note, int duration) {</i></div>
<div>
<i> char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', 'D', 'E', 'F', 'G', 'A', 'B' };</i></div>
<div>
<i> int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 851, 760, 716, 628, 568, 507 };</i></div>
<div>
<i> </i></div>
<div>
<i> // play the tone corresponding to the note name</i></div>
<div>
<i> for (int i = 0; i < 14; i++) {</i></div>
<div>
<i> if (names[i] == note) {</i></div>
<div>
<i> playTone(tones[i], duration);</i></div>
<div>
<i> }</i></div>
<div>
<i> }</i></div>
<div>
<i>}</i></div>
<div>
<i><br /></i></div>
<div>
<i>void setup() {</i></div>
<div>
<i> pinMode(speakerPin, OUTPUT);</i></div>
<div>
<i>}</i></div>
<div>
<i><br /></i></div>
<div>
<i>void loop() {</i></div>
<div>
<i> for (int i = 0; i < length; i++) {</i></div>
<div>
<i> if (notes[i] == ' ') {</i></div>
<div>
<i> delay(beats[i] * tempo); // rest</i></div>
<div>
<i> } else {</i></div>
<div>
<i> playNote(notes[i], beats[i] * tempo);</i></div>
<div>
<i> }</i></div>
<div>
<i> </i></div>
<div>
<i> // pause between notes</i></div>
<div>
<i> delay(tempo / 2); </i></div>
<div>
<i> }</i></div>
<div>
<i>}</i></div>
</div>
<div>
<i><br /></i></div>
<div class="separator" style="clear: both; text-align: center;">
<iframe width="320" height="266" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/jrvzyuDtZsE/0.jpg" src="https://www.youtube.com/embed/jrvzyuDtZsE?feature=player_embedded" frameborder="0" allowfullscreen></iframe></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
ÉXITOS!</div>
<div>
<br /></div>
<div>
<br /></div>
<div style="text-align: center;">
<span style="color: red;"><i>Maryori Sabalza Mejía </i></span></div>
<div style="text-align: center;">
<span style="color: red;"><i>Cartagena-Colombia</i></span></div>
<br />
<br />
<br />
<br />
<br />
<br />Maryori Sabalzahttp://www.blogger.com/profile/13211307381591319962noreply@blogger.com1tag:blogger.com,1999:blog-3095918335501954441.post-61589836530439534032015-06-27T09:50:00.000-07:002015-06-27T09:50:25.079-07:00CPLD Max II Blink Led<br />
¡Hola!<br />
<br />
<div style="text-align: justify;">
Los novedosos CPLD que se están empezando a usar no solo por su fácil acceso y costo, sino también que en esta tarjetita permite analizar y comprobar laboratorios.</div>
<div style="text-align: justify;">
En esta ocasión encenderemos un led conectado a esta tarjeta.</div>
<div style="text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVjacz_hjeU8nQ1o5gD9Sg8CBHY2_w18XEmG0WCgNUadOAzmDeBqAO8E7txDx46RSa7exMpnVy2iNuLlbC5zhXGAWR3Z399XJgCSp29wqY4dndtR9jMStpzFY-5Y6IfGPMGr-qR7hwhtw/s1600/epm240.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVjacz_hjeU8nQ1o5gD9Sg8CBHY2_w18XEmG0WCgNUadOAzmDeBqAO8E7txDx46RSa7exMpnVy2iNuLlbC5zhXGAWR3Z399XJgCSp29wqY4dndtR9jMStpzFY-5Y6IfGPMGr-qR7hwhtw/s320/epm240.jpg" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
Figura 1. MAX II EPM240, Altera</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
El código a implementar para un led usando Verilog es el siguiente:</div>
<div class="separator" style="clear: both; text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<i>module ledblink(clk,led);</i></div>
<div class="separator" style="clear: both; text-align: left;">
<i>input clk;</i></div>
<div class="separator" style="clear: both; text-align: left;">
<i>output led;</i></div>
<div class="separator" style="clear: both; text-align: left;">
<i>reg led;</i></div>
<div class="separator" style="clear: both; text-align: left;">
<i><br /></i></div>
<div class="separator" style="clear: both; text-align: left;">
<i>reg[23:0] cnt;</i></div>
<div class="separator" style="clear: both; text-align: left;">
<i><br /></i></div>
<div class="separator" style="clear: both; text-align: left;">
<i>always @(posedge clk) begin </i></div>
<div class="separator" style="clear: both; text-align: left;">
<i> cnt<= cnt + 1'b1; </i></div>
<div class="separator" style="clear: both; text-align: left;">
<i> led<=cnt[23];</i></div>
<div class="separator" style="clear: both; text-align: left;">
<i>end</i></div>
<div class="separator" style="clear: both; text-align: left;">
<i><br /></i></div>
<div class="separator" style="clear: both; text-align: left;">
<i>endmodule </i></div>
<div class="separator" style="clear: both; text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
Ahora para conectar el pin buscamos en el datasheet: <a href="https://www.altera.com/content/dam/altera-www/global/en_US/pdfs/literature/dp/max2/epm240.pdf">Datasheet EPM240</a></div>
<div class="separator" style="clear: both; text-align: justify;">
Podemos probar con el Pin_B1 ya programar debe funcionar.</div>
<div class="separator" style="clear: both; text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibNe-0nrJdlbx1sLmWISXSvoNoz3Fmf5_4lo5z4uf1vUg_TsuekIp8t4qD-WgpWD7rKMuZkdDBFG6CPT2gODUs23qCO_xEGlfI0I2QfwuogxHz8ssuDQkn_PFd9zMmRZThjVeIFmbR1C4/s1600/pin.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="170" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibNe-0nrJdlbx1sLmWISXSvoNoz3Fmf5_4lo5z4uf1vUg_TsuekIp8t4qD-WgpWD7rKMuZkdDBFG6CPT2gODUs23qCO_xEGlfI0I2QfwuogxHz8ssuDQkn_PFd9zMmRZThjVeIFmbR1C4/s320/pin.jpg" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
Figura 2. Pin planner</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
Ahora si en vez de 1 sean 3 o mas leds se debe modificar el código de la siguiente manera y asignar otros pines:</div>
<div class="separator" style="clear: both; text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDERU-fmR9G7MLWzs0OcEbwYFp0Pbmqa9KLzgdiWmkZOaojD3uQ5-AE1BETft2oiu6Fcb5ztJJlFtRInH1jJH8pxMQLkpf9OKAjHRLAxoaLnB2puDl52a4UjAxALXNcaf8DvkvJZtBOJ4/s1600/3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="211" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDERU-fmR9G7MLWzs0OcEbwYFp0Pbmqa9KLzgdiWmkZOaojD3uQ5-AE1BETft2oiu6Fcb5ztJJlFtRInH1jJH8pxMQLkpf9OKAjHRLAxoaLnB2puDl52a4UjAxALXNcaf8DvkvJZtBOJ4/s400/3.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
Figura 3. Blink 3 Leds y pin planer</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
Y luego de programar debemos ver algo así: </div>
<div class="separator" style="clear: both; text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<iframe width="320" height="266" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/PZy8exwSGA4/0.jpg" src="https://www.youtube.com/embed/PZy8exwSGA4?feature=player_embedded" frameborder="0" allowfullscreen></iframe></div>
<div class="separator" style="clear: both; text-align: justify;">
Éxitos.</div>
<div class="separator" style="clear: both; text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="color: red;"><i>Maryori Sabalza Mejía</i></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="color: red;"><i>Cartagena-Colombia</i></span></div>
<div class="separator" style="clear: both; text-align: justify;">
<br /></div>
<br />Maryori Sabalzahttp://www.blogger.com/profile/13211307381591319962noreply@blogger.com2tag:blogger.com,1999:blog-3095918335501954441.post-36874935694739088182015-06-23T22:25:00.001-07:002015-06-27T09:14:36.247-07:00I2C Arduino uno & Tiva C launchpad comunicandose<div style="text-align: center;">
<br /></div>
<div style="text-align: justify;">
<span style="text-align: right;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>¡Hola!</b></span></span></div>
<div style="text-align: justify;">
<span style="text-align: right;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b><br /></b></span></span></div>
<div style="text-align: justify;">
En este tutorial mostrare a el Arduino uno hablándole a la Tiva c launcpad de TI quien le enviara un carácter de respuesta a Arduino, Para que esto suceda debemos trabajar con el protocolo de comunicación I2C que es una comunicación en serie para ínter circuitos integrados.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGbo2sAAHkU5I39DfB9MDjOkcWdxqud7UsC76iDaZdwqt7hjmp7ng82FCsna4Z7ScdJvtSgYsLSKRD5-T2E9DSezIipSicUBSpnzMQPi3tnZRz_WDsRL7Z1VqdpMzQiswExI1JzvMh0O8/s1600/425px-I2C.svg+%25281%2529.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="112" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGbo2sAAHkU5I39DfB9MDjOkcWdxqud7UsC76iDaZdwqt7hjmp7ng82FCsna4Z7ScdJvtSgYsLSKRD5-T2E9DSezIipSicUBSpnzMQPi3tnZRz_WDsRL7Z1VqdpMzQiswExI1JzvMh0O8/s320/425px-I2C.svg+%25281%2529.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
Figura 1. I2C (from Wikipedia)</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Materiales:</div>
<div style="text-align: justify;">
-Tiva C launchpad</div>
<div style="text-align: justify;">
-Arduino uno</div>
<div style="text-align: justify;">
-cables</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Se deben interconectar los SDA Y SCL que son por viajan los datos y el reloj que llevan estos, tambien se deben conectar tierra entre las 2 placas.</div>
<div style="text-align: justify;">
Para el caso de la tiva: </div>
<div style="text-align: justify;">
SDA:PD1 SCL: PD0</div>
<div style="text-align: justify;">
mientras que para arduino: </div>
<div style="text-align: justify;">
SDA: A4 SCL:A5<br />
<br />
<br /></div>
<div style="text-align: justify;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4D_6_N_n87ris_cCcLzEH1furgBa7wK6TiEQN99gaYXqsCh4Bdd-Ngs1GrkdT8KL2Z3cfkOzqGpCNFsOrZrGJL51mvP4wdd6TavWIATMBWzt1mkjMulDvX6UsWo49IoJzeUEQOPwRUgI/s1600/diagrama.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="131" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4D_6_N_n87ris_cCcLzEH1furgBa7wK6TiEQN99gaYXqsCh4Bdd-Ngs1GrkdT8KL2Z3cfkOzqGpCNFsOrZrGJL51mvP4wdd6TavWIATMBWzt1mkjMulDvX6UsWo49IoJzeUEQOPwRUgI/s320/diagrama.png" width="320" /></a></div>
<br /></div>
<div style="text-align: justify;">
<span style="text-align: center;"> Figura 2. Diagrama del sistema</span></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Gracias a la libreria <a href="https://www.arduino.cc/en/Reference/Wire">Wire.h</a> que la traen las 2 placas haremos posible la comunicación entre estas.</div>
<div style="text-align: justify;">
Se usara el master-write con el slave-receiver y el master-reader con el slave-sender.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<span style="text-align: center;"><br /></span>
<span style="text-align: center;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOAkaPqvYU2vc6tXdp7dbtOakfmDQp_mVQss_NXpfHG2sASGCkrZ-hELlUvZwGtOjz1nwnY_d7aGmAQvZt0IhR-mJxsmmcYgyj-SKYOUeESMdidPorkI1fRkrQ1ytkPTmDWZmJCySdqDo/s1600/tivai2c.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="179" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOAkaPqvYU2vc6tXdp7dbtOakfmDQp_mVQss_NXpfHG2sASGCkrZ-hELlUvZwGtOjz1nwnY_d7aGmAQvZt0IhR-mJxsmmcYgyj-SKYOUeESMdidPorkI1fRkrQ1ytkPTmDWZmJCySdqDo/s320/tivai2c.jpg" width="320" /></a></div>
<span style="text-align: center;"><br /></span>
<span style="text-align: center;"> Figura 3. Programas a usar</span></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Al final en el siguiente video se muestra como deberia trabajar este sistema:</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/73FeIL-TJg4/0.jpg" frameborder="0" height="266" src="https://www.youtube.com/embed/73FeIL-TJg4?feature=player_embedded" width="320"></iframe></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Éxitos.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: center;">
<span style="color: red;"><i>Maryori Sabalza Mejía</i></span></div>
<div style="text-align: center;">
<span style="color: red;"><i>Cartagena-Colombia</i></span></div>
<div style="text-align: justify;">
<br /></div>
Maryori Sabalzahttp://www.blogger.com/profile/13211307381591319962noreply@blogger.com0tag:blogger.com,1999:blog-3095918335501954441.post-11486664934961849222015-06-23T19:25:00.001-07:002015-06-27T09:14:58.633-07:00BarGraph Arduino uno<iframe frameborder="0" height="400" marginheight="0" marginwidth="0" scrolling="no" src="https://www.slideshare.net/slideshow/embed_code/key/IUWMNSLWILpyNq" width="476"></iframe>
Maryori Sabalzahttp://www.blogger.com/profile/13211307381591319962noreply@blogger.com0tag:blogger.com,1999:blog-3095918335501954441.post-40619391527604776732015-06-23T18:05:00.001-07:002015-06-27T09:15:19.215-07:00BarGraph Tiva C series Launchpad<br />
<div style="text-align: center;">
Tiva C series Launchpad-BarGraph</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: justify;">
Hola! en este primera entrada del blog les mostrare como hacer la prueba del bargraph usando leds y un potenciometro al igual que se hace en Arduino uno.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Materiales:</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
-Tiva C serie TM4C123g</div>
<div style="text-align: justify;">
-Led's (use 8)</div>
<div style="text-align: justify;">
-Resistencias 470 ohm (mismo numero de los leds usados)</div>
<div style="text-align: justify;">
-Potenciometro 10 Kohm</div>
<div style="text-align: justify;">
-Protoboard</div>
<div style="text-align: justify;">
-Cables</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
La primera conexion que se debe hacer es la del potenciometro de la siguiente manera:</div>
<div style="text-align: justify;">
<br />
A0=PE3<br />
GND<br />
5V=VBUS</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEDOy3HtKpMNanN-DbtSvnf8NHSGlitqhS8pO_Xcs5n37LKFjAkhnNcOTki-lK9ybqofvaQGaugdV5LtJUkq_tUqhQ6NrWRAQNyMrIs9pT1J_eUX6Bs1mH4d-1OS-xi97xlIZvfB9bTns/s1600/TIVApotenciometro.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="219" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEDOy3HtKpMNanN-DbtSvnf8NHSGlitqhS8pO_Xcs5n37LKFjAkhnNcOTki-lK9ybqofvaQGaugdV5LtJUkq_tUqhQ6NrWRAQNyMrIs9pT1J_eUX6Bs1mH4d-1OS-xi97xlIZvfB9bTns/s320/TIVApotenciometro.jpg" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
Figura 1. Conexion del Potenciometro con la Tiva C</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
Ahora el codigo a usar sera: File-Examples-display-barGraph.</div>
<div class="separator" style="clear: both; text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghiHOvCiOzuN7d68hv7dF_l_cpBfc-OaoIzK_coAbPM14-d1JUoEwVz87Ti8xcLJ_the1NX2dJ9Ez3rBRnJLz8EgO0G-2mYZSYk0Qj27D0_pTSk0JJ7eYUFJFQkeNkVgUN_gRl5hVUBuY/s1600/bg2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghiHOvCiOzuN7d68hv7dF_l_cpBfc-OaoIzK_coAbPM14-d1JUoEwVz87Ti8xcLJ_the1NX2dJ9Ez3rBRnJLz8EgO0G-2mYZSYk0Qj27D0_pTSk0JJ7eYUFJFQkeNkVgUN_gRl5hVUBuY/s400/bg2.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
Figura 2. Programa básico</div>
<div class="separator" style="clear: both; text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Y el codigo incluyendo los 8 leds y el pin analogo A0:</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
// these constants won't change:</div>
<div style="text-align: justify;">
const int analogPin = 29; // the pin that the potentiometer is attached to</div>
<div style="text-align: justify;">
const int ledCount = 8; // the number of LEDs in the bar graph</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
int ledPins[] = { 4, 5, 6, 7,8,9,10,13 }; // an array of pin numbers to which LEDs are attached</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
const int numReadings = 8;</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
int readings[numReadings]; // the readings from the analog input</div>
<div style="text-align: justify;">
int index = 0; // the index of the current reading</div>
<div style="text-align: justify;">
int total = 0; // the running total</div>
<div style="text-align: justify;">
int average = 0; // the average</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
int inputPin = A0;</div>
<div style="text-align: justify;">
void setup() {</div>
<div style="text-align: justify;">
// loop over the pin array and set them all to output:</div>
<div style="text-align: justify;">
for (int thisLed = 0; thisLed < ledCount; thisLed++) {</div>
<div style="text-align: justify;">
pinMode(ledPins[thisLed], OUTPUT); </div>
<div style="text-align: justify;">
}</div>
<div style="text-align: justify;">
// initialize serial communication with computer:</div>
<div style="text-align: justify;">
Serial.begin(9600); </div>
<div style="text-align: justify;">
// initialize all the readings to 0: </div>
<div style="text-align: justify;">
for (int thisReading = 0; thisReading < numReadings; thisReading++)</div>
<div style="text-align: justify;">
readings[thisReading] = 0; </div>
<div style="text-align: justify;">
}</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
void loop() {</div>
<div style="text-align: justify;">
// read the potentiometer:</div>
<div style="text-align: justify;">
int sensorReading = analogRead(analogPin);</div>
<div style="text-align: justify;">
// map the result to a range from 0 to the number of LEDs:</div>
<div style="text-align: justify;">
int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
// loop over the LED array:</div>
<div style="text-align: justify;">
for (int thisLed = 0; thisLed < ledCount; thisLed++) {</div>
<div style="text-align: justify;">
// if the array element's index is less than ledLevel,</div>
<div style="text-align: justify;">
// turn the pin for this element on:</div>
<div style="text-align: justify;">
if (thisLed < ledLevel) {</div>
<div style="text-align: justify;">
digitalWrite(ledPins[thisLed], HIGH);</div>
<div style="text-align: justify;">
} </div>
<div style="text-align: justify;">
// turn off all pins higher than the ledLevel:</div>
<div style="text-align: justify;">
else {</div>
<div style="text-align: justify;">
digitalWrite(ledPins[thisLed], LOW); </div>
<div style="text-align: justify;">
}</div>
<div style="text-align: justify;">
}</div>
<div style="text-align: justify;">
</div>
<div style="text-align: justify;">
// subtract the last reading:</div>
<div style="text-align: justify;">
total= total - readings[index]; </div>
<div style="text-align: justify;">
// read from the sensor: </div>
<div style="text-align: justify;">
readings[index] = analogRead(inputPin); </div>
<div style="text-align: justify;">
// add the reading to the total:</div>
<div style="text-align: justify;">
total= total + readings[index]; </div>
<div style="text-align: justify;">
// advance to the next position in the array: </div>
<div style="text-align: justify;">
index = index + 1; </div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
// if we're at the end of the array...</div>
<div style="text-align: justify;">
if (index >= numReadings) </div>
<div style="text-align: justify;">
// ...wrap around to the beginning: </div>
<div style="text-align: justify;">
index = 0; </div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
// calculate the average:</div>
<div style="text-align: justify;">
average = total / numReadings; </div>
<div style="text-align: justify;">
// send it to the computer as ASCII digits</div>
<div style="text-align: justify;">
Serial.println(average); </div>
<div style="text-align: justify;">
delay(1);</div>
<div style="text-align: justify;">
}</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: justify;">
El resultado debe verse algo así:</div>
<div style="text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/klJAjTqdF6U/0.jpg" frameborder="0" height="266" src="https://www.youtube.com/embed/klJAjTqdF6U?feature=player_embedded" width="320"></iframe></div>
<div style="text-align: justify;">
<br />
<br />
Para mas información pueden revisar mi siguiente entrada que se trata de este mismo proyecto usando Arduino uno.<br />
<br />
<br /></div>
<div style="text-align: justify;">
Exitos!</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: center;">
<i><span style="color: red;">Maryori Sabalza </span></i><span style="color: red;"><i>Mejía</i></span></div>
<div style="text-align: center;">
<i><span style="color: red;">Cartagena-Colombia</span></i></div>
<div style="text-align: justify;">
<br /></div>
Maryori Sabalzahttp://www.blogger.com/profile/13211307381591319962noreply@blogger.com2