Transférer les fichiers vers 'offok'

This is a test console for a TVBGONE.

It gets IR codes send by TVBGONE, and displays each code on OLED.
In the end if enough code have been send it plays a merry tune,
otherwise it plays a sad tune.

offok.ino is the main file.

offok_logo.h holds the splashscreen

offok_tune.h defines variables loaded with tunes in RTTTL format
This commit is contained in:
JeArz 2021-05-20 06:23:37 +02:00
parent bdb0d49e53
commit 7702f6408a
3 changed files with 317 additions and 0 deletions

171
offok/offok.ino Normal file
View File

@ -0,0 +1,171 @@
/*--------------------------------------------------------------*/
/* Projet: OFFOK */
/* File : offok.ino */
/* Author: JeARZ 02/14/21 */
/*--------------------------------------------------------------*/
/*
This gets IR codes send by a TvBeGone & displays results on OLED
02/14/21: First proof of IR sensor & Oled
02/17/21: Moved to new lib U8g2lib, works OK on UNO
04/05/21: OK on NANO
04/22/21: new logo, display hex code, test piezo OK
05/19/21: added offok_tunes.h for rtttl libraries & ringtones
logo.h renamed to offok_logo.h
TODO: adjust parameters, use protothreads ?
*/
#include <Arduino.h>
/*
Graphics settings
*/
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2\
(U8G2_R0, /* RST=*/ U8X8_PIN_NONE);
#include "offok_logo.h" // Home logo :-)
/*
IR settings
*/
#include <IRremote.h>
/* the function tone() uses timer2 by default, so does IRremote lib.
* File IRremoteBoardDefs.h, in lib IRremote define wich timer to use */
// #define IR_USE_TIMER1 // use Timer 1 instead of Timer 2
const int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;
/*
* Sound settings
*/
#define PIEZO 7 // Loudspeaker pin
#include "offok_tunes.h" // predefined ringtones juke-box :-)
//#define DEBUG
#define SOUND_ON // comment if you can't stand
#define NBCODES 120 // min number of codes to qualify a kit
#define ACQUINONE 4000 // no IR signal timeout in millisecond
// ==================== Functions ====================
void showTrace(); // defined after main ifdef DEBUG
void showCount(int val) ; // defined after main not used anymore
// play a rtttl ringtone definef in offok_tunes.h
void play_r3tl (const char * rtune){
#ifdef SOUND_ON
anyrtttl::blocking::play(PIEZO, rtune);
#endif
}
void drawLogo(void) { // draw the logo screen
u8g2.firstPage();
do {
u8g2.drawXBMP( 0, 0, logo_width, logo_height, logo_bits);
} while ( u8g2.nextPage() );
}
// Oled brightness dimmer, slope up or down
void constratSlope(int depart, int aim, int inc, int lag) {
int i=depart;
// at first, if increasing then
if (inc > 0) u8g2.setPowerSave(0); // disable oled
do {
i=constrain(i,0,254);
u8g2.setContrast(i); // 0 (no contrast) to 255
delay (lag);
i=i+inc;
} while (i != aim);
// at end, if decreasing then
if (inc < 0) u8g2.setPowerSave(0); // disable oled
}
// & at the end ... the winner is
void showResult(int val){
char l1[8];
sprintf(l1, "%4d",val);
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_profont17_tr);
u8g2.drawStr(10,24, "Total recus :");
u8g2.setFont(u8g2_font_profont22_tr);
u8g2.drawStr(30,54, l1);
} while ( u8g2.nextPage() );
if (val > NBCODES)
play_r3tl(_rCountOK_);
else
play_r3tl(_rCountKO_);
noTone(PIEZO);
}
// display incoming IR frame code
void showCode(unsigned long val) {
char buf[16];
play_r3tl(_rGetIR_);
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_profont17_tr);
u8g2.drawStr(16,24, "Code recu :");
sprintf(buf, "%08X", val ) ;
u8g2.setFont(u8g2_font_profont22_tr);
u8g2.drawStr(16,54,buf);
} while ( u8g2.nextPage() );
}
void setup(void) {
noTone(PIEZO);
u8g2.begin();
drawLogo();
#ifdef DEBUG
Serial.begin(9600);
#endif
play_r3tl(_rIntro_);
irrecv.enableIRIn(); // Start the receiver
delay(1000);
}
// ==================== Main ====================
// Global parameters
int cl=0; unsigned long lastReading=0, currentt=0;
void loop(void) {
noTone(PIEZO);
if (irrecv.decode(&results)) { // if we keep getting signals, it is running
lastReading=millis();
cl += 1;
showCode(results.value); //showCount(cl);
irrecv.resume();
}
else // got no more reading
{ // if we keep getting nothing, then it is over
currentt = millis();
if ((lastReading + ACQUINONE < currentt) && ( cl > 0)) { // lastReading too old
showTrace();
showResult(cl); cl = 0;
constratSlope(255, 0, -1, 50);
delay(3000);
drawLogo();
constratSlope(0, 255, 1, 20);
}
}
} // loop
// debugging
void showTrace() {
#ifdef DEBUG
Serial.print("OK cl : ");
Serial.print(cl);
Serial.print(" currentt : ");
Serial.print(currentt);
Serial.print(" lastReading : ");
Serial.println(lastReading);
#endif
}
// show IR frames count, by showResult
void showCount(int val) {
char buf[16];
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_fub14_tr);
u8g2.drawStr(12,28,"Codes lus :");
sprintf(buf, "%3d", val ) ;
u8g2.setFont(u8g2_font_fub20_tr);
u8g2.drawStr(40,60,buf);
} while ( u8g2.nextPage() );
}

103
offok/offok_logo.h Normal file
View File

@ -0,0 +1,103 @@
/*--------------------------------------------------------------*/
/* Projet: OFFOK */
/* File : offok.logo.h */
/* Author: JeARZ 02/14/21 */
/*--------------------------------------------------------------*/
/*
XBM array 128x64 pixels of logo Tetal@b for OLED display SH1106
04/22/21: new logo
*/
#ifndef __OFFOK_LOGO_h__
#define __OFFOK_LOGO_h__
#define logo_width 128
#define logo_height 64
static const unsigned char logo_bits[] U8X8_PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0xb4,
0x16, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xc0, 0x0f, 0x77, 0x77, 0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xde, 0xf7, 0xf7, 0xbd, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xbd, 0xf3,
0xe7, 0x5e, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xc0, 0xbe, 0xf0, 0x87, 0xbe, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0xf6, 0x37, 0xfe, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x7f, 0xc7,
0x71, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1f, 0x1f, 0x7c, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xde, 0xbf, 0xfe, 0xbd, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xc0, 0xdf,
0xfd, 0x81, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x70, 0x9a, 0xdf, 0xfd, 0x2c, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x33, 0xdf, 0x7d, 0x66, 0x06, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x77, 0xdf,
0x7d, 0xf7, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0xf9, 0xff, 0xf9, 0xff, 0xf9, 0xfe, 0x3e, 0x7f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xf9, 0xff, 0xf9, 0xff,
0x79, 0xff, 0x3d, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0xc1, 0x80, 0xc1, 0x80, 0xb9, 0x43, 0x3b, 0x7f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0xc1, 0x80, 0xc1, 0x80, 0xd9, 0x01, 0x36, 0x60,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xbf, 0xf9, 0x9c, 0xf9, 0x9f,
0xd9, 0x38, 0x36, 0x60, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x01, 0x00, 0x80,
0xf9, 0x9c, 0xf9, 0x9f, 0xd9, 0x7c, 0xf6, 0x67, 0x00, 0x00, 0x20, 0x00,
0x00, 0xe2, 0xff, 0xbf, 0xf9, 0x9c, 0xf9, 0x90, 0xd9, 0x3c, 0x37, 0x64,
0xff, 0xff, 0x11, 0x00, 0x00, 0xc4, 0xff, 0xbf, 0xf9, 0x84, 0xf9, 0x90,
0xd9, 0x3c, 0x37, 0x67, 0xff, 0xff, 0x08, 0x00, 0x00, 0x88, 0xff, 0xbf,
0xf9, 0x84, 0xf9, 0x9c, 0xd9, 0x18, 0x36, 0x67, 0xff, 0x7f, 0x04, 0x00,
0x00, 0x10, 0xff, 0xbf, 0xf9, 0xfc, 0xf9, 0x9c, 0xd9, 0x01, 0x30, 0x67,
0xff, 0x3f, 0x02, 0x00, 0x00, 0x20, 0xfe, 0xbf, 0xf9, 0xfc, 0xf9, 0x9c,
0xb9, 0x83, 0x39, 0x67, 0xff, 0x1f, 0x01, 0x00, 0x00, 0x40, 0xfc, 0xbf,
0xf9, 0x80, 0xf9, 0x80, 0x79, 0xff, 0x3f, 0x60, 0xff, 0x8f, 0x00, 0x00,
0x00, 0x80, 0xf8, 0xbf, 0xf9, 0x80, 0xf9, 0x80, 0xf9, 0xfe, 0x3e, 0x60,
0xff, 0x47, 0x00, 0x00, 0x00, 0x00, 0xf1, 0xbf, 0xff, 0xff, 0xff, 0xff,
0xff, 0x01, 0xff, 0x7f, 0xff, 0x23, 0x00, 0x00, 0x00, 0x00, 0xe2, 0xbf,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xff, 0x11, 0x00, 0x00,
0x00, 0x00, 0xe2, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0x11, 0x00, 0x00, 0x00, 0x00, 0xf1, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x23, 0x00, 0x00, 0x00, 0x80, 0xf8, 0x7f,
0x00, 0xf0, 0x3f, 0x00, 0x00, 0xfe, 0x07, 0x00, 0xff, 0x47, 0x00, 0x00,
0x00, 0x40, 0xfc, 0xff, 0x00, 0xe0, 0x3f, 0xd5, 0x77, 0xfe, 0x03, 0x80,
0xff, 0x8f, 0x00, 0x00, 0x00, 0x20, 0xfe, 0xff, 0x03, 0xe4, 0x3f, 0x15,
0x45, 0xfe, 0x13, 0xe0, 0xff, 0x1f, 0x01, 0x00, 0x00, 0x10, 0xff, 0xff,
0x0f, 0xc4, 0x3f, 0x54, 0x55, 0xfe, 0x11, 0xf8, 0xff, 0x3f, 0x02, 0x00,
0x00, 0x88, 0xff, 0xff, 0x3f, 0xcc, 0x3f, 0x5f, 0x75, 0xfe, 0x19, 0xfe,
0xff, 0x7f, 0x04, 0x00, 0x00, 0xc4, 0xff, 0xff, 0x7f, 0x8c, 0x7f, 0x00,
0x10, 0xff, 0x18, 0xff, 0xff, 0xff, 0x08, 0x00, 0x00, 0xe2, 0xff, 0xff,
0xff, 0x1d, 0xdf, 0x01, 0xc0, 0x7d, 0xdc, 0xff, 0xff, 0xff, 0x11, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x18, 0x86, 0x07, 0xf0, 0x30, 0x0c, 0x00,
0x00, 0x00, 0x20, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x33, 0xcc, 0xff,
0xff, 0x19, 0xe6, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x70, 0xd8, 0xf7, 0xf7, 0x0d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xf0, 0xe3, 0xe3, 0x87, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xe1, 0xc1,
0xc1, 0xc3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x0f, 0xff,
0xfc, 0x83, 0x83, 0xeb, 0xeb, 0xe0, 0x00, 0xc0, 0x0f, 0xc3, 0x00, 0x00,
0x00, 0xe0, 0x1f, 0xff, 0xfc, 0x03, 0x07, 0xfe, 0x3f, 0x70, 0x00, 0xe0,
0x1f, 0xe3, 0x00, 0x00, 0x00, 0x70, 0x38, 0x07, 0x1c, 0x00, 0x1e, 0xe0,
0x03, 0x3c, 0x00, 0x70, 0x38, 0x73, 0x00, 0x00, 0x00, 0x30, 0x30, 0x07,
0x1c, 0x00, 0x7c, 0x00, 0x00, 0x1f, 0x00, 0x30, 0x30, 0x3b, 0x00, 0x00,
0x00, 0x30, 0x30, 0x07, 0x1c, 0x00, 0xf0, 0x03, 0xe0, 0x07, 0x00, 0x30,
0x30, 0x1f, 0x00, 0x00, 0x00, 0x30, 0x30, 0x7f, 0xfc, 0x01, 0xe0, 0xff,
0xff, 0x03, 0x00, 0x30, 0x30, 0x1f, 0x00, 0x00, 0x00, 0x30, 0x30, 0x7f,
0xfc, 0x01, 0x20, 0xff, 0x7f, 0x02, 0x00, 0x30, 0x30, 0x3f, 0x00, 0x00,
0x00, 0x30, 0x30, 0x07, 0x1c, 0x00, 0x20, 0xf8, 0x0f, 0x02, 0x00, 0x30,
0x30, 0x37, 0x00, 0x00, 0x00, 0x30, 0x30, 0x07, 0x1c, 0x00, 0x20, 0x00,
0x00, 0x02, 0x00, 0x30, 0x30, 0x73, 0x00, 0x00, 0x00, 0x70, 0x38, 0x07,
0x1c, 0x00, 0x20, 0x00, 0x00, 0x02, 0x00, 0x70, 0x38, 0x63, 0x00, 0x00,
0x00, 0xe0, 0x1f, 0x07, 0x1c, 0x00, 0x60, 0x00, 0x00, 0x03, 0x00, 0xe0,
0x1f, 0xe3, 0x00, 0x00, 0x00, 0xc0, 0x0f, 0x07, 0x1c, 0x00, 0xc0, 0x58,
0x8d, 0x01, 0x00, 0xc0, 0x0f, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x5f, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x0d, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
#endif // __OFFOK_LOGO_h__

43
offok/offok_tunes.h Normal file
View File

@ -0,0 +1,43 @@
/*--------------------------------------------------------------*/
/* Projet: OFFOK */
/* File : offok.tune.h */
/* Author: JeARZ 05/19/21 */
/*--------------------------------------------------------------*/
/*
RTTTL tunes
*/
#ifndef __OFFOK_TUNES_h__
#define __OFFOK_TUNES_h__
/*
Used libs for playing rtttl ringtones
*/
#include <anyrtttl.h>
#include <binrtttl.h>
#include <pitches.h>
/*
OffOk predefined variables holding rtttl tunes
*/
const char *_rIntro_ =
"StarTrekIntro1:d=4,o=5,b=63:8f.,16a#,d#.6,8d6,16a#.,16g.,16c.6,f6";
const char *_rIntro1_ =
"StarTrekIntro2:d=4,o=6,b=225:2b.4,4e.5,1a5,4g#.5,4e.5,4c#.5,4f#.5,2b.5,4b.5,2d#.6";
const char *_rGetIR_ =
"StarTrekCom:d=32,o=7,b=480:d#,e";
const char *_rGetIRl_ =
"StarTrekCom:d=32,o=7,b=180:d#,e,g,d#,g,d#,f#,e,f";
const char *_rCountKO_ =
"Death March:d=4,o=5,b=125:c.,c,8c,c.,d#,8d,d,8c,c,8c,2c.";
const char *_rCountOKs_ =
"LightMyFire:d=4,o=5,b=140:8b,16g,16a,8b,8d6,8c6,8b,8a,8g,8a,16f,16a,8c6,8f6,16d6,16c6,16a#,16g,8g#,8g,8g#";
const char *_rCountOK_ =
"LightMyFire:d=4,o=5,b=140:8b,16g,16a,8b,8d6,8c6,8b,8a,8g,8a,16f,16a,8c6,8f6,16d6,16c6,16a#,16g,8g#,8g,8g#,16g,16a,8b,8c#6,16b,16a,16g,16f,8e,8f,1a,a";
const char *_rCountOK1_ =
"tetris:d=4,o=5,b=160:e6,8b,8c6,8d6,16e6,16d6,8c6,8b,a,8a,8c6,e6,8d6,8c6,b,8b,8c6,d6,e6,c6,a,2a,8p,d6,8f6,a6,8g6,8f6,e6,8e6,8c6,e6,8d6,8c6,b,8b,8c6,d6,e6,c6,a,a";
const char *_rCountOK2_ =
"Pacman:d=32,o=6,b=112:b.5,b.,f#.,d#.,b.,f#.,16p,16d#,c.,c.7,g.,e.,c.7,g.,16p,16e,b.5,b.,f#.,d#.,b.,f#.";
// just for fun ;-)
const char * arkanoid =
"Arkanoid:d=4,o=5,b=140:8g6,16p,16g.6,2a#6,32p,8a6,8g6,8f6,8a6,2g6";
#endif // __OFFOK_TUNES_h__