import latest version of libraries + new examples

master
parent 983eb7ba98
commit 7e7093a91a

@ -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() {
}

@ -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.
*/

@ -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)

@ -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

@ -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);
}
}

@ -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; pfmR<MaxVit; pfmR++) {pfmL=pfmR; DelMs(20);}
LedOn;
for (pfmR=MaxVit; pfmR>0; 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);
}

@ -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.
*/

@ -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
}

@ -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 // welcome with Rainbow and fast blink push n times
// 1 push red several move on-off and back to menu // 1 push several move on-off and back to menu
// 2 pushes green same with pfm speed changes // 2 pushes same with pfm speed changes
// 3 control blue with most TV IR 1pulse stop, 2,3,4,5 move // 3 control with most TV IR 1pulse stop, 2,3,4,5 move
// 4 demonstrate log dim // 4 demonstrate log dim
// 5 compte // 5 count in binary
// 6 test accelero Gy521 reset to restart demo // 6 test accelerometer Gy521 value in terminal 4 orientations on leds
#include "Witty.h" #include "Witty.h"
#include "GetPush.h" #include "GetPush.h"
@ -27,11 +27,12 @@ void setup() {
SetupTerSer(); SetupTerSer();
SetupI2Ctwi(); SetupI2Ctwi();
SetupGy521(); 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 // Example of a not simple function binary counter 1 bright 0 dark but visible
// On veut tester un compteur binaire 1 allumé 0 sombre // 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) { void ShowByte (uint8_t nn,uint8_t rr,uint8_t gg,uint8_t bb) {
ApaHead(); ApaHead();
for (byte i=0; i<Npix; i++) { for (byte i=0; i<Npix; i++) {
@ -44,70 +45,65 @@ void ShowByte (uint8_t nn,uint8_t rr,uint8_t gg,uint8_t bb) {
byte cPush; byte cPush;
byte cnt5=0; // test 5 byte cnt5=0; // test 5
#define D DelMs(1000) #define D02 DelMs(200)
#define D2 DelMs(2000) #define D05 DelMs(500)
#define D1 DelMs(1000)
#define D2 DelMs(2000)
void loop() { void loop() {
cli(); // if Demo3 before cli(); // if Demo3 before
ApaRainbow(); ApaRainbow();
cPush= GetPush(); cPush= GetPush();
switch (cPush) { switch (cPush) {
D2;
case 1: // Demo1 Move case 1: // Demo1 Move
byte cmo; ApaLogRed(4);
cmo=2; AvD; AvG; D05; // Avance
while(cmo--){ // on répète 2 fois StopG; StopD; D05;
ApaLogRed(1); AvD; D05; //TourneG
AvD; AvG; D; // Avance StopG; StopD; D05;
StopG; StopD; D; AvG; D05; // TourneD
ApaLogGreen(4); StopG; StopD; D05;
AvD; D; //TourneG RecD; RecG; D05; // Recule
StopG; StopD; D; StopG; StopD; D05;
ApaLogBlue(4); AvD; AvG; D05; RecD; RecG; D05;
AvG; D; // TourneD BlockG; BlockD; D05;
StopG; StopD; D; ApaLogGreen(4); AvG; RecD; D1;
ApaLogWhite(4); ApaLogBlue(4); AvD; RecG; D1;
RecD; RecG; D; // Recule BlockG; BlockD; D05;
StopG; StopD; D; ApaLogWhite(4); AvD; AvG; D05; RecD; RecG; D05;
ApaLogRed(15); StopG; StopD; ApaLogRed(4);D02;ApaLogGreen(4);D02;
AvD; AvG; D; RecD; RecG; D;
BlockG; BlockD; D;
}
break; break;
case 2: // Demo2 Pfm Move case 2: // Demo2 Pfm Move
ApaLogBlue(10); ApaLogBlue(10);
SetupInter2(); SetupInter2();
ApaLogGreen(1); pfmL=2; pfmR=2; D2;D2;
pfmL=1; pfmR=1; D2; pfmL=-2; pfmR=-2; D2;D2;
ApaLogGreen(2);
pfmL=2; pfmR=2; D2;
ApaLogGreen(4);
pfmL=4; pfmR=4; D2; pfmL=4; pfmR=4; D2;
ApaLogGreen(8); pfmL=-4; pfmR=-4; D2;
pfmL=8; pfmR=8; D; pfmL=16; pfmR=16; D1;
ApaLogGreen(10); pfmL=0; pfmR=0; D2;
pfmL=20; pfmR=20; DelMs(500); pfmL=-16; pfmR=-16; D1;
ApaClear(); pfmL=0; pfmR=0; D2;
pfmL=0; pfmR=0; D; pfmL=70; pfmR=70; D05;
ApaLogRed(10); pfmL=0; pfmR=0; D2;
pfmL=-20; pfmR=-20; DelMs(500); pfmL=-70; pfmR=-70; D05;
pfmL=0; pfmR=0; D; pfmL=0; pfmR=0; D1;
ApaLogRed(15);
pfmL=70; pfmR=70; DelMs(300);
pfmL=0; pfmR=0; D;
ApaLogYellow(15);
pfmL=-70; pfmR=-70; DelMs(300);
pfmL=0; pfmR=0; D;
ApaLogBlue(2); ApaLogBlue(2);
#define Dac DelMs(20) #define Dac DelMs(10)
#define MaxVit 75 // 15x5 a cause int logique leds for(volatile byte i; i<3; i++) {
for (pfmR=0; pfmR<MaxVit; pfmR++) {pfmL=pfmR; ApaLogGreen(pfmR/5);Dac;} D2;
for (pfmR=MaxVit; pfmR>=0; pfmR--) {pfmL=pfmR; ApaLogBlue(pfmR/5);Dac;} #define MaxVit 80
pfmL=0; pfmR=0; ApaLogWhite(5); D; for (pfmR=0; pfmR<MaxVit; pfmR++) {pfmL=pfmR; ApaLogGreen(pfmL/5); Dac;}
for (pfmR=0; pfmR>-MaxVit; pfmR--) {pfmL=pfmR; ApaLogBlue(-pfmR/5);Dac;} ApaLogRed(2);
for (pfmR=-MaxVit; pfmR<0; pfmR++) {pfmL=pfmR; ApaLogGreen(-pfmR/5);Dac;} for (pfmR=MaxVit; pfmR>0; pfmR--) {pfmL=pfmR; ApaLogGreen(pfmL/5); Dac;}
pfmL=0; pfmR=0; ApaLogWhite(5); D; for (pfmR=0; pfmR>-MaxVit; pfmR--) {pfmL=pfmR; ApaLogRed(-pfmL/5); Dac;}
DelMs(1000); ApaLogGreen(2);
cli(); for (pfmR=-MaxVit; pfmR<0; pfmR++) {pfmL=pfmR; ApaLogRed(-pfmL/5); Dac;}
break; pfmL=0; pfmR=0; D1;
}
cli();
break;
case 3: // Demo IRM control case 3: // Demo IRM control
ApaLogWhite(10); ApaLogWhite(10);
byte nPress; byte nPress;
@ -115,10 +111,10 @@ void loop() {
nPress= Compte(); nPress= Compte();
switch (nPress) { switch (nPress) {
case 1: // stop case 1: // stop
ApaLogGreen(5); ApaLogRed(5);
FreeG; FreeD; break; FreeG; FreeD; break;
case 2: // avance case 2: // avance
ApaLogRed(5); ApaLogGreen(5);
AvG; AvD; break; AvG; AvD; break;
case 3: // tourneG case 3: // tourneG
ApaLogBlue(5); ApaLogBlue(5);
@ -133,11 +129,13 @@ void loop() {
ShowByte (0x55,5,5,5); ShowByte (0x55,5,5,5);
FreeG; FreeD; break; FreeG; FreeD; break;
} // end switch } // end switch
} // end while } // end while
case 5: // RGB // new numbering // reset to quit
case 5: // RGB // ApaLog requires interrupt
sei(); sei();
for (byte i=0;i<16;i++) {ApaLogRed(i); DelMs(100);} for (volatile 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=16;i>0;i--) {ApaLogRed(i-1); DelMs(100);}
ApaLogGreen(1);DelMs(1000);ApaLogBlue(1);DelMs(1000);ApaLogRed(1);DelMs(1000); 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 ApaLogGreen(15);DelMs(1000);ApaLogBlue(15);DelMs(1000);ApaLogRed(15);DelMs(1000); // max intensity
// add your own tricks // add your own tricks

@ -1,9 +1,9 @@
name=Witty name=Witty
version=1.0.0 version=1.0.1
author=Didel <info@didel.com> author=Didel <info@didel.com>
maintainer=Boxtec <info@boxtec.ch> maintainer=Boxtec <info@boxtec.ch>
sentence=Witty Support Library 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. paragraph=Several support libraries for the Witty self-balancing 2WD bot from Didel.com. See the WittyQuickStartGuide.pdf in the docs folder.
category=Other category=Other
url=https://git.boxtec.ch/didel/Witty url=https://git.boxtec.ch/didel/Witty
architectures=* architectures=*

@ -1,6 +1,6 @@
//#include "I2Ctwi.h" TWI et fonctions composées //#include "I2Ctwi.h" TWI et fonctions composées
// inside PP #include "I2Ctwi.h" SetupI2Ctwi(); // inside PP #include "I2Ctwi.h" SetupI2Ctwi();
//#include <Arduino.h> // pas nécessaire? #include <Arduino.h> // pas nécessaire?
// aadd defini dans pp avec #define aadd valeur adresse 8 bits sélect // aadd defini dans pp avec #define aadd valeur adresse 8 bits sélect
// ? changera avec paramètre explicite? ou nom G521Twi // ? changera avec paramètre explicite? ou nom G521Twi
byte status; byte status;

@ -1,12 +1,17 @@
//Inter2.h //Inter2.h
//Dans PP #include "Inter2.h" SetupInter2(); //Begin main progr #include "Inter2.h" SetupInter2();
volatile byte cpf,cup,cdo; volatile byte period;
volatile uint16_t tt;
void DoCligno() {
if (tt++ > period) {
tt=0; LedToggle;
}
}
volatile byte cpf;
ISR (TIMER2_OVF_vect) { ISR (TIMER2_OVF_vect) {
// TCNT2 = 256-20; // 2M 20 11us 100 35us 200 85us TCNT2 = 141; // 58 us period
TCNT2 = 141; // 58 us calibre pour Tell if (cpf++ > 18-1) { cpf=0; // toutes les 18x58= ~1ms
cup++;cdo++; DoCligno(); // durée <2us
if (cpf++ > 35) { cpf=0; // toutes les 35x58= 2ms
DoPfm (); //durée 2us
} }
} }
@ -14,7 +19,6 @@ void SetupInter2() { // initialisation
TCCR2A = 0; //default TCCR2A = 0; //default
TCCR2B = 0b00000010; // 2MHz TCCR2B = 0b00000010; // 2MHz
TIMSK2 = 0b00000001; // TOIE2 TIMSK2 = 0b00000001; // TOIE2
//TIFR2 flag TOV2 sei(); // Interrupt enabled
sei();
} }

@ -1,7 +1,14 @@
//Pfm.h avec table vit //Pfm.h avec table vit
//#include "Pfm.h" SetupPfm(); dans le pp //#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 #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 pfmCntL;
volatile byte pfmCntR; volatile byte pfmCntR;
void DoPfm () { void DoPfm () {

@ -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(); //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 bLed 1 // PORTC
#define bPush 0 // actif à zero #define bPush 0 // actif à zero
#define PushOn (!(PINC&(1<<bPush))) // pull-up int #define PushOn (!(PINC&(1<<bPush))) // pull-up int
@ -58,17 +55,13 @@ void Delus (uint16_t dm) { // 182-152
for (uint16_t i=0; i<dm; i++) {nop;nop;nop;} for (uint16_t i=0; i<dm; i++) {nop;nop;nop;}
} }
void Cli(byte nn) { // do not use void Cligno(byte nn,int dd) {
for (byte i=0; i<2*nn; i++) { LedToggle; DelMs(300);}
}
void Cligno(byte nn,byte dd) {
for (byte i=0; i<2*nn; i++) { LedToggle, DelMs(dd);} for (byte i=0; i<2*nn; i++) { LedToggle, DelMs(dd);}
} }
void CliErr (byte ct,byte dd) { void CliErr (byte ct,int dd, int ww) {
while(1) { while(1) {
Cligno (ct,dd); Cligno (ct,dd);
DelMs (1000); DelMs (ww);
} }
} }

Loading…
Cancel
Save