tag:blogger.com,1999:blog-18374316915355532024-03-19T14:29:51.848-07:00DarduinoBlog de tutos autour de l' Attiny 85, de l'Arduino Uno. les sujets : random, CharliePlexing et leds.Anonymoushttp://www.blogger.com/profile/08797231754964942111noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-1837431691535553.post-4484983098435838102015-05-24T12:13:00.001-07:002015-05-24T12:13:40.941-07:00Dice Led Charlieplexing<iframe allowfullscreen="" frameborder="0" height="344" src="https://www.youtube.com/embed/oGQk5BaY3Ug" width="459"></iframe>Anonymoushttp://www.blogger.com/profile/08797231754964942111noreply@blogger.com0tag:blogger.com,1999:blog-1837431691535553.post-61611297130256005702015-05-17T12:39:00.000-07:002015-05-22T13:36:50.482-07:00Dé Attiny 85 en CharliePlexing moulé en résine Crystal <div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: center;">
<br /></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigORjpwJtZiAA1EqY0lIabmyvbIsYAU3OBb8ZjYhyphenhyphenOH6pghNAg6WEsPBhx9KpkvjKyIWhoiRn1TISpscncz6AFhD5Yxpk7Stob55EMNgeDGpLM8FeGahh6_FwaR8a35nV8lyW-AC2EtQ/s1600/IMG_1677.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigORjpwJtZiAA1EqY0lIabmyvbIsYAU3OBb8ZjYhyphenhyphenOH6pghNAg6WEsPBhx9KpkvjKyIWhoiRn1TISpscncz6AFhD5Yxpk7Stob55EMNgeDGpLM8FeGahh6_FwaR8a35nV8lyW-AC2EtQ/s320/IMG_1677.jpg" width="320" /></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;">le résultat : gauche dernière version, à droite première version (démoulée trop tôt).</span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="text-align: start;">les images de ce tuto sont issues de plusieurs expériences autour du même sujet. Le sketch et les indications de montages sont le résultat des derniers essais. </span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="text-align: start;"><a href="http://www.instructables.com/id/Dice-ATTINY85-Charlieplexing/" target="_blank">La version anglaise sur : http://www.instructables.com/id/Dice-ATTINY85-Charlieplexing/</a></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="text-align: start;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLh-XgBOSQE3_gC-FD25HvTKSEbavjWPvnc1QZOqLMCtjZaIFBOjiUsmXrWZn_SzezXTvVKR9x6coJQDwu94Q5SOv_YBhA49oTLSQOwkIm6NoQNRlm4ANyR_tEAkqlo2X_cSv_qBobzA/s1600/IMG_1675.MOV" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLh-XgBOSQE3_gC-FD25HvTKSEbavjWPvnc1QZOqLMCtjZaIFBOjiUsmXrWZn_SzezXTvVKR9x6coJQDwu94Q5SOv_YBhA49oTLSQOwkIm6NoQNRlm4ANyR_tEAkqlo2X_cSv_qBobzA/s320/IMG_1675.MOV" width="180" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="text-align: start;"><br /></span></div>
<h2>
Inventaire : </h2>
<div>
<ul>
<li>Leds 5 mm (acheté par 1000 ebay chine)</li>
<li>tilt sensor <a href="http://www.ebay.fr/itm/10Pcs-SW-520D-Vibration-Sensor-Dual-Metal-Ball-Tilt-Shaking-Switch-for-Arduino-R-/371026076064?pt=LH_DefaultDomain_71&hash=item5662e0a1a0" target="_blank">ebay</a></li>
<li>Attiny85 + support <a href="http://www.ebay.fr/itm/251531901676?var=550438036555&ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649" target="_blank">ebay</a></li>
<li>support pile bouton CR2432 ebay</li>
<li>4 Resistances 39 ohms</li>
<li>Resine Crystal</li>
<li>un gloss ultra brillant pour résine (<a href="http://www.amazon.fr/dp/B0054VV8KG/ref=asc_df_B0054VV8KG26397054/?tag=googshopfr-21&creative=22686&creativeASIN=B0054VV8KG&linkCode=df0" target="_blank">amazon</a>)</li>
<li>moule 3x3x3 cube silicone</li>
<li>de la pâte Playdoh</li>
</ul>
<div>
Les trucs qui n'ont pas fonctionné :</div>
</div>
<div>
<ul>
<li>l'interrupteur (bloqué par la résine)</li>
<li>le random standard</li>
</ul>
</div>
<h2>
Les étapes importantes du montage : </h2>
<br />
<h3>
1. Le CharliePlexing<br /><span style="font-weight: normal;"><span style="font-size: small;">voir le wiki : <a href="http://en.wikipedia.org/wiki/Charlieplexing">http://en.wikipedia.org/wiki/Charlieplexing</a></span></span><br /><span style="font-weight: normal;"><span style="font-size: small;">Dans notre cas nous avons 7 leds à piloter, le nombre de pins nécessaires est de 4. la règle avec 4 pins on peut piloter : (4*4)-4 = 12 pins. </span></span><br /><span style="font-weight: normal;"><span style="font-size: small;">le schéma pins <-> leds est le suivant : </span></span></h3>
<h3>
<table border="0">
<caption> Schéma Charlieplexing </caption>
<tbody>
<tr>
<th><div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKhie1_HJfZRW-XLQ8MkB0AIPZKoOjWgfO252XP4prkcBTN2gV8lhH7Yx2Mi7l7QQqj2YTcLf-K2dUIw3SWmHBWqc9VuCZhZ5u1r-ka28NDOukGe4P_KzQ0ty8IVTNkcXlHseclB2xvBw/s1600/schema_charlieplex.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="172" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKhie1_HJfZRW-XLQ8MkB0AIPZKoOjWgfO252XP4prkcBTN2gV8lhH7Yx2Mi7l7QQqj2YTcLf-K2dUIw3SWmHBWqc9VuCZhZ5u1r-ka28NDOukGe4P_KzQ0ty8IVTNkcXlHseclB2xvBw/s320/schema_charlieplex.jpg" width="320" /></a></div>
</th>
<th><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlExECWJLIIAUu88Sg6ofKDaEAS7PROo5gpEYP8zlLXTLAMv5o9cTZX6TTuPFbCWl1b58zYau4Mw8eyuKeKsLbnfis4WxZpGzBzjjLuZAKAma-Ag_pJndRi3R5F0X-evpmRQk6RRotEQ/s1600/IMG_1656.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlExECWJLIIAUu88Sg6ofKDaEAS7PROo5gpEYP8zlLXTLAMv5o9cTZX6TTuPFbCWl1b58zYau4Mw8eyuKeKsLbnfis4WxZpGzBzjjLuZAKAma-Ag_pJndRi3R5F0X-evpmRQk6RRotEQ/s320/IMG_1656.jpg" width="240" /></a></th>
</tr>
</tbody></table>
<span style="font-weight: normal;"><span style="font-size: small;"><!-----><!-----><!-----><!-----><!-----></span></span><br />
</h3>
<h3>
2. Souder les leds et respecter la forme finale.</h3>
<div>
Afin de respecter la forme finale, j'utilise une plaquette en bois percée en 5 mm. Utilisation de pâte Play-Doh pour maintenir les composants. Sur la led 4 faire attention aux croisements, le vernis à ongle peut être utilisé pour isoler. Tester et valider qu'il n'y a pas de faux contacts.<br />
<br />
<br /></div>
<table border="0">
<caption> Positionner les leds à souder </caption>
<tbody>
<tr>
<th><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZfsdf0opEEH5yZaMM8r5FCEHm_a2ed7-g3mLdgwsS0Ia_ADWG5BpLnmg9gw_q9UYUxli-v7VHhnnz_UNh4ygA32NNtNg0DoJ7MH3iqjGDBUNjsYRd98rF64Etz-ZqvmmWLfpHJhPOWQ/s1600/IMG_1698.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZfsdf0opEEH5yZaMM8r5FCEHm_a2ed7-g3mLdgwsS0Ia_ADWG5BpLnmg9gw_q9UYUxli-v7VHhnnz_UNh4ygA32NNtNg0DoJ7MH3iqjGDBUNjsYRd98rF64Etz-ZqvmmWLfpHJhPOWQ/s320/IMG_1698.jpg" width="240" /></a></div>
</th>
<th><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhruy7wj8GvqZcIeQhAGpr5SRXoVhZ9iYR9DQ3EjdnYKJHH7gYp4CYLplLhMg93-iZ-8xkZwiFvSO-Fu87O1-bWfj-cYYdZ01ObU8_UvumsjtDzIZXivyAgbxhqh56Lc9FcJ4THIF5Rtw/s1600/IMG_1701.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhruy7wj8GvqZcIeQhAGpr5SRXoVhZ9iYR9DQ3EjdnYKJHH7gYp4CYLplLhMg93-iZ-8xkZwiFvSO-Fu87O1-bWfj-cYYdZ01ObU8_UvumsjtDzIZXivyAgbxhqh56Lc9FcJ4THIF5Rtw/s320/IMG_1701.jpg" width="240" /></a></div>
</th>
</tr>
<tr>
<th><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgX6qZosYOYmdOyNS2ytd3x1DyvWInUNYprWB8eF6RROX9UMpRP9dSl0v8dSsFMN0GmRhHEJpP5yfvliJx56hxB03tu0eTwdx7e0uoxF03Mg01zZRSTtbUoZUzYiP2xRGh9_QtNSC-J_w/s1600/IMG_1702.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgX6qZosYOYmdOyNS2ytd3x1DyvWInUNYprWB8eF6RROX9UMpRP9dSl0v8dSsFMN0GmRhHEJpP5yfvliJx56hxB03tu0eTwdx7e0uoxF03Mg01zZRSTtbUoZUzYiP2xRGh9_QtNSC-J_w/s320/IMG_1702.jpg" width="240" /></a></div>
</th>
<th><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLmG63tTKdfDgEmosYTF7A0A93KSejwFyUhZfyCaRUz5bKhMGAHRcAWIXthRCeTNNdAfMbJq0GeJptVVKOkAzdszzuMDmWYOzoFnzQiaMgX9qdNgy1L8OGJirv23hSeGMoIzIbw_LQnA/s1600/IMG_1703.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLmG63tTKdfDgEmosYTF7A0A93KSejwFyUhZfyCaRUz5bKhMGAHRcAWIXthRCeTNNdAfMbJq0GeJptVVKOkAzdszzuMDmWYOzoFnzQiaMgX9qdNgy1L8OGJirv23hSeGMoIzIbw_LQnA/s320/IMG_1703.jpg" width="240" /></a></div>
</th>
</tr>
</tbody>
</table>
<br />
<h3>
3. Souder l'Attiny 85 avec son support</h3>
<table border="0">
<caption> Evitez les erreurs en dessinant l'Attiny85</caption>
<tbody>
<tr>
<th><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihu7hiwk0RaP45V1oqAwdqNaS3hARBEsxgiTqjffnxXbkcFpF-PTqeXYZvF_etBQ6ADfm4qhBkim-V8aeKkGXkRS_lgDhb1fyLgy1An584nAZIICOcwWv5rFzR0orEqKOsydPrPT2jdQ/s1600/IMG_1661.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihu7hiwk0RaP45V1oqAwdqNaS3hARBEsxgiTqjffnxXbkcFpF-PTqeXYZvF_etBQ6ADfm4qhBkim-V8aeKkGXkRS_lgDhb1fyLgy1An584nAZIICOcwWv5rFzR0orEqKOsydPrPT2jdQ/s320/IMG_1661.jpg" width="240" /></a></div>
</th>
<th><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5Mg4Ir-nAIx8czunDP0E7dfjnx7dQWDS-cFWup-qIv2fEgterM5pZpFjFqxztLebD4WN4mjPSWIK8LrQ8Hd6aMNlDr39f8SlHbPQt3n9B2VSnr3xVCyc9DUdJ-MB1WAe2O9Fmq8tXRKs/s1600/IMG_1660.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5Mg4Ir-nAIx8czunDP0E7dfjnx7dQWDS-cFWup-qIv2fEgterM5pZpFjFqxztLebD4WN4mjPSWIK8LrQ8Hd6aMNlDr39f8SlHbPQt3n9B2VSnr3xVCyc9DUdJ-MB1WAe2O9Fmq8tXRKs/s320/IMG_1660.jpg" width="240" /></a></div>
</th>
</tr>
</tbody></table>
<div>
<br /></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
</div>
<div>
<table border="0">
<caption>Raccordement des leds</caption>
<tbody>
<tr> <th><div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9Ic7LdfVJ4c430ASogYYe2ePiGOYnwQ2luisDz9jWsYAZnNmQ_pDae5TgtpRjIvZe6_d5rhiq00PtxIBD1dB9rAQbagQAekUwAQ3MVaOAnZBps4vqxudrY7XkOsbjVldYgHcjB0OkRqA/s1600/IMG_1659.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9Ic7LdfVJ4c430ASogYYe2ePiGOYnwQ2luisDz9jWsYAZnNmQ_pDae5TgtpRjIvZe6_d5rhiq00PtxIBD1dB9rAQbagQAekUwAQ3MVaOAnZBps4vqxudrY7XkOsbjVldYgHcjB0OkRqA/s320/IMG_1659.jpg" width="240" /></a><br />
<br />
<br /></div>
</th>
<td>Les pins 1, 2, 3 et 4 sont reliés à des résistances de 39 ohms, reliées aux 4 brins issues des leds. Le mapping avec le schéma initial est :
<br />
<div>
bleu = 1</div>
<div>
vert = 2</div>
<div>
rouge = 3</div>
<div>
noir = 4<br />
<br /></div>
</td>
</tr>
</tbody></table>
</div>
<div>
<table border="0">
<caption>Raccordement Attiny 85 et Tilt Sensor </caption>
<tbody>
<tr> <th><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBAttBocgj8MM_fRdVFeQ38aL2S8GmOjuX1MNLDzQ6WNJ3IXDEhrUvnlDJ-JWOqPl4RN4pre905LrRzyB8nQW3QUcJg6gowoH1jzbf0CqtwC2ry5nPpwKNNIwPCGjreUHF58JY40OiCVw/s1600/IMG_1663.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBAttBocgj8MM_fRdVFeQ38aL2S8GmOjuX1MNLDzQ6WNJ3IXDEhrUvnlDJ-JWOqPl4RN4pre905LrRzyB8nQW3QUcJg6gowoH1jzbf0CqtwC2ry5nPpwKNNIwPCGjreUHF58JY40OiCVw/s320/IMG_1663.jpg" width="240" /></a>
</th>
<td>Le tilt sensor est utilisé comme interrupteur. il est composé de deux pins : l'un raccordé au (+) de la pile bouton et l'autre au (+) de l'Attiny. pour comprendre le tilt sensor voir :
<a href="http://www.learningaboutelectronics.com/Articles/Tilt-sensor-circuit.php">http://www.learningaboutelectronics.com/Articles/Tilt-sensor-circuit.php</a><br />
<div>
Le (-) de la pile bouton est relié au GND de l'Attiny.</div>
</td>
</tr>
<tr> <th><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilNNeuvQz9TB7-uhrYSkAayR8JYEX-QXxURoIXebzSb_U8nU2UcSJWswJCW6pR4XVu_Apt4-gpuNBIBdV4n2jGe4BFc0lJTHPjnFmVtzQ3q0Lvy3AkQITccBoE3yArfC8B574JSTU28w/s1600/IMG_1714.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilNNeuvQz9TB7-uhrYSkAayR8JYEX-QXxURoIXebzSb_U8nU2UcSJWswJCW6pR4XVu_Apt4-gpuNBIBdV4n2jGe4BFc0lJTHPjnFmVtzQ3q0Lvy3AkQITccBoE3yArfC8B574JSTU28w/s320/IMG_1714.jpg" width="240" /></a></div>
</th>
<th><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAtFqFkPkIs1Us6-H_hF5fP68ASzY-zO43LKZ_DbgHsqhyphenhyphenGTaNdurNU39UaX4D43qmYSkjOoHLhseX7gXza2xvrw-e04GeQrx542fNotgYWSW5N9FPm3amrdOfOYIMhLkxkIfqTFpTGw/s1600/IMG_1715.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAtFqFkPkIs1Us6-H_hF5fP68ASzY-zO43LKZ_DbgHsqhyphenhyphenGTaNdurNU39UaX4D43qmYSkjOoHLhseX7gXza2xvrw-e04GeQrx542fNotgYWSW5N9FPm3amrdOfOYIMhLkxkIfqTFpTGw/s320/IMG_1715.JPG" width="320" /></a></div>
<br /></th></tr>
</tbody>
</table>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<h3>
Souder la pile bouton</h3>
<div>
C'est la dernière étape de soudure, le système complet doit tenir dans le moule (à glaçon) prévu pour le dé. Il s'agit d'un moule à glaçon de 3x3x3 cm en silicone.</div>
<div>
<br /></div>
<div>
<br /></div>
<br />
<h2>
Les étapes de la programmation :</h2>
<ol>
<li>chargement du programme sur Attiny</li>
<li>Programmation du charlieplexing</li>
<li>Programmation du random (différent sur Attiny et pas fiable en standard).</li>
<li>Programmer le lancement</li>
</ol>
<div>
<h3>
<b>1) le chargement du programme sur Attiny</b></h3>
</div>
<div>
Le meilleur tuto sur le sujet est sur le lien suivant : <a href="http://highlowtech.org/?p=1695">http://highlowtech.org/?p=1695</a></div>
<div>
et faire le test avec un programme simple (voir blink).<br />
Pour ma part, j'utilise un arduino pour programmer l'Attiny.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHOtdhbzONzDvdTVxifsJzFij9XDaC5duv4wtx3p_802lLZ7nB4UE7pMXhpUKlpx9oDqKbP6MxeD1ivJ3CTFeDNMhgq1Xwla1gk3iGTMXOCGJ7aYwRxHKFNuUBfHRLX-_nQJ5wt7Zktg/s1600/IMG_1671.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHOtdhbzONzDvdTVxifsJzFij9XDaC5duv4wtx3p_802lLZ7nB4UE7pMXhpUKlpx9oDqKbP6MxeD1ivJ3CTFeDNMhgq1Xwla1gk3iGTMXOCGJ7aYwRxHKFNuUBfHRLX-_nQJ5wt7Zktg/s320/IMG_1671.jpg" width="240" /></a></div>
<br /></div>
<div>
il s'agit d'un shield arduino, connecté pour charger l'attiny.<br />
A savoir, la vitesse par défaut 1mhz de l'Attiny n'est pas suffisante pour un affichage fluide.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
A 8 mhz c'est parfait. pour changer la vitesse, il faut choisir l'attiny 85 à 8mhz.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi87CNrKAHblI1rtycBfIAvskVUepwCv8axnPj54rZfc6vSkNfZX759Z9zUE6Kspzs_jFuZXVTU-dDqZCiG0xXfFfqDVkbSizVBAu7pGS4w6KfuCWLFp6UobxAVsJqoXiDxoByZ4NEYnw/s1600/menucarteattiny85a8.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="126" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi87CNrKAHblI1rtycBfIAvskVUepwCv8axnPj54rZfc6vSkNfZX759Z9zUE6Kspzs_jFuZXVTU-dDqZCiG0xXfFfqDVkbSizVBAu7pGS4w6KfuCWLFp6UobxAVsJqoXiDxoByZ4NEYnw/s320/menucarteattiny85a8.jpg" width="320" /></a></div>
avant de téléverser le programme, il faut graver la sequence d'initialisation pour changer la vitesse :<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVIvA0NJ8Q6Gwb6BR5aU0G7z4_9UlI5o3N9FyH0fYdwdk4IxP8MjValB_n10LEIXO5AtdhtURepNjLpMZQCHmcUp4AVmnOa_hMDDp0SdV7eUfj0oPWApNm7SyAA_VhKEeDhk4bDt1jzA/s1600/menuburncarte.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVIvA0NJ8Q6Gwb6BR5aU0G7z4_9UlI5o3N9FyH0fYdwdk4IxP8MjValB_n10LEIXO5AtdhtURepNjLpMZQCHmcUp4AVmnOa_hMDDp0SdV7eUfj0oPWApNm7SyAA_VhKEeDhk4bDt1jzA/s1600/menuburncarte.jpg" /></a></div>
<br />
<br /></div>
<div>
<h3>
<b>2) Programmation Charlieplexing</b></h3>
</div>
<div>
<br /></div>
<div>
<u>les indispensables </u>: </div>
<div>
une table pour identifier chaque led : (1 pour pole +, 2 pour -, 3 pour inactif).<br />
On initialise un tableau d'équivalence pour piloter chaque led.</div>
<br />
<blockquote>
<pre><span style="color: blue;">// 1= output high
// 2= output low
// 3= input low
int tabled[7][4] ={
//row 1 2 3 4
{1,2,3,3}, //led 1
{2,1,3,3}, //led 2
{1,3,2,3}, //led 3
{3,1,2,3}, //led 4
{3,3,1,2}, //led 5
{3,3,2,1}, //led 6
{3,2,3,1}, //led 7
}; </span><span style="color: blue;">
</span></pre>
<div>
<br /></div>
</blockquote>
<div>
l'affichage d'une led se fait en déterminant la polarité des pins : </div>
<div>
<blockquote>
<pre><span style="color: blue;">
switch (tabled[numled][i]) {
case 1 :
pinMode(pin_switch + i, OUTPUT);
break;
case 2 :
pinMode(pin_switch + i, OUTPUT);
break;
case 3 :
pinMode(pin_switch + i, INPUT);
break;
default :
break;
switch (tabled[numled][i]) {
case 1 :
digitalWrite(pin_switch + i, HIGH);
break;
case 2 :
digitalWrite(pin_switch + i, LOW);
break;
case 3 :
digitalWrite(pin_switch + i, LOW);
break;
default :
break;
</span></pre>
</blockquote>
<h3>
<b>3) La programmation du random</b></h3>
</div>
<div>
La fonction randomSeed avec la lecture du port analogique retourne la même série de valeurs.<br />
j'ai utilisé deux techniques pour m'assurer un random parfait :<br />
<br />
<ul>
<li>l'excellente librairie <a href="https://sites.google.com/site/astudyofentropy/project-definition/timer-jitter-entropy-sources/entropy-library" target="_blank">Entropy</a></li>
<li>la sauvegarde du nombre de la série randomSeed dans l'eprom via la librairie <a href="http://www.arduino.cc/en/Reference/EEPROM" target="_blank">EPROM</a>. l'utilisation du tilt comme interrupteur fait que nous ne pouvons pas utiliser une simple variable pour sauver le dernier nombre utilisé. </li>
</ul>
</div>
<div>
<h3>
<b>4) Le programme </b></h3>
</div>
<div>
<br /></div>
<div>
Chaque chiffre du dé correspond à un ensemble de leds allumées. la clé est une table décrivant cette correspondance.</div>
<div>
<blockquote>
<pre :="" overflow:auto=""><span style="color: blue;">
/* Charliplexing 7 LEDs
dice description :
1 5
2 4 6
3 7
--------------------------------------------------------------------------------
Row 1 (R1): Arduino Pin 10 or ATTINY Pin 1
Row 2 (R2): Arduino Pin 11 or ATTINY Pin 2
Row 3 (R3): Arduino Pin 12 or ATTINY Pin 3
Row 4 (R4): Arduino Pin 13 or ATTINY Pin 4
See pin_switch var Arduino vs Attiny
--------------------------------------------------------------------------------
variable pinMode state
L OUTPUT LOW
H OUTPUT HIGH
Z INPUT LOW
---------------------------------------------------------------------------------
*/
#define ATTINY_MODE 1 // Comment for ARDUINO
//#define TEST_MODE 1 // Comment for production version
//#define ATTINYfd_1 1 //Attiny à 1 mhz
#define ATTINYfd_8 1 //Attiny à 8 mhz
//#define ATTINYfd_20 1 //Attiny à 20 mhz
</span><eeprom .h=""><entropy .h=""><span style="color: blue;">// Library
#include < EEPROM.h > // save data for random
#include < Entropy.h > // GNU random
const int coef = 5;
#if !defined (ATTINY_MODE) //ARDUINO
const int temps_affiche = 500; //display refresh rate = 500 for arduino 150 for ATTINY
const int temps_une_led = 30; // display repet light per led = 30 for arduino and 5 for ATTINY
const int pin_switch = 10; // match pin between ATTINY and arduino
#endif
#if defined(ATTINYfd_1)
const int temps_affiche = 150; //display refresh rate = 500 for arduino 150 for ATTINY
const int temps_une_led = 24; // display repet light per led = 30 for arduino and 5 for ATTINY
const int pin_switch = 1; // match pin between ATTINY and arduino
#endif
#if defined(ATTINYfd_8)
const int temps_affiche = 300; //display refresh rate = 500 for arduino 150 for ATTINY
const int temps_une_led = 100; // display repet light per led = 30 for arduino and 5 for ATTINY
const int pin_switch = 1; // match pin between ATTINY and arduino
#endif
// dice number To led matrix
byte dede[8][7] ={
//3 4 5 6 7 8 9
{0,0,0,0,0,0,0}, // 0 nothing
{0,0,0,1,0,0,0}, // 1
{0,0,1,0,1,0,0}, // 2
{1,0,0,1,0,0,1}, // 3
{1,0,1,0,1,0,1}, // 4
{1,0,1,1,1,0,1}, // 5
{1,1,1,0,1,1,1}, // 6
{1,1,1,1,1,1,1}, // 7 all
};
// 1= output high
// 2= output low
// 3= input low
int tabled[7][4] ={
//row 1 2 3 4
{1,2,3,3}, //led 1
{2,1,3,3}, //led 2
{1,3,2,3}, //led 3
{3,1,2,3}, //led 4
{3,3,1,2}, //led 5
{3,3,2,1}, //led 6
{3,2,3,1}, //led 7
};
void setup()
{
uint8_t random_byte;
unsigned int id = EEPROM.read(0);
Entropy.Initialize();
if (Entropy.available()) {
randomSeed(id);
id = Entropy.random();
}
EEPROM.write(0, id);
#if !defined (ATTINY_MODE)
Serial.begin (115200);
Serial.println ("setup");
Serial.println ("id : ");
Serial.print (id+1);
Serial.println("");
#endif
#if !defined (TEST_MODE)
Lancedes();
#endif
}
void loop()
{
#if defined (TEST_MODE)
afficheled(0,temps_affiche*coef);
afficheled(1,temps_affiche*coef);
afficheled(2,temps_affiche*coef);
afficheled(3,temps_affiche*coef);
afficheled(4,temps_affiche*coef);
afficheled(5,temps_affiche*coef);
afficheled(6,temps_affiche*coef);
affichede(1, temps_affiche);
affichede(2, temps_affiche);
affichede(3, temps_affiche);
affichede(4, temps_affiche);
affichede(5, temps_affiche);
affichede(6, temps_affiche);
#endif
}
// ***** affiche led *****
void afficheled(int numled,int temps)
{ int i,j;
//boucle de repetition nombre de temps
//par defaut 1
if (numled > 6 || numled < 0) affiche_erreur (1);
for(i=0;i < 4;i++) // changement des pins arduino
{
switch (tabled[numled][i]) {
case 1 :
pinMode(pin_switch + i, OUTPUT);
break;
case 2 :
pinMode(pin_switch + i, OUTPUT);
break;
case 3 :
pinMode(pin_switch + i, INPUT);
break;
default :
break;
}
}
if (temps ==0) temps=1;
for (j=0;j < temps;j++)
{
for(i=0;i < 4;i++) // changement des pins arduino
{
switch (tabled[numled][i]) {
case 1 :
digitalWrite(pin_switch + i, HIGH);
break;
case 2 :
digitalWrite(pin_switch + i, LOW);
break;
case 3 :
digitalWrite(pin_switch + i, LOW);
break;
default :
break;
}
}
}
}
// ***** set up leds corresponding the number *****
void affichede(int n ,int temps)
{ int i,j;
int tp_led , tp_boucle;
if (n > 6 || n < 1) affiche_erreur (2);
tp_led = temps_une_led / n;
tp_boucle= temps;
//boucle de repetition nombre de temps
//par defaut 1
if (tp_boucle ==0) tp_boucle=1;
for (j=0;j < tp_boucle;j++)
{
for(i=0;i < 7;i++) if (dede[n][i]==1) afficheled(i,tp_led);
}
}
void affiche_erreur(int erreur)
{
int i,j;
switch (erreur) {
case 1 : // erreur affiche led
for (i=0;i < 10;i++) for (j=1;j < 8;j++) afficheled(j,temps_affiche);
break;
case 2 : // erreur affichede
for (i=0;i < 10;i++) for (j=1;j < 4;j++) afficheled(j,temps_affiche);
break;
default :
break;
}
}
void Lancedes()
{
int n,i;
int loto1; // résultat random du nombre de tour de dès avant résultat
int maxi =15; // maxi du random du nombre de tour de dès avant résultat
int mini = 5; // mini du random du nombre de tour de dès avant résultat
int delay1; // temps d'affichage entre deux tours avant final
int resultat = 10; // résultat intermediaire
int ancienresultat = 10; // empeche deux fois le meme nombre
loto1 = Entropy.random(mini,maxi);
for (n=0; n < loto1;n++)
{
while (resultat == ancienresultat) resultat=Entropy.random(1,7);
ancienresultat=resultat;
delay1=(temps_affiche)/(loto1-n);
affichede(resultat,delay1);
}
#if !defined (ATTINY_MODE)
Serial.print ("resultat final :");
Serial.print(resultat);
Serial.print(" nb resul inter : ");
Serial.println(loto1);
#endif
affichede(resultat,temps_affiche*100);
}
</span></entropy></eeprom></pre>
</blockquote>
</div>
<div>
<br />
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: Times; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;">
</div>
<br />
<h2 style="-webkit-text-stroke-width: 0px; color: black; font-family: Times; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;">
Le moulage en résine : </h2>
</div>
<div>
Avant de mouler l'ensemble, il faut protéger l'emplacement de la pile bouton pour pouvoir la changer.</div>
<div>
j'utilise la pâte Playdoh, mais le résidu n'est pas évident à retirer après.<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5OuXMgs9jslACUcDL07aNipTZWQKKXQnhbjRFdcrBC0TzUaA_Ekm0QuGut1sG95C5nXvGOXNYRAlA9-oStw2mu42V78AnbDbwQ2wMpxS8WWyyxFJzqDgj_kdk2GSF2Qgip3pfyiiNHQ/s1600/IMG_1680.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5OuXMgs9jslACUcDL07aNipTZWQKKXQnhbjRFdcrBC0TzUaA_Ekm0QuGut1sG95C5nXvGOXNYRAlA9-oStw2mu42V78AnbDbwQ2wMpxS8WWyyxFJzqDgj_kdk2GSF2Qgip3pfyiiNHQ/s320/IMG_1680.jpg" width="240" /></a></div>
Le séchage est long > 3 jours, 1 semaine est recommandé. il est important de ne pas démouler avant l'heure.</div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8A-4GsmutFWRjFmPYx0JKRNGInGEhtKL9tvH46_h7xd-MqsRn8fI-IlrujrOWCAAIBsmr4pui3nEmluC2FbnDS5ei1UySSiagZM72GfpDEYjYhqiYw7XV-6jHoEF25ScwefvVTmzXyg/s1600/IMG_1678.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8A-4GsmutFWRjFmPYx0JKRNGInGEhtKL9tvH46_h7xd-MqsRn8fI-IlrujrOWCAAIBsmr4pui3nEmluC2FbnDS5ei1UySSiagZM72GfpDEYjYhqiYw7XV-6jHoEF25ScwefvVTmzXyg/s320/IMG_1678.jpg" width="240" /></a></div>
<br />
<br /></div>
<div>
Après séchage, si le dé n'est pas entièrement transparent, utilisez le vernis Gloss.<br />
<br />
<br />
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/08797231754964942111noreply@blogger.com1tag:blogger.com,1999:blog-1837431691535553.post-60769963891775334202014-07-31T01:38:00.000-07:002015-05-19T03:24:51.922-07:00Deux dés Arduino / Conception / Page 2<h4>Tutoriel pour deux dés</h4><div>retour conception page 1<br /><h3>Organisation des leds :</h3></div><div>Avec 2 dés, il faut gérer l'affichage de 14 leds avec seulement 7 sorties Arduino.<br />Le dispositif est similaire avec une double connexion des 7 pins sur les leds symétriques des deux dés.<br /><br />Nous utilisons deux transistors NPN(<a href="http://playground.arduino.cc/Main/Components" target="_blank">Explication composant pnp</a>) avec 3 pattes, qui laissent passer le courant aux extrémités lorsque nous envoyons du courant sur la patte centrale. Nous raccordons aux sorties 10 et 11 chacun des transistors. toutes les cathodes (-) d'un dés sont rattachées à une patte extérieur du composant NPN. la patte libre est connectée au GND (-).<br /><br />Pour afficher un chiffre différent, on éteint un dés et on allume l'autre ensuite on alterne. Ce fonctionnement impose un affichage, continu en alternance de chaque dés.<br /><br /><br /></div><div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdySP6uLh3N6OZRXTyx3VAPDfehYMa-b0-GPrkygIUkEJaOZ3sDPfNHO7iP-xgcz2Sjex6K9IJ9IQyqe1Q9OePvYNY5-leiU5izKHmwTMVLS9T-r813pKoBJ0CcaI6_OPcYQo2iNaO2g/s1600/deuxdes_complet_fzz_-_Fritzing_-__Vue_de_la_platine_d_essai_.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="536" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdySP6uLh3N6OZRXTyx3VAPDfehYMa-b0-GPrkygIUkEJaOZ3sDPfNHO7iP-xgcz2Sjex6K9IJ9IQyqe1Q9OePvYNY5-leiU5izKHmwTMVLS9T-r813pKoBJ0CcaI6_OPcYQo2iNaO2g/s1600/deuxdes_complet_fzz_-_Fritzing_-__Vue_de_la_platine_d_essai_.jpg" width="640" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><br /><h3><i><span style="font-size: x-small;">le script de fonctionnement pour les deux dés est le suivant : </span></i></h3><i><span style="font-size: x-small;"><br /></span></i><i><span style="font-size: x-small;">//organisation des dès avec sorties : </span></i><br /><i><span style="font-size: x-small;">// 6 4</span></i><br /><i><span style="font-size: x-small;">// 7 5 3</span></i><br /><i><span style="font-size: x-small;">// 8 2</span></i><br /><i><span style="font-size: x-small;">int butPin = 9; // bouton</span></i><br /><i><span style="font-size: x-small;">int transi1 = 10; // transistor 1</span></i><br /><i><span style="font-size: x-small;">int transi2 = 11; // transistor 2</span></i><br /><i><span style="font-size: x-small;"><br /></span></i><i><span style="font-size: x-small;">byte dede[8][7] ={</span></i><br /><i><span style="font-size: x-small;"> //2 3 4 5 6 7 8</span></i><br /><i><span style="font-size: x-small;"> {0,0,0,0,0,0,0}, // 0 rien</span></i><br /><i><span style="font-size: x-small;"> {0,0,0,1,0,0,0}, // 1</span></i><br /><i><span style="font-size: x-small;"> {1,0,0,0,1,0,0}, // 2</span></i><br /><i><span style="font-size: x-small;"> {0,0,1,1,0,0,1}, // 3</span></i><br /><i><span style="font-size: x-small;"> {1,0,1,0,1,0,1}, // 4</span></i><br /><i><span style="font-size: x-small;"> {1,0,1,1,1,0,1}, // 5</span></i><br /><i><span style="font-size: x-small;"> {1,1,1,0,1,1,1}, // 6</span></i><br /><i><span style="font-size: x-small;"> {1,1,1,1,1,1,1}, // 7 tout</span></i><br /><i><span style="font-size: x-small;">};</span></i><br /><i><span style="font-size: x-small;"><br /></span></i><i><span style="font-size: x-small;">byte resultatloto[2][30]; // remplissage du résultat des deux dès lancés</span></i><br /><i><span style="font-size: x-small;">int resultdesun=0; </span></i><br /><i><span style="font-size: x-small;">int resultdesdeux=0;</span></i><br /><i><span style="font-size: x-small;">int attenteboucle = 5; //10 en standard = calcul la vitesse de changement</span></i><br /><i><span style="font-size: x-small;"><br /></span></i><i><span style="font-size: x-small;">void setup()</span></i><br /><i><span style="font-size: x-small;">{</span></i><br /><i><span style="font-size: x-small;"> int i;</span></i><br /><i><span style="font-size: x-small;"> for (i=2; i<9; i++) pinMode(i,OUTPUT); // led pins</span></i><br /><i><span style="font-size: x-small;"> pinMode(transi1,OUTPUT);</span></i><br /><i><span style="font-size: x-small;"> pinMode(transi2,OUTPUT);</span></i><br /><i><span style="font-size: x-small;"> pinMode(butPin,INPUT); </span></i><br /><i><span style="font-size: x-small;"> digitalWrite(butPin, HIGH); // indispensable pour la lecture du switch proto</span></i><br /><i><span style="font-size: x-small;"> </span></i><br /><i><span style="font-size: x-small;"> // start/stop button</span></i><br /><i><span style="font-size: x-small;"> turnOnNumber(0);</span></i><br /><i><span style="font-size: x-small;"> randomSeed(analogRead(0)); // initialise le random</span></i><br /><i><span style="font-size: x-small;"> Serial.begin(9600);</span></i><br /><i><span style="font-size: x-small;">}</span></i><br /><i><span style="font-size: x-small;"><br /></span></i><i><span style="font-size: x-small;">void loop() </span></i><br /><i><span style="font-size: x-small;">{</span></i><br /><i><span style="font-size: x-small;"> Lancedes();</span></i><br /><i><span style="font-size: x-small;">}</span></i><br /><i><span style="font-size: x-small;"><br /></span></i><i><span style="font-size: x-small;">void Lancedes() </span></i><br /><i><span style="font-size: x-small;">{</span></i><br /><i><span style="font-size: x-small;"> </span></i><br /><i><span style="font-size: x-small;"> int n,i; </span></i><br /><i><span style="font-size: x-small;"> int loto1; </span></i><br /><i><span style="font-size: x-small;"> int loto2; </span></i><br /><i><span style="font-size: x-small;"> int maxi =15;</span></i><br /><i><span style="font-size: x-small;"> int delay1;</span></i><br /><i><span style="font-size: x-small;"> int resultat = 10;</span></i><br /><i><span style="font-size: x-small;"> int ancienresultat = 10; // empeche deux fois le meme nombre</span></i><br /><i><span style="font-size: x-small;"><br /></span></i><i><span style="font-size: x-small;"> // test bouton </span></i><i><span style="font-size: x-small;"> si actionné</span></i><br /><i><span style="font-size: x-small;"> if (digitalRead(butPin) == HIGH)</span></i><br /><i><span style="font-size: x-small;"> {</span></i><br /><i><span style="font-size: x-small;"> // Calcul et chargement du résultat dans resultatloto (tableau des resultats)</span></i><br /><i><span style="font-size: x-small;"> randomSeed(analogRead(0)); // initialise le random</span></i><br /><i><span style="font-size: x-small;"> loto1 = random(5,maxi);</span></i><br /><i><span style="font-size: x-small;"> randomSeed(analogRead(1)); // initialise le random</span></i><br /><i><span style="font-size: x-small;"> loto2 = random(5,maxi);</span></i><br /><i><span style="font-size: x-small;"><br /></span></i><i><span style="font-size: x-small;"> for (n=0; n < maxi;n++)</span></i><br /><i><span style="font-size: x-small;"> {</span></i><br /><i><span style="font-size: x-small;"> while (resultat == ancienresultat) resultat=random(1,7);</span></i><br /><i><span style="font-size: x-small;"> ancienresultat=resultat;</span></i><br /><i><span style="font-size: x-small;"> if (n<loto1) resultatloto[0][n]=resultat;</span></i><br /><i><span style="font-size: x-small;"> else resultatloto[0][n]=0;</span></i><br /><i><span style="font-size: x-small;"> }</span></i><br /><i><span style="font-size: x-small;"> // resultat final sur premier dés</span></i><br /><i><span style="font-size: x-small;"> resultdesun = resultatloto[0][loto1-1];</span></i><br /><i><span style="font-size: x-small;"><br /></span></i><i><span style="font-size: x-small;"> for (n=0; n < maxi ;n++)</span></i><br /><i><span style="font-size: x-small;"> {</span></i><br /><i><span style="font-size: x-small;"> while (resultat == ancienresultat) resultat=random(1,7);</span></i><br /><i><span style="font-size: x-small;"> ancienresultat=resultat;</span></i><br /><i><span style="font-size: x-small;"> if (n<loto2) resultatloto[1][n]=resultat;</span></i><br /><i><span style="font-size: x-small;"> else resultatloto[1][n]=0;</span></i><br /><i><span style="font-size: x-small;"> }</span></i><br /><i><span style="font-size: x-small;"> // resultat final sur deuxième dés</span></i><br /><i><span style="font-size: x-small;"> resultdesdeux = resultatloto[1][loto2-1];</span></i><br /><i><span style="font-size: x-small;"><br /></span></i><i><span style="font-size: x-small;"><br /></span></i><i><span style="font-size: x-small;"> // affichage des résultats</span></i><br /><i><span style="font-size: x-small;"> if (loto1<loto2) maxi = loto2; // determine la boucle max pour les deux dès</span></i><br /><i><span style="font-size: x-small;"> else maxi = loto1;</span></i><br /><i><span style="font-size: x-small;"><br /></span></i><i><span style="font-size: x-small;"> // boucle avec affichage de plus en plus lent</span></i><br /><i><span style="font-size: x-small;"> for (n=0; n<maxi; n++)</span></i><br /><i><span style="font-size: x-small;"> {</span></i><br /><i><span style="font-size: x-small;"> delay1=(n+1) * 2;</span></i><br /><i><span style="font-size: x-small;"> for (i=0;i<delay1;i++)</span></i><br /><i><span style="font-size: x-small;"> {</span></i><br /><i><span style="font-size: x-small;"> if (resultatloto[0][n] != 0) </span></i><br /><i><span style="font-size: x-small;"> {</span></i><br /><i><span style="font-size: x-small;"> resultdesun = resultatloto[0][n];</span></i><br /><i><span style="font-size: x-small;"> }</span></i><br /><i><span style="font-size: x-small;"> else </span></i><br /><i><span style="font-size: x-small;"> {</span></i><br /><i><span style="font-size: x-small;"> resultdesun = resultatloto[0][loto1-1];</span></i><br /><i><span style="font-size: x-small;"> }</span></i><br /><i><span style="font-size: x-small;"><br /></span></i><i><span style="font-size: x-small;"> if (resultatloto[1][n]!=0) </span></i><br /><i><span style="font-size: x-small;"> {</span></i><br /><i><span style="font-size: x-small;"> resultdesdeux = resultatloto[1][n]; </span></i><br /><i><span style="font-size: x-small;"> }</span></i><br /><i><span style="font-size: x-small;"> else </span></i><br /><i><span style="font-size: x-small;"> {</span></i><br /><i><span style="font-size: x-small;"> resultdesdeux = resultatloto[1][loto2-1];</span></i><br /><i><span style="font-size: x-small;"> }</span></i><br /><i><span style="font-size: x-small;"> </span></i><br /><i><span style="font-size: x-small;">// Serial.println(resultdesun);</span></i><br /><i><span style="font-size: x-small;"> // Serial.println(resultdesdeux);</span></i><br /><i><span style="font-size: x-small;"> </span></i><br /><i><span style="font-size: x-small;"> digitalWrite(transi1,HIGH);</span></i><br /><i><span style="font-size: x-small;"> digitalWrite(transi2,LOW);</span></i><br /><i><span style="font-size: x-small;"> turnOnNumber(resultdesun);</span></i><br /><i><span style="font-size: x-small;"> delay(attenteboucle);</span></i><br /><i><span style="font-size: x-small;"> digitalWrite(transi2,HIGH);</span></i><br /><i><span style="font-size: x-small;"> digitalWrite(transi1,LOW);</span></i><br /><i><span style="font-size: x-small;"> turnOnNumber(resultdesdeux);</span></i><br /><i><span style="font-size: x-small;"> delay(attenteboucle);</span></i><br /><i><span style="font-size: x-small;"> }</span></i><br /><i><span style="font-size: x-small;"> }</span></i><br /><i><span style="font-size: x-small;"> }</span></i><br /><i><span style="font-size: x-small;"> digitalWrite(transi1,HIGH);</span></i><br /><i><span style="font-size: x-small;"> digitalWrite(transi2,LOW);</span></i><br /><i><span style="font-size: x-small;"> turnOnNumber(resultdesun);</span></i><br /><i><span style="font-size: x-small;"> delay(attenteboucle);</span></i><br /><i><span style="font-size: x-small;"> digitalWrite(transi2,HIGH);</span></i><br /><i><span style="font-size: x-small;"> digitalWrite(transi1,LOW);</span></i><br /><i><span style="font-size: x-small;"> turnOnNumber(resultdesdeux);</span></i><br /><i><span style="font-size: x-small;"> delay(attenteboucle);</span></i><br /><i><span style="font-size: x-small;">}</span></i><br /><i><span style="font-size: x-small;"><br /></span></i><i><span style="font-size: x-small;"><br /></span></i><i><span style="font-size: x-small;">// ***** set up leds corresponding the number *****</span></i><br /><i><span style="font-size: x-small;">void turnOnNumber(int n)</span></i><br /><i><span style="font-size: x-small;">{</span></i><br /><i><span style="font-size: x-small;"> int i;</span></i><br /><i><span style="font-size: x-small;"> </span></i><br /><i><span style="font-size: x-small;"> for(i=0;i<7;i++) //n en décalage de 1 lié à la gestion tableau qui commence à0 </span></i><br /><i><span style="font-size: x-small;"> {</span></i><br /><i><span style="font-size: x-small;"> if (dede[n][i]==0) digitalWrite(i+2, LOW);</span></i><i><span style="font-size: x-small;"> </span></i><br /><i><span style="font-size: x-small;"> else digitalWrite(i+2, HIGH);</span></i><br /><i><span style="font-size: x-small;"> </span></i><i><span style="font-size: x-small;">}</span></i><br /><i><span style="font-size: x-small;">}</span></i><br /><br /><br /><br /><br /><br /><br /></div><div><br /></div>Anonymoushttp://www.blogger.com/profile/08797231754964942111noreply@blogger.com0tag:blogger.com,1999:blog-1837431691535553.post-16255868064045185942014-07-28T04:35:00.000-07:002015-05-19T03:24:51.918-07:00Deux dés Arduino / Conception / Page 1<div style="text-align: center;"><h2>DEUX DES ARDUINO / CONCEPTION</h2><div style="text-align: left;"><br /></div></div><h4>Tutorial pour un dés seul</h4><h3>Organisation des leds :</h3>Un dé est composé de 7 leds. Chaque led est reliée à une sortie Arduino.<br />Voila à quoi ça ressemble :<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIxz9r7q7HUBQATrM7J2PLiWOiFXEJeTmwaLJ4-LJkMerqtY6fh82sRcASeLARE6nWtEOYjzX_c-SrkYl8FkvzDNNKIN1-LjNU8rDS0oIxf3uYndgykiOYE_uubgBqg5IY1OMSuzNq3g/s1600/twodice_schema1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="276" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIxz9r7q7HUBQATrM7J2PLiWOiFXEJeTmwaLJ4-LJkMerqtY6fh82sRcASeLARE6nWtEOYjzX_c-SrkYl8FkvzDNNKIN1-LjNU8rDS0oIxf3uYndgykiOYE_uubgBqg5IY1OMSuzNq3g/s1600/twodice_schema1.jpg" width="400" /></a></div><br /><div>Ce dispositif permet d'afficher un dé. Voici l'exemple image et script qui fonctionne avec ce dispositif: </div><div><h3>Dispositif Arduino 1 dé</h3></div><div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiLwD3S2hmgwIHL7dOCyB6ExGldw6JTjNzVbgQSiH8Kn27aksDzproMfcfgA9NXLGC5KJaD-nx9_NeB2E_WkFuAvPYFRICkH4ir_sr7iSR0lj2QsmFawqo16k1U7lGIc-53fexUPU_fg/s1600/arduino_7leds.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiLwD3S2hmgwIHL7dOCyB6ExGldw6JTjNzVbgQSiH8Kn27aksDzproMfcfgA9NXLGC5KJaD-nx9_NeB2E_WkFuAvPYFRICkH4ir_sr7iSR0lj2QsmFawqo16k1U7lGIc-53fexUPU_fg/s1600/arduino_7leds.jpg" /></a></div><h3 style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Sketch Arduino Uno 1 dé</span></i></h3><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">/****************************************************************************************</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">------------------------------------- Programme 1 dés ---------------------------------------------- </span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Déclaration des variables</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> ButPin pour le bouton</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> etat pour le resultat du bouton</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> dede est un tableau contenant les positions </span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> des 7 leds pour toutes les combinaisons d'un dés</span></i></div><div class="separator" style="clear: both; text-align: left;"><i style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><br /></i></div><div class="separator" style="clear: both; text-align: left;"><i style="font-family: Arial, Helvetica, sans-serif; font-size: small;">organisation des dès avec sorties : </i></div><div class="separator" style="clear: both;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><i> led-pin relationships: 6 4</i></span></div><div class="separator" style="clear: both;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><i> 7 5 3</i></span></div><div class="separator" style="clear: both;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"></span></i></div><div class="separator" style="clear: both;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><i> 8 2</i></span></div><div><div class="separator" style="clear: both;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">****************************************************************************************</span></i><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">*/</span></i></div></div><div><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">int butPin = 9;</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">int etat =0;</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">byte dede[8][7] ={</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> //2 3 4 5 6 7 8 numéro des pins associés aux leds</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> {0,0,0,0,0,0,0}, // 0 rien</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> {0,0,0,1,0,0,0}, // 1</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> {1,0,0,0,1,0,0}, // 2</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> {0,0,1,1,0,0,1}, // 3</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> {1,0,1,0,1,0,1}, // 4</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> {1,0,1,1,1,0,1}, // 5</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> {1,1,1,0,1,1,1}, // 6</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> {1,1,1,1,1,1,1}, // 7 tout</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">};</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">// initialisation partie du programme qui s'execute une fois</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">void setup()</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">{</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> int i; // utilisé pour la boucle qui suit</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> // initialisation des pins 2 à 8 pour les leds</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> for (i=2; i<9; i++) pinMode(i,OUTPUT); // led pins</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> pinMode(butPin,INPUT); // initialisation du bouton switch</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> turnOnNumber(0); // extinction des leds</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> randomSeed(analogRead(0)); // initialise le random astuce pour avoir un vrai random</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> Serial.begin(9600);</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">}</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">void loop() </span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">{</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> </span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> int n; </span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> int loto; </span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> int resultat = 10;</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> int ancienresultat = 10; // empeche deux fois le meme nombre</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">// lecture du bouton</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> etat= digitalRead(butPin);</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> if ( etat == HIGH)</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> {</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> turnOnNumber(7);</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> delay(500);</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> turnOnNumber(0);</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> delay(500);</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> </span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> loto = random(5,30);</span></i></div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> for (n=2; n <loto;n++)</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> {</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> while (resultat == ancienresultat) resultat=random(1,7);</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> turnOnNumber(resultat);</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> ancienresultat=resultat;</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> delay(500-((loto-n)*20));</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> }</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> }</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">}</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">// ***** set up leds corresponding the number *****</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">void turnOnNumber(int n)</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">{</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> int i;</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> </span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> for(i=0;i<7;i++) //n en décalage de 1 lié à la gestion tableau qui commence à0 </span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> {</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> if (dede[n][i]==0) digitalWrite(i+2, LOW);</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> else digitalWrite(i+2, HIGH);</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> }</span></i></div><div class="separator" style="clear: both; text-align: left;"><i><span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">} //******************************************* FIN DU PROGRAMME ********************************</span></i></div><div style="text-align: left;"><br /></div><br /><br /><a href="http://darduino123.blogspot.com/2014/07/deux-des-arduino-conception-page-2.html" target="_blank">La suite affichage de deux dés</a></div><div><h4></h4></div>Anonymoushttp://www.blogger.com/profile/08797231754964942111noreply@blogger.com0