diff --git a/examples/Stencil/Stencil.ino b/examples/Stencil/Stencil.ino new file mode 100644 index 0000000..20a423e --- /dev/null +++ b/examples/Stencil/Stencil.ino @@ -0,0 +1,25 @@ +// Stencil.ino -- rename first and update this title +// Empty file you can use if the WittyLib.zip has been loaded with Arduino libs +// Cut and paste what you use: +// #include "Witty.h" SetupWitty(); +// #include "GetPush.h" need Witty.h +// #include "Telec.h" need Witty.h +// #include "Apa102.h" SetupApa102(); +// #include "Inter2.h" SetupInter2(); application dependant +// #include "Pfm.h" SetupPfm(); +// #include "TerSer.h" SetupTerSer(); +// #include "I2Ctwi.h" SetupI2Ctwi(); +// SetupGy521(); need I2Ctwi.h + +#include "Witty.h" +// global variables and functions + +void setup() { + SetupWitty(); + +} + +void loop() { + + +} diff --git a/examples/TestApa102/TestApa102.ino b/examples/TestApa102/TestApa102.ino new file mode 100644 index 0000000..e8a1ff5 --- /dev/null +++ b/examples/TestApa102/TestApa102.ino @@ -0,0 +1,28 @@ +//TestApa.ino ok 190330 1224b 38v +// arc en ciel de 0 à 192 manque de l'orangé +#include "Witty.h" +#define Npix 8 // nombre de LEDs +#define Brt 2 // max 31 brigtness +#include "Apa102.h" + +void setup () { + SetupWitty(); + SetupApa102(); + +} + +void loop() { + ApaRainbow(); + DelMs (2000); + + for (byte i=0; i<16; i++) { ApaLogRed (i); DelMs(100);} + for (byte i=16; i>0; i--) { ApaLogRed (i-1); DelMs(100);} + for(;;); +} + +/* + Test ApaRed from 0 to 255 (reduce delay) + Modify Brt value + Modify in the lib parameters of ApaRainbow. Hue etc is explained in doc. +*/ + diff --git a/examples/TestGetPush/TestGetPush.ino b/examples/TestGetPush/TestGetPush.ino new file mode 100644 index 0000000..402e1da --- /dev/null +++ b/examples/TestGetPush/TestGetPush.ino @@ -0,0 +1,41 @@ +// TestGetPush.ino +#include "Witty.h" +#include "GetPush.h" +void setup() { + SetupWitty(); + Cligno(2,200); DelMs(500); // 2 blinks and delay +} +byte choix; +void loop() { + choix= GetPush(); // blink fast + DelMs(500); //little wait to show the transistion + // Direct use of parameter +// DelMs(500); //delay after the confirmation blinks +// Cligno(choix,200); // do the selected task +// DelMs (1000); + + //Test with a switch-case + switch(choix) { + case 1: + Cligno(5,200); + break; + case 2: + AvD; DelMs(500); StopD; DelMs(200); + AvG; DelMs(500); StopG; DelMs(200); + RecD; DelMs(500); StopD; DelMs(200); + RecG; DelMs(500); StopG; DelMs(200); + break; + case 3: + while (!PushOn) { // push to quit + if (IrmOn) {LedOn;} // Test your TV remote + else {LedOff;} + } + while (PushOn) {} + break; + default: + CliErr(3,50,500); // Reset to quit + } // end switch +} // end loop + + +// Write an ErrSOS() function that repeat SOS the marine way (no parameter) diff --git a/examples/TestGy521/TestGy521.ino b/examples/TestGy521/TestGy521.ino new file mode 100644 index 0000000..a818de9 --- /dev/null +++ b/examples/TestGy521/TestGy521.ino @@ -0,0 +1,38 @@ +//TestG521.ino affichage TerSer +// 1g is given as 16384 +#define aadd 0x68*2 // adresse 8bits du 6050 .. a faire mieux + +// déf et variables globales +int16_t GyX,GyY,GyZ; +int16_t AcX,AcY,AcZ; + +#include "Witty.h" +#include "TerSer.h" +#include "I2Ctwi.h" +#include "Gy521.h" + +void setup() { + SetupWitty(); + SetupI2Ctwi(); + SetupGy521(); + SetupTerSer(); +} + +int var; +void loop() { + DelMs(1000); //Wait 1s for stabilisation + Text("Gy521 values"); CR(); + int16_t AcX,AcY,AcZ; + while(1){ + AcX=ReadWordAt(0x3B); //Accelerometer + AcY=ReadWordAt(0x3D); + AcZ=ReadWordAt(0x3F); + + Text(" AcX= "); Dec16s(AcX); + Text(" AcY= "); Dec16s(AcY); + Text(" AcZ= "); Dec16s(AcZ); + CR(); + DelMs (500); + } // end while +} // end loop + diff --git a/examples/TestInter2/TestInter2.ino b/examples/TestInter2/TestInter2.ino new file mode 100644 index 0000000..eac938d --- /dev/null +++ b/examples/TestInter2/TestInter2.ino @@ -0,0 +1,17 @@ +//TestInter.ino Witty +// Clignotement continu par interruption + + +#include "Witty.h" +#include "Inter2.h" + +void setup(){ + SetupInter2(); +} + +void loop() { + for (byte i=10; i<200; i+=2) { + period=i; DelMs(100); + } +} + diff --git a/examples/TestPfm/TestPfm.ino b/examples/TestPfm/TestPfm.ino new file mode 100644 index 0000000..178a358 --- /dev/null +++ b/examples/TestPfm/TestPfm.ino @@ -0,0 +1,27 @@ +//TestMotPfm.ino witty +// On accélère et ralenti les moteurs +// la vitesse max est toujours +/- 80 +#include "Witty.h" +#include "Pfm.h" +#include "Inter2.h" + +void setup(){ + SetupWitty(); + SetupInter2(); +} + +#define MaxVit 70 +void loop() { + LedOff; + for (pfmR=0; pfmR0; pfmR--) {pfmL=pfmR; DelMs(20);} + LedOff; + for (pfmR=0; pfmR>-MaxVit; pfmR--) {pfmL=pfmR; DelMs(20);} + LedOn; + for (pfmR=-MaxVit; pfmR<0; pfmR++) {pfmL=pfmR; DelMs(20);} + LedOff; + pfmL=1; pfmR=1; DelMs(2000); + pfmL=-1; pfmR=-1; DelMs(2000); +} + diff --git a/examples/TestTelec/TestTelec.ino b/examples/TestTelec/TestTelec.ino new file mode 100644 index 0000000..f13e99b --- /dev/null +++ b/examples/TestTelec/TestTelec.ino @@ -0,0 +1,18 @@ +//TestTelec.ino Blink number of pulses + +#include "Witty.h" +#include "Telec.h" +void setup () { + SetupWitty(); +} + +byte nPulses; +void loop() { + nPulses= CompteIR(); + Cligno (nPulses,1000); +} + +/* + Modify the timings on Telec.h + Control the motos as in Demo2 program. + */ diff --git a/examples/TestWitty/TestWitty.ino b/examples/TestWitty/TestWitty.ino new file mode 100644 index 0000000..e5e8d67 --- /dev/null +++ b/examples/TestWitty/TestWitty.ino @@ -0,0 +1,24 @@ +//TestWitty.ino Test Button, Led Cligno and CliErr +#include "Witty.h" +void setup() { + SetupWitty(); + Cligno(3,200); +} + +byte cDel=0; +void loop() { +// Led stay on for 2 second, reactivate after <2 seconds with a push + + while (cDel++<200) { + LedOn; DelMs(2000/200); // 2 + if (PushOn) {cDel=0;} // check every 10ms + } + LedOff; + DelMs(1000); + + Cligno(5,50); + + CliErr(2,200,1000); +// need a reset now +} + diff --git a/examples/WittyDemo2/WittyDemo2.ino b/examples/WittyDemo2/WittyDemo2.ino index c416dd3..7ac737c 100644 --- a/examples/WittyDemo2/WittyDemo2.ino +++ b/examples/WittyDemo2/WittyDemo2.ino @@ -1,11 +1,11 @@ - // WittyDemo2.ino 190419 4434b 112v !! 2 copies ajouté effet lum + // WittyDemo2.ino 190506 4580b 113v distributed on w01-w10 // welcome with Rainbow and fast blink push n times -// 1 push red several move on-off and back to menu -// 2 pushes green same with pfm speed changes -// 3 control blue with most TV IR 1pulse stop, 2,3,4,5 move +// 1 push several move on-off and back to menu +// 2 pushes same with pfm speed changes +// 3 control with most TV IR 1pulse stop, 2,3,4,5 move // 4 demonstrate log dim -// 5 compte -// 6 test accelero Gy521 reset to restart demo +// 5 count in binary +// 6 test accelerometer Gy521 value in terminal 4 orientations on leds #include "Witty.h" #include "GetPush.h" @@ -27,11 +27,12 @@ void setup() { SetupTerSer(); SetupI2Ctwi(); SetupGy521(); - Cli(2); DelMs(500); + Cligno(2,200); } -// Une fonction démo à mettre dans un .h sépare avec par exemple un générateur de caractères -// On veut tester un compteur binaire 1 allumé 0 sombre +// Example of a not simple function binary counter 1 bright 0 dark but visible +// That function has no reason to be included in the Apa102.h file +// Show a byte in any color. void ShowByte (uint8_t nn,uint8_t rr,uint8_t gg,uint8_t bb) { ApaHead(); for (byte i=0; i=0; pfmR--) {pfmL=pfmR; ApaLogBlue(pfmR/5);Dac;} - pfmL=0; pfmR=0; ApaLogWhite(5); D; - for (pfmR=0; pfmR>-MaxVit; pfmR--) {pfmL=pfmR; ApaLogBlue(-pfmR/5);Dac;} - for (pfmR=-MaxVit; pfmR<0; pfmR++) {pfmL=pfmR; ApaLogGreen(-pfmR/5);Dac;} - pfmL=0; pfmR=0; ApaLogWhite(5); D; - DelMs(1000); - cli(); - break; + #define Dac DelMs(10) + for(volatile byte i; i<3; i++) { + D2; + #define MaxVit 80 + for (pfmR=0; pfmR0; pfmR--) {pfmL=pfmR; ApaLogGreen(pfmL/5); Dac;} + for (pfmR=0; pfmR>-MaxVit; pfmR--) {pfmL=pfmR; ApaLogRed(-pfmL/5); Dac;} + ApaLogGreen(2); + for (pfmR=-MaxVit; pfmR<0; pfmR++) {pfmL=pfmR; ApaLogRed(-pfmL/5); Dac;} + pfmL=0; pfmR=0; D1; + } + cli(); + break; + case 3: // Demo IRM control ApaLogWhite(10); byte nPress; @@ -115,10 +111,10 @@ void loop() { nPress= Compte(); switch (nPress) { case 1: // stop - ApaLogGreen(5); + ApaLogRed(5); FreeG; FreeD; break; case 2: // avance - ApaLogRed(5); + ApaLogGreen(5); AvG; AvD; break; case 3: // tourneG ApaLogBlue(5); @@ -133,11 +129,13 @@ void loop() { ShowByte (0x55,5,5,5); FreeG; FreeD; break; } // end switch - } // end while - case 5: // RGB // new numbering + } // end while + // reset to quit + + case 5: // RGB // ApaLog requires interrupt sei(); - for (byte i=0;i<16;i++) {ApaLogRed(i); DelMs(100);} - for (byte i=16;i>0;i--) {ApaLogRed(i-1); DelMs(100);} + for (volatile byte i=0;i<16;i++) {ApaLogRed(i); DelMs(100);} + for (volatile byte i=16;i>0;i--) {ApaLogRed(i-1); DelMs(100);} ApaLogGreen(1);DelMs(1000);ApaLogBlue(1);DelMs(1000);ApaLogRed(1);DelMs(1000); ApaLogGreen(15);DelMs(1000);ApaLogBlue(15);DelMs(1000);ApaLogRed(15);DelMs(1000); // max intensity // add your own tricks diff --git a/library.properties b/library.properties index 2d26a4a..633338e 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ name=Witty -version=1.0.0 +version=1.0.1 author=Didel maintainer=Boxtec sentence=Witty Support Library paragraph=Several support libraries for the Witty self-balancing 2WD bot from Didel.com. See the WittyQuickStartGuide.pdf in the docs folder. category=Other url=https://git.boxtec.ch/didel/Witty -architectures=* \ No newline at end of file +architectures=* diff --git a/src/I2Ctwi.h b/src/I2Ctwi.h index 1dcd771..df8bc5b 100644 --- a/src/I2Ctwi.h +++ b/src/I2Ctwi.h @@ -1,6 +1,6 @@ //#include "I2Ctwi.h" TWI et fonctions composées // inside PP #include "I2Ctwi.h" SetupI2Ctwi(); -//#include // pas nécessaire? +#include // pas nécessaire? // aadd defini dans pp avec #define aadd valeur adresse 8 bits sélect // ? changera avec paramètre explicite? ou nom G521Twi byte status; diff --git a/src/Inter2.h b/src/Inter2.h index 929ce2a..6110247 100644 --- a/src/Inter2.h +++ b/src/Inter2.h @@ -1,12 +1,17 @@ //Inter2.h -//Dans PP #include "Inter2.h" SetupInter2(); -volatile byte cpf,cup,cdo; +//Begin main progr #include "Inter2.h" SetupInter2(); +volatile byte period; +volatile uint16_t tt; +void DoCligno() { + if (tt++ > period) { + tt=0; LedToggle; + } +} +volatile byte cpf; ISR (TIMER2_OVF_vect) { -// TCNT2 = 256-20; // 2M 20 11us 100 35us 200 85us - TCNT2 = 141; // 58 us calibre pour Tell - cup++;cdo++; - if (cpf++ > 35) { cpf=0; // toutes les 35x58= 2ms - DoPfm (); //durée 2us + TCNT2 = 141; // 58 us period + if (cpf++ > 18-1) { cpf=0; // toutes les 18x58= ~1ms + DoCligno(); // durée <2us } } @@ -14,7 +19,6 @@ void SetupInter2() { // initialisation TCCR2A = 0; //default TCCR2B = 0b00000010; // 2MHz TIMSK2 = 0b00000001; // TOIE2 - //TIFR2 flag TOV2 - sei(); + sei(); // Interrupt enabled } diff --git a/src/Pfm.h b/src/Pfm.h index 29205e0..5943b06 100644 --- a/src/Pfm.h +++ b/src/Pfm.h @@ -1,7 +1,14 @@ //Pfm.h avec table vit //#include "Pfm.h" SetupPfm(); dans le pp -volatile int8_t pfmL, pfmR; // -80 .. +80 +volatile char vitL, vitR; // -15..+15 saturé dans inter +volatile char pfmL, pfmR; // -80 .. +80 +//#define MaxVit 15 #define MaxPfm 80 +char taVitR []= {-80,-70,-60,-51,-43,-35,-28,-22,-18,-14,-11,-8,-5,-2,0,\ + 0,0,2,5,8,11,14,18,22,28,35,43,51,60,70,80}; +char taVitL []= {-80,-70,-60,-51,-43,-35,-28,-22,-18,-14,-11,-8,-5,-2,0,\ + 0,0,2,5,8,11,14,18,22,28,35,43,51,60,70,80}; + volatile byte pfmCntL; volatile byte pfmCntR; void DoPfm () { diff --git a/src/Witty.h b/src/Witty.h index 12d59cf..896c0b9 100644 --- a/src/Witty.h +++ b/src/Witty.h @@ -1,9 +1,6 @@ -//Witty.h 190124 voir www.didel.com/Witty.pdf +//Witty.h 190331 ref voir www.didel.com/WittySoft.pdf //Dans PP #include "Witty.h" SetupWitty(); -//Strip RGB - voir Apa102.h et www.didel.com/ApaWitty.pdf -//Gy521 - voir Gy521.h www.didel.com/Gy521Witty.pdf -//Simple teled control -//Push et Led - voir GetPush.h et https://www.didel.com/diduino/Poussoir.pdf + #define bLed 1 // PORTC #define bPush 0 // actif à zero #define PushOn (!(PINC&(1<