my link

dimanche 10 avril 2016

Arduino Morse Tutor "ZEN & ART of CW"

Based on the original Morse Tutor kit by Dan Trudgian M0TGN 
 
Based on the book of Carlo Consoli IK0YGJ 
the "ZEN AND THE ART OF RADIOTELEGRAPHY"

video



I do not want to be dependent on a PC or a smartphone to learn Morse code. There with this electronic assembly, I have it in the pocket, I turn ON and the exercise is directly available.
I thought it was much more convenient to me, to make a little Arduino board to learning CW with ajust speed capabilities. The Morse tutor Kit by Dan M0TGN is perfect for that!

I discovered the wonderful book by Carlo IK0YGJ. It is for this reason that there is no display, because we use the book to learn Morse code.



I modified the Arduino M0TGN program so that the Arduino send exercises Morse code of the book . The main difficulty was that all exercises fit into is in Arduino.
Thank to Fred F1UIH helped me. We discovered the use of PROGMEM, and its reading method "pgm_read_byte_near"!


Schematic:



To select the good exercises:



be carrefull minor change with the M0TGN Kit:
#define dotPeriod (analogRead(0)/8+30) is modified to adapt for my Arduino Mini Pro
please change with the good PIN for the M0TGN kit version at analogRead(2)

I add a lipo battery (380mAh), battery charger, and jack connector. And now it's "mobile" :)

10pcs 5V Mini USB 1A Lithium Battery Charging Board Charger Module (eBay :272124988190)


Somes pictures










The software:


This is 06 july 2016 version for arduino.

// Morse Tutor "ZEN & ART of CW"
// version 1.3 correct some bug... ERROR!!! in original morse code... mhmmm
// original Morse Tutor by Dan Trudgian M0TGN //http://www.m0tgn.com/2015/11/morse-tutor-kits-details.html
// modified april 2016 by Nicolas F4EGX and Fred F1UIH
// to match with le book of Carlo Consoli IK0YGJ http://www.qsl.net/ik0ygj/enu/
// the "ZEN AND THE ART OF RADIOTELEGRAPHY"

// be carrefull: at line 130 #define dotPeriod (analogRead(0)/8+30) is modified
// please change with the good PIN for the M0TGN kit version at analogRead(2)...
// And minor change with some delay in this version.


#include <avr/pgmspace.h>
int jour=0;
int week=0;
char tutor_CHARACTERS[150];

const int J1Pin = 4; // pour la selection du jour
const int J2Pin = 5; //
const int J3Pin = 6; //
const int W1Pin = 7; // pour la selection de la semaine
const int W2Pin = 8; //
const int W3Pin = 9; //
const int backPin = 10; //

//test
char test[]= {'P','O','U','F',};
//Semaine 1 -Jour N°1:
const char S1J1[]PROGMEM="TANTE NTENT NMEMN MEEII NMMMN ETEII EIMNM AAEMM ITENM NAANA TMTNE AAIET TETNN ITEEE EIENI TIMIA NNEAT IMNNA MIMIN TINAM MMENT AMMTE ANTMA EEETT NNIAE";
//Semaine 1 -Jour N°2:
const char S1J2[]PROGMEM="TEAIM AAETN INATE EAINI EITNI MIETA NTNEE MEEIE IIIAT ENAIA MAMIT EAMNI ANEIA TTMIM TAAEA TETAN IMTIA ENNMM NTIAT IEMAI TEEMN NAEMN NANAN NITMT EMIAA";
//Semaine 1 -Jour N°3:
const char  S1J3[]PROGMEM="EINEN AETMI ATTMT NAMIA TMIIT ETIEE MTIIT MIAIE MTNAM MENNA IAAMM ETANM ETNMA IETTM NMNAE ETAAA TATAI NNANN NMEMA ANTET AENTE EIIAE ANNAI IENTI TTENN";
//Semaine 1 -Jour N°4:
const char  S1J4[]PROGMEM="TIAMA INNAA TMINN TTNTA ENITN TEAAM NTTNA AMEMI NMMMA NMANE AIIMN TMIEM NNTTI NMTME NMTMN IEEET AIEIE TETTE NNENN IMINI INAEE MMTAM ATAMT ANEMA TMMEM";
//Semaine 1 -Jour N°5:
const char  S1J5[]PROGMEM="ANATA AMMAM ITIAT IIEEE ATAEM NAMAM MIETT NIINN IEAEA IMMMN ITTNM MITTN TIETA TMTMA MITMN AETET MEMII ITEIE NNIAI TAEET EITMA MMMNE TMNEN TNTNT MIINT";
//Semaine 1 -Jour N°6:
const char  S1J6[]PROGMEM="INIAM AIETI EMAAE AEMEA IIIIE ANATI MTTAM ITTTI TAEIT TAMMN ATIIT MEEMM ATTAT MNEMN TNMMI TTAIE TEIEM AMIMI EETEM METNE MITIA EIMIN ITMAT IAINT IMETT";
//Semaine 1 -Jour N°7:
const char  S1J7[]PROGMEM="INIAM AIETI EMAAE AEMEA IIIIE ANATI MTTAM ITTTI TAEIT TAMMN ATIIT MEEMM ATTAT MNEMN TNMMI TTAIE TEIEM AMIMI EETEM METNE MITIA EIMIN ITMAT IAINT IMETT";

//Semaine 2 -Jour N° 1:
const char  S2J1[]PROGMEM="CDDDC CSROU SUCCS CDORU SUSCS UDRSC RDDSC RUCSC SUUOU ORSOS ODDSS UUDSO RCSSU CRRRR RODDD CCCOR OCCOS SSDSO URDSR CUDOD CSCOS CROSO CDDOC SRROC RCSUC";
//Semaine 2 -Jour N° 2:
const char  S2J2[]PROGMEM="SNMIT TADND SRNOM RDAMC RMNDR RCUIO ITDSM RAIDT CSOES EETDO DSIUS RADER OETRT AODCS CESRA EOAUD DETIC SCMEO TRSEO AUCCO TCSST IEUMA TUMMR NDAAA CRIOR";
//Semaine 2 -Jour N° 3:
const char  S2J3[]PROGMEM="COINR CMIEM CCIMR OCMSA OIIIT OTOMN DINRS UASIN OIERD IOCMI SMAIS CDRRO CUODS AMOER ACTAD AAEOU EUNEM UATUI OOEMD NROUI INNMC ONAUS TECNM SIRED ISDID";
//Semaine 2 -Jour N° 4:
const char  S2J4[]PROGMEM="SSSOS RSMDN RCOTA TUSRR USDAM MITMA MEEMD OMUDN RAETS CESUC RUSMR NRDSR DMUII AAACS UODEU UNIOI SIOEO EMSNR IADMS MNRNS ODREU SCRES INONR UADUO ORNNE";
//Semaine 2 -Jour N° 5:
const char  S2J5[]PROGMEM="DTOUU OSCTC TTCUM UUTRN TNIDD ESANT RUAAO OCNEU STEID AEMOM ACNRU IUECA RAIUI NNECT CNCDI CCMCI ONINM DCCUN OIUUN NNNSI RSDNU RDTMI INAUT TUTCA MSEOE";
//Semaine 2 -Jour N° 6:
const char  S2J6[]PROGMEM="DSUTS AOTRU CUUIT NNTOS ESNOA MRTTN UTDCU OTTDA MOTTU IMOCN IMESS SNMMA TRSUC ICOAO UENTO NIDSS ORRAR MUTTI ISIAD SDACS MMUTA MUDOR DAEIT OESOU TIRIS";
//Semaine 2 -Jour N° 7:
const char  S2J7[]PROGMEM="NOODO IARCO OTOOU MTDAC ATSME CMAAI NIDDA ERDMD UAMMU REIMA NUOCA DISRT EDIRE SSMMA MUONR ROISE ECISN RMUUA UUTST ASNOR AOTTC CTUTD RTSRE DMDAE RENDN";


//Semaine 3 -Jour N° 1:
const char  S3J1[]PROGMEM="GKPGP BPKPP WKGLG GBBBW GPGWB LBPLK WGLLW KPWWG PBGPB KBPBW PGWKP GWKBW KPBGP KGPLL GBBPW KGGWG PKPLG BGGWB PKKPG KGKBW WPLLP GKPLL BLKWG WGKKB BPGGW";
//Semaine 3 -Jour N° 2:
const char  S3J2[]PROGMEM="EDGMK IBCUR GWNRB BTISI PWGOS TOMLD UGUWP CEIPD CBMDB DWTOB OSCSP ABRGW MIASM GGORA UGURA GKBTK CSKBD GCOMM MKARA NLALD PLEKD GUMEO EACPU KANNK TOPRT";
//Semaine 3 -Jour N° 3:
const char  S3J3[]PROGMEM="BWLRP LCEIL LCKIR BNMKO RRDLR LOOTN IOLLE AKKIA SLELA IBKEB NPTKA GKMCO AWSDO EDGAM TRMNW LAWCR SLKDU SIAPE IKKSN BDMSM WSTPR SWENU LMIUW RPMSO BLWLT";
//Semaine 3 -Jour N° 4:
const char S3J4[]PROGMEM="RPAUW PNTDT WILBE WOKPR APPEL ETULT DGUBP OODBG AKOUI TEAUU OOKSG CNMOC SIOSK KADWL MSGAO ISMUG GTCIN APNPL EPRRA RSBWN DEOWI IWTAE RMTRL GKCMS AASAU";
//Semaine 3 -Jour N° 5:
const char  S3J5[]PROGMEM="PSMPN MGDWG SBLOP UIULW KEKPG LABTB TTRCL WCILA DDDOM EBKLD SLWIR KOCUG NRKKB SWBEC OMTWO KTMOB BGRWM OEKEK DSNRI KCKOA RNLIB MUEKR IBWIB IDPMG WPCBL";
//Semaine 3 -Jour N° 6:
const char  S3J6[]PROGMEM="PIRTC AGBCU ARBCC GIDGD TDMAB OAMSL UTACC UETNB NPSDW CACOD TGIWI KPWOE GBULO RRAOA CWAOG BKPLA LREPK UMPOK CCCUO RKEMK AUTUN LISME TDKWG LEDRR ILOGR";
//Semaine 3 -Jour N° 7:
const char  S3J7[]PROGMEM="LAMOC WTCCS DUGNE SIBRR KIICA OSAIL MROOE WURDU PKUNN GDRKI DSIRN KUIBI MEDIB BEROD GNCPL AUUCC LIGML WKCDG ENLCP MULAO GTBSA PBBRB BIRWI EBTWN BSUGB";


//Semaine 4 -Jour N° 1:
const char  S4J1[]PROGMEM="HFQQY YFFQH YQQQH FYHHQ YHFHY QYYYY YFFFF FYYHH FQYYF YYHQF QYQHF QQYQY QFFHH QYHQY FQFFH FQFQH QHQYY HFHHH YHFYQ YQHQH QYQQY YFHQH YHQQH YQHQY FQHQQ";
//Semaine 4 -Jour N° 2:
const char  S4J2[]PROGMEM="QPRRR EFHPL FICMU FAUQM NQSRR WHPOO FOHTB AUMGF GUWYE ITYIO MWPGI BOLSR COOMY MLMOH TMGUB MNDDE NPCEC NWWDY AFBQM QCUFL CWHKU EDOKS PFMYD UCUFY EGYTS";
//Semaine 4 -Jour N° 3:
const char  S4J3[]PROGMEM="SKMFI ECRNE ETIEW BPCSU QHQDY TMAWH IANPT ISTAO LCKKO WLATG BTBBU LLFEP PBHPS AAHKE HTLYH OCMCM LEFAE BKRNP MEOFY WNRCO BIFIQ WPLWL LEIOH PIYAR BMCHP";
//Semaine 4 -Jour N° 4:
const char  S4J4[]PROGMEM="HIQRR ANQUI MKKOM UPTWT WWBWE NUEIW RMIDT QUMII BGPCN GHCIP ESWPO QCSMQ WHBDM NPHRS DRYDM EAFSA KCEYH BHGCB WDWLE BKLCG OSTPG QAPUF HACNT LNSKH IFPTI";
//Semaine 4 -Jour N° 5:
const char  S4J5[]PROGMEM="IGBRO DGMQU CLNQE STBPT WYONR LTOSO SRPGQ POSYR ECRCW YBUUS IKNDI WDYWF BMAEM ULUIM TTTCU MCCLN NDPMP CAINO EATHB NNNBA HCGKL TTACC HMECH BGSTM NSLOT";
//Semaine 4 -Jour N° 6:
const char  S4J6[]PROGMEM="FPPAM PNQGN OUTCI ONNTC SUTUA OTLYU WLNPE UCPTG IQNIE FBQDC GGILS RWTGF UMKDB PYAYA IGBRT TNMRY CSTGY WIEQE GOPPN MHWIG FAOEB ROGAG BDUUR KCENW OPEIF";
//Semaine 4 -Jour N° 7:
const char  S4J7[]PROGMEM="SOCSL PEMEH NWFQF HHSPT UGBQG IEQQS UWBAC EQSEW GGDCC OFUDI FCMGL YUUBU LSWCY ERUAO KSCHB OFSBG AKHPQ BWKTY QQBFT BSOOG NTRKC WIUIO IQTNO SOAGY EQYHY";


//Semaine 5 -Jour N° 1:
const char  S5J1[]PROGMEM="ZJXJJ JZJJX JVVZX VXXZX ZZXJV JVZZJ ZXVVJ VJJVZ ZZZVX XVXVJ XXXVX VXJZJ JVZJJ VZVJV ZZZZJ ZXJJV JJZZX JZVJX ZXJXV VJJXX JXZJV JJVXJ ZZZVV XJJVX ZJVJZ";
//Semaine 5 -Jour N° 2:
const char  S5J2[]PROGMEM="JWWRC PSQRK HEDRN BPNAH VRSDO MCMLO PAKBM XFTJR SZYEN TEEFP AJPRU OSQBV UYPDD DXXIC UYEUW HLWIG IJVXY SCRZM ISGZE SOHYD NWZBF WGYNX DUXLZ VXKHT TQAFK";
//Semaine 5 -Jour N° 3:
const char  S5J3[]PROGMEM="CHVYQ CSZGZ QVZFC BNXUP PDGMH OEVLH BHMSK UFFPK KGBIH ZPUIV FGVFK IVMCY HJBNO HZJZH MGDED ZTVDH QUGZI HSACZ QZLUW XLQCG DOOGN MBJBK PSAON IOJQB GBMKN";
//Semaine 5 -Jour N° 4:
const char  S5J4[]PROGMEM="WAWNZ ALEQR RDGUP JPDXM RCJLM DDLFY DPCLK OQPJY SUJFR PKEJP WZZQD IVZEP BBCVJ HTTOM RRRIP IHSFT JNJWT XFRML ADIKX PFUFA DWOBR VZXAU HAYWY RQMIR QLHIW";
//Semaine 5 -Jour N° 5:
const char  S5J5[]PROGMEM="JUMTU GPGHS LNQLQ MLUQF OPRZI JSFBE NAXBU HLWRL ISUSU VXUHA MSILK ATXVN HQAMT QUAVI MUHRQ CRSJY ACTMC KWJVB FSXLX GXQZM KGAOM APGUQ ZBYSY VSLTW TUCRM";
//Semaine 5 -Jour N° 6:
const char  S5J6[]PROGMEM="XBVOS CPKAE HYMBW ZLRNK XNFJP MIFBT BDHBB SLUGO FSRXL PQWJU XQQXP WIVYW MLBKC CHIVS AVJQW BNWQX ZPUWV KHAPU OZEBL BERSI ZRNAN XBSWS KOJPD IJCXZ TLKIO";
//Semaine 5 -Jour N° 7:
const char  S5J7[]PROGMEM="GZQCE ZTPWL ADMRR UURZL ABYXY EMJFM HXIYE SLITF DWOST CODEK ATAQH VVFPV EAPJQ JJKVQ JSYFZ UPBGZ NZLMR BZHMG VYBYM EPNKA KZIKW DGQTH HEMAS CMZZM VPGEE";


//Semaine 6 -Jour N° 1:
const char  S6J1[]PROGMEM="33141 12525 24435 51213 52411 52425 35413 12515 55335 42215 34512 44514 23554 41243 42122 53221 41354 41145 14253 34154 43132 25521 24153 21331 54155";
//Semaine 6 -Jour N° 2:
const char  S6J2[]PROGMEM="XVZBQ 68499 HPXWP 60896 QHBJT BMHPK 93208 XUFXS 16504 VIUME KLGXF 82508 IGTSL 66304 XMIYJ UWJKE 16139 JDYHG 33288 EBAMH NSBVO 78156 EUXKX 79385 IRDRC";
//Semaine 6 -Jour N° 3:
const char  S6J3[]PROGMEM="OUSNC 78136 AFHSZ 02369 ZIIZO RTSEN 39103 PBFQD 35514 WLFBQ NLQTH 04053 IVMZO 04393 TOWNY FVTKF 67407 PGCNG 73035 EQVDF ITJVO 76293 ILZFQ 69459 NUUIC";
//Semaine 6 -Jour N° 4:
const char  S6J4[]PROGMEM="EUUCL 28997 NFNKR 82127 BZPOS QIKYR 16952 MEGQI 63601 MEBFX FIJOW 24877 SSKEH 64762 MZZAW NZGFM 05813 GDGBX 63328 VVHTN QATJK 49307 FIWEU 45555 NNHYF";
//Semaine 6 -Jour N° 5:
const char  S6J5[]PROGMEM="WKNOE 45839 FAQAY 83508 HLGMT DUCPI 09406 NSBMN 11423 DPCZY OTDPU 61271 ULRMA 67692 HUNEU BQRTW 42668 NYMSZ 75670 DASRK OBOFA 31623 DDGHQ 12913 SUNQK";
//Semaine 6 -Jour N° 6:
const char  S6J6[]PROGMEM="CEAZK 94686 LGYCI 07706 OSDXX BQYJY 40051 OWAIP 90862 CPDRY YUUBK 80146 HNALK 19601 OXVBH ZNLJN 79062 YZOWL 95891 WFKJC GDTWB 66336 FVLPE 59559 MZNKM";
//Semaine 6 -Jour N° 7:
const char  S6J7[]PROGMEM="KGFAD 38144 EFLPV 89500 LKVVN NCBJV 58831 XYRMT 79169 KBAYZ CRNKK 76717 MVBSB 03521 SHSTN YRDOM 75330 WJHMP 53191 LDIXO UQMJV 31922 DXVXV 46672 FQVEQ";





void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
//#define dotPeriod (60) // For when you have no Variable resistors.
//#define gapSpace (500) // For when we have no Variable resitor
#define gapSpace (constrain((analogRead(3)-200)*2,0,2023))
#define dotPeriod (analogRead(0)/8+30)
#define dahPeriod (dotPeriod*3)
//#define relaxTime (dahPeriod * 1.3) // Relax time to be used between charactors
#define letterSpace (dotPeriod*3+gapSpace)
#define wordSpace (dotPeriod*7+gapSpace)
#define tonePin 3 // Speaker is connected to pin 3
#define buzz (800) // Tine value set here. 800 = 800Hz

pinMode(J1Pin, INPUT_PULLUP);
pinMode(J2Pin, INPUT_PULLUP);
pinMode(J3Pin, INPUT_PULLUP);
pinMode(W1Pin, INPUT_PULLUP);
pinMode(W2Pin, INPUT_PULLUP);
pinMode(W3Pin, INPUT_PULLUP);
pinMode(backPin, INPUT_PULLUP);
delay(200);

//define the week and day for the exercice.
if(digitalRead(J1Pin)){bitSet(jour,0);} else {bitClear(jour,0);}
if(digitalRead(J2Pin)){bitSet(jour,1);} else {bitClear(jour,1);}
if(digitalRead(J3Pin)){bitSet(jour,2);} else {bitClear(jour,2);}
if(digitalRead(W1Pin)){bitSet(week,0);} else {bitClear(week,0);}
if(digitalRead(W2Pin)){bitSet(week,1);} else {bitClear(week,1);}
if(digitalRead(W3Pin)){bitSet(week,2);} else {bitClear(week,2);}



}

void printLetter(char x)
{Serial.println(x);} // debug and compatibilities with M0TGN software

// Array for Mixed
    char MIXED_CHARACTERS[] = {
        // Numbers
        '0', '1', '2', '3', '4',
        '5', '6', '7', '8', '9',
        // Letters
        'A', 'B', 'C', 'D', 'E',
        'F', 'G', 'H', 'I', 'J',
        'K', 'L', 'M', 'N', 'O',
        'P', 'Q', 'R', 'S', 'T',
        'U', 'V', 'W', 'X', 'Y', 'Z',
    };

// Array for numbers only.
    char NUM_CHARACTERS[] = {
        // Numbers
        '0', '1', '2', '3', '4',
        '5', '6', '7', '8', '9',
    };

// Array for Letters only.
    char LETTERS_CHARACTERS[] = {
        // Letters
        'A', 'B', 'C', 'D', 'E',
        'F', 'G', 'H', 'I', 'J',
        'K', 'L', 'M', 'N', 'O',
        'P', 'Q', 'R', 'S', 'T',
        'U', 'V', 'W', 'X', 'Y', 'Z', ' ',
    };





void playLetter(char x)
{
 
  switch (x){
     case 'E':
      dit(); printLetter(x);  return;
    case 'I':
      dit(); dit(); printLetter(x); return;
    case 'S':
      dit(); dit(); dit(); printLetter(x);return;
    case 'A':
      dit(); dah(); printLetter(x);return;
    case 'U':
      dit(); dit(); dah(); printLetter(x);return;
    case 'T':
      dah(); printLetter(x);return;
    case 'M':
      dah(); dah(); printLetter(x);return;
    case 'O':
      dah(); dah(); dah(); printLetter(x);return;
    case 'N':
      dah(); dit(); printLetter(x);return;
    case 'D':
      dah(); dit(); dit(); printLetter(x);return;
    case 'F':
      dit();dit(); dah(); dit(); printLetter(x);return;
    case 'P':
      dit(); dah(); dah(); dit(); printLetter(x); return;
    case 'J':
      dit();dah();dah();dah(); printLetter(x);return;
    case 'L':
      dit(); dah(); dit(); dit(); printLetter(x);return;
    case 'Q':
      dah(); dah(); dit(); dah(); printLetter(x);return;
    case 'X':
      dah(); dit(); dit(); dah(); printLetter(x); return;
    case 'B':
      dah(); dit(); dit();dit(); printLetter(x);return;
    case 'Y':
      dah(); dit(); dah(); dah(); printLetter(x); return;
    case 'W':
      dit(); dah(); dah(); printLetter(x); return;
    case 'R':
      dit(); dah(); dit(); printLetter(x);return;
    case 'H':
      dit(); dit();dit();dit(); printLetter(x);return;
    case 'Z':
      dah();dah();dit();dit();printLetter(x); return;
    case 'G':
      dah(); dah(); dit(); printLetter(x);return;
    case 'K':
      dah(); dit();dah(); printLetter(x); return;
    case 'V':
      dit(); dit(); dit(); dah();printLetter(x); return;
    case 'C':
      dah(); dit(); dah();dit();printLetter(x);return;
    case '1':
       dit(); dah(); dah(); dah(); dah(); printLetter(x);return;
    case '2':
      dit();dit(); ; dah(); dah(); dah();  printLetter(x);return;
    case '3':
      dit(); dit();dit(); dah(); dah();  printLetter(x);return;
    case '4':
      dit();  dit();dit();dit(); dah();  printLetter(x);return;
    case '5':
       dit(); dit();dit(); dit(); dit();printLetter(x);return;
    case '6':
        dah(); dit();dit(); dit(); dit();printLetter(x);return;
    case '7':
       dah(); dah();dit(); dit(); dit();printLetter(x);return;
    case '8':
        dah(); dah(); dah(); dit(); dit();printLetter(x);return;
    case '9':
        dah(); dah(); dah(); dah(); dit();printLetter(x);return;
    case '0':
       dah();dah();dah();dah();dah();printLetter(x);return;
    case ' ':
      delay(wordSpace);return;
    case '/':
       dah();dit();dit();dah();dit(); printLetter(x);return;
       //return;
    default:
        delay(500);tone(tonePin, buzz*2, dotPeriod*4);delay(1000);return;
}

}

void dit()
{
  tone(tonePin, buzz, dotPeriod);
  delay(2*dotPeriod);
}

void dah()
{

  tone(tonePin, buzz, dahPeriod);
    delay(dotPeriod+dahPeriod);
}




void loop() {
  // put your main code here, to run repeatedly:
//int i=2; {
       for (int i = 0; i < 149; i++){
//           Serial.print("i=");
//           Serial.print(i);
//           Serial.print(" ");

           if(!digitalRead(backPin)){i=i-1;}

           if (week==0 && jour==0){playLetter (pgm_read_byte_near(S1J1 + i));}
           if (week==0 && jour==1){playLetter (pgm_read_byte_near(S1J2 + i));}
           if (week==0 && jour==2){playLetter (pgm_read_byte_near(S1J3 + i));}
           if (week==0 && jour==3){playLetter (pgm_read_byte_near(S1J4 + i));}
           if (week==0 && jour==4){playLetter (pgm_read_byte_near(S1J5 + i));}
           if (week==0 && jour==5){playLetter (pgm_read_byte_near(S1J6 + i));}
           if (week==0 && jour==6){playLetter (pgm_read_byte_near(S1J7 + i));}
        
           if (week==1 && jour==0){playLetter (pgm_read_byte_near(S2J1 + i));}
           if (week==1 && jour==1){playLetter (pgm_read_byte_near(S2J2 + i));}
           if (week==1 && jour==2){playLetter (pgm_read_byte_near(S2J3 + i));}
           if (week==1 && jour==3){playLetter (pgm_read_byte_near(S2J4 + i));}
           if (week==1 && jour==4){playLetter (pgm_read_byte_near(S2J5 + i));}
           if (week==1 && jour==5){playLetter (pgm_read_byte_near(S2J6 + i));}
           if (week==1 && jour==6){playLetter (pgm_read_byte_near(S2J7 + i));}
         
           if (week==2 && jour==0){playLetter (pgm_read_byte_near(S3J1 + i));}
           if (week==2 && jour==1){playLetter (pgm_read_byte_near(S3J2 + i));}
           if (week==2 && jour==2){playLetter (pgm_read_byte_near(S3J3 + i));}
           if (week==2 && jour==3){playLetter (pgm_read_byte_near(S3J4 + i));}
           if (week==2 && jour==4){playLetter (pgm_read_byte_near(S3J5 + i));}
           if (week==2 && jour==5){playLetter (pgm_read_byte_near(S3J6 + i));}
           if (week==2 && jour==6){playLetter (pgm_read_byte_near(S3J7 + i));}
         
           if (week==3 && jour==0){playLetter (pgm_read_byte_near(S4J1 + i));}
           if (week==3 && jour==1){playLetter (pgm_read_byte_near(S4J2 + i));}
           if (week==3 && jour==2){playLetter (pgm_read_byte_near(S4J3 + i));}
           if (week==3 && jour==3){playLetter (pgm_read_byte_near(S4J4 + i));}
           if (week==3 && jour==4){playLetter (pgm_read_byte_near(S4J5 + i));}
           if (week==3 && jour==5){playLetter (pgm_read_byte_near(S4J6 + i));}
           if (week==3 && jour==6){playLetter (pgm_read_byte_near(S4J7 + i));}
         
           if (week==4 && jour==0){playLetter (pgm_read_byte_near(S5J1 + i));}
           if (week==4 && jour==1){playLetter (pgm_read_byte_near(S5J2 + i));}
           if (week==4 && jour==2){playLetter (pgm_read_byte_near(S5J3 + i));}
           if (week==4 && jour==3){playLetter (pgm_read_byte_near(S5J4 + i));}
           if (week==4 && jour==4){playLetter (pgm_read_byte_near(S5J5 + i));}
           if (week==4 && jour==5){playLetter (pgm_read_byte_near(S5J6 + i));}
           if (week==4 && jour==6){playLetter (pgm_read_byte_near(S5J7 + i));}
         
           if (week==5 && jour==0){playLetter (pgm_read_byte_near(S6J1 + i));}
           if (week==5 && jour==1){playLetter (pgm_read_byte_near(S6J2 + i));}
           if (week==5 && jour==2){playLetter (pgm_read_byte_near(S6J3 + i));}
           if (week==5 && jour==3){playLetter (pgm_read_byte_near(S6J4 + i));}
           if (week==5 && jour==4){playLetter (pgm_read_byte_near(S6J5 + i));}
           if (week==5 && jour==5){playLetter (pgm_read_byte_near(S6J6 + i));}
           if (week==5 && jour==6){playLetter (pgm_read_byte_near(S6J7 + i));}

           if (week==7 && jour==7){playLetter (MIXED_CHARACTERS[random(0,36)]);} //100% random
           if(!digitalRead(backPin)){i=i-1;}
        
           delay (letterSpace);
           if (i==148){delay(2000);tone(tonePin, buzz*2, dotPeriod*4);delay(500);tone(tonePin, buzz/2, dotPeriod*4);delay(5000);return;}

            
        }
}




1 commentaire:

  1. Bjr Nicolas

    Merci pour l'article.

    Si je peux me permettre, qques petites remarques pour avoir un code plus court, plus efficace et plus structuré :

    Dans setup() :

    - Remplacer les pinMode et digitalWrite par une seule instruction pinMode(pin, INPUT_PULLUP)

    - Supprimer les variables booléennes J1, J2 etc. inutiles et faire :

    if (digitalRead(pinx))
    bitSet(jour, x);
    else
    bitClear(jour, x);

    Dans printLetter :

    - Supprimer le tableau LETTERS_CHARACTERS inutile.

    - De façon générale, on peut supprimer cette fonction qui est alors réduite à Serial.println(x) que l'on peut appeler tel quelle.

    Dans playLetter :

    - Sortir le printLetter de tous les case (de A à Z et 0 à 9 et /) pour le mettre après le switch (et le remplacer par Serial.println comme indiqué plus haut.

    Dans loop :

    - Replacer tous les if (week == x) && (jour == y) par un switch du genre

    switch ((6 * week) + jour) {
    case (0 + 0) : playLetter(etc. S1J1); break;
    case (0 + 1) : playLetter(etc. S1J2); break;
    ...
    case (6 + 0) : playLetter(etc. S2J1); break;
    ...
    }

    On pourrait aussi encore bien améliorer en indexant tous les adresses SxJy dans un tableau pour un accès direct.

    Bonne continuation

    73

    Laurent - F6FVY

    RépondreSupprimer