// Reminder...
// For M5Stamp C3 -> Arduino IDE -> Tools -> USB CDC On Boot: --> "Disable"
// For M5Stamp C3U -> Arduino IDE -> Tools -> USB CDC On Boot: --> "Enable"
//
// For ESP32C3 SuperMini & M5Stamp C3U (using "ESP32C3 Dev Module" board)
// -> USB off + Left Button pressed -> USB on + Left button pressed -> Release Left button
// -> After Upload the code, press Right button (reset)
// NeoPixel inicializations >>>
#include <Adafruit_NeoPixel.h>
// define Neopixel LEDs
//#define PinRGBled 2 // Internal Pin LED SK6812 for M5Stamp C3
#define PinRGBstrip1 2 //3 // WS2812B Strip 1
#define PinRGBstrip2 3 // // WS2812B Strip 2
#define PinRGBstrip3 0 //5 // WS2812B Strip 3
#define PinRGBstrip4 1 //6 // WS2812B Strip 4
#define NUMPIXELSstrip1 12
#define NUMPIXELSstrip2 16 // 12
#define NUMPIXELSstrip3 16 // 12
#define NUMPIXELSstrip4 16 // 12
Adafruit_NeoPixel pixelsStrip1 = Adafruit_NeoPixel(NUMPIXELSstrip1, PinRGBstrip1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixelsStrip2 = Adafruit_NeoPixel(NUMPIXELSstrip2, PinRGBstrip2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixelsStrip3 = Adafruit_NeoPixel(NUMPIXELSstrip3, PinRGBstrip3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixelsStrip4 = Adafruit_NeoPixel(NUMPIXELSstrip4, PinRGBstrip4, NEO_GRB + NEO_KHZ800);
// OLED display SSD1306 I2C inicialization >>>
#include <Wire.h>
#include <U8g2lib.h>
#define I2C_SDA 4 //21 //I2C_SDA -> Pin 4 for ESP32C3 -> Pin 21 for ESP32
#define I2C_SCL 5 //22 //I2C_SCL -> Pin 5 for ESP32C3 -> Pin 22 for ESP32
// OLED display 0.96 128x64 SSD1306 BiColor 0..14 Yellow 15..63 Blue
// --> u8g2.setFont(u8g2_font_scrum_tr); //https://github.com/olikraus/u8g2/wiki/fntlist8 fuente muy equilibrada, la _tf tambien
// --> u8g2.setFont(u8g2_font_bpixeldouble_tr); fuente un poco más BOLD (negrita)
//U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ SCL, /* data=*/ SDA); // 0.91 Display
//U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); //M0/ESP32/ESP8266/mega2560/Uno/Leonardo
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // 0.91 Display
//U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0); // 1.3 Display
#define u8g_logo_width 128
#define u8g_logo_height 64
// Bender logo
static unsigned char u8g_logo_bits[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x3f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xc7, 0x0f, 0xf8, 0x73, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xf1, 0x1f, 0xfc, 0xc7, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xf1, 0x3f, 0xfe, 0xc7, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xf8, 0x3f, 0xfe, 0x8f, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x9f, 0x78, 0x7c, 0x1f, 0x8f, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x9f, 0x78, 0x7c, 0x1f, 0x8f, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x9f, 0x78, 0x7c, 0x1e, 0x8f, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xf8, 0x3f, 0xfe, 0x8f, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xf1, 0x3f, 0xfe, 0xc7, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xbf, 0xe1, 0x1f, 0xfc, 0xc7, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xe7, 0x0f, 0xf8, 0x73, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x73, 0xce, 0x39, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x73, 0xce, 0x39, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x73, 0xce, 0x39, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x63, 0xce, 0x39, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0xce, 0x39, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0xcc, 0x19, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
byte ScreenLineNum = 0; // 3 Lines 0 (default values), 1 (User values), 2 (Bars)
byte ScreenColum = 0; // 4 Columns 0 (Brightness),1 (Red),2 (Green),3 (Blue)
struct ScreenLineValues
{
const byte BrightnessVal;
const byte RedVal;
const byte GreenVal;
const byte BlueVal;
};
ScreenLineValues ScreenLine1 = {50, 0, 0, 0};
ScreenLineValues ScreenLine2 = {50, 0, 0, 0};
ScreenLineValues ScreenLine3 = {50, 0, 0, 0};
// >> External Interruptions inicializations
// define a structure for interruption buttons
struct ButtonISR
{
const uint8_t PIN;
byte bttnNumberPressed; // Not used
bool pressed;
};
// define the iterruption buttons values
ButtonISR bttnUP = {21, 0, false}; // Pin 0
ButtonISR bttnDW = {7, 0, false}; // Pin 21
ButtonISR bttnOK = {20, 0, false}; // Pin 1
ButtonISR bttnLF = {19, 0, false}; // Pin 20
ButtonISR bttnRI = {18, 0, false}; // Pin 2
byte bttnNumberPressed; // 0=No bttn pressed, 1=UP, 2=DW, 3=LF, 4=RI, 5=OK
volatile unsigned long oldtime_ISRbttn = 0;
bool flaganybttnpressed = false;
#define timePressingButton 5 // Wait 5ms pressing button
// @@@--- INTERRUPTIONS ---@@@ //
void IRAM_ATTR ISR_UPbttn()
{
f_detachInterrupt_ISRbttns();
flaganybttnpressed = true;
oldtime_ISRbttn = millis();
bttnNumberPressed = 1;
}
void IRAM_ATTR ISR_DWbttn()
{
f_detachInterrupt_ISRbttns();
flaganybttnpressed = true;
oldtime_ISRbttn = millis();
bttnNumberPressed = 2;
}
void IRAM_ATTR ISR_OKbttn()
{
f_detachInterrupt_ISRbttns();
flaganybttnpressed = true;
oldtime_ISRbttn = millis();
bttnNumberPressed = 5;
}
void IRAM_ATTR ISR_LFbttn()
{
f_detachInterrupt_ISRbttns();
flaganybttnpressed = true;
oldtime_ISRbttn = millis();
bttnNumberPressed = 3;
}
void IRAM_ATTR ISR_RIbttn()
{
f_detachInterrupt_ISRbttns();
flaganybttnpressed = true;
oldtime_ISRbttn = millis();
bttnNumberPressed = 4;
}
// @@@--- SETUP ---@@@ //
void setup()
{
Serial.begin(115200);
setupSSD1306();
setup_Neopixel();
setup_ISRbttns();
}
void setupSSD1306()
{
Wire.setPins(I2C_SDA, I2C_SCL);
Wire.begin();
u8g2.begin();
draw_welcome_display();
}
void draw_welcome_display()
{
u8g2.firstPage();
do {
u8g2.drawXBM( 0, 0, u8g_logo_width, u8g_logo_height, u8g_logo_bits);
} while ( u8g2.nextPage() );
delay(4000);
u8g2.firstPage();
do {
//keep this the same as it pages through the data generating the screen
//u8g2.setFont(u8g2_font_t0_18_tr);
//u8g2.setFont(u8g2_font_balthasar_titling_nbp_tr);
u8g2.setFont(u8g2_font_scrum_tr);
u8g2.drawStr(0,14,"ADN electronics");
//u8g2.setFont(u8g2_font_profont22_tr); //https://github.com/olikraus/u8g2/wiki/fntlist8
u8g2.setFont(u8g2_font_profont15_tr); //https://github.com/olikraus/u8g2/wiki/fntlist8
u8g2.drawStr(4,40,"ESP32C3");
u8g2.drawStr(6,60,"U8g2-SSD1306");
//u8g2.setFont(u8g2_font_profont15_tr); //https://github.com/olikraus/u8g2/wiki/fntlist8
//u8g2.drawStr(6,60,"NPDC development");
} while ( u8g2.nextPage() );
delay(4000);
u8g2.clear();
}
void setup_Neopixel()
{
pixelsStrip1.begin(); // Inicializamos la librería Neopixel
pixelsStrip2.begin(); // Inicializamos la librería Neopixel
pixelsStrip3.begin(); // Inicializamos la librería Neopixel
pixelsStrip4.begin(); // Inicializamos la librería Neopixel
pixelsStrip1.setBrightness(200); // Fijamos un nivel de brillo (0 .. 255) moderado al inicio.
pixelsStrip2.setBrightness(200); // Fijamos un nivel de brillo (0 .. 255) moderado al inicio.
pixelsStrip3.setBrightness(200); // Fijamos un nivel de brillo (0 .. 255) moderado al inicio.
pixelsStrip4.setBrightness(200); // Fijamos un nivel de brillo (0 .. 255) moderado al inicio.
s_Neopixel_start_sequence1();
s_Neopixel_start_sequence2();
}
void s_Neopixel_start_sequence1()
{
for (int i=0; i<4; i++)
{
if (i<1)
{
pixelsStrip1.setPixelColor(i, pixelsStrip1.Color(0,0,255)); // Ponemos el LED en color AZUL para comprobar que funciona correctamente
}
if (i<2)
{
pixelsStrip2.setPixelColor(i, pixelsStrip2.Color(255,0,0)); // Ponemos el LED en color ROJO para comprobar que funciona correctamente
}
if (i<3)
{
pixelsStrip3.setPixelColor(i, pixelsStrip3.Color(0,255,0)); // Ponemos el LED en color VERDE para comprobar que funciona correctamente
}
if (i<4)
{
pixelsStrip4.setPixelColor(i, pixelsStrip4.Color(255,255,255)); // Ponemos el LED en color BLANCO para comprobar que funciona correctamente
}
pixelsStrip1.show();
pixelsStrip2.show();
pixelsStrip3.show();
pixelsStrip4.show();
delay(250);
}
delay (3000);
//for (int i=3; i>=0; i--)
for (int i=0; i<4; i++)
{
if (i<1)
{
pixelsStrip1.setPixelColor(i, pixelsStrip1.Color(0,0,0)); // Ponemos el LED en color APAGADO
}
if (i<2)
{
pixelsStrip2.setPixelColor(i, pixelsStrip2.Color(0,0,0)); // Ponemos el LED en color APAGADO
}
if (i<3)
{
pixelsStrip3.setPixelColor(i, pixelsStrip3.Color(0,0,0)); // Ponemos el LED en color APAGADO
}
if (i<4)
{
pixelsStrip4.setPixelColor(i, pixelsStrip4.Color(0,0,0)); // Ponemos el LED en color APAGADO
}
pixelsStrip1.show();
pixelsStrip2.show();
pixelsStrip3.show();
pixelsStrip4.show();
delay(250);
}
delay (3000);
}
void s_Neopixel_start_sequence2()
{
for (int i=0; i<16; i++)
{
if (i<12)
{
pixelsStrip1.setPixelColor(i, pixelsStrip1.Color(0,0,255));
}
pixelsStrip2.setPixelColor(i, pixelsStrip2.Color(0,0,255));
pixelsStrip3.setPixelColor(i, pixelsStrip3.Color(0,0,255));
pixelsStrip4.setPixelColor(i, pixelsStrip4.Color(0,0,255));
pixelsStrip1.show();
pixelsStrip2.show();
pixelsStrip3.show();
pixelsStrip4.show();
delay(100);
}
delay(3000);
//for (int i=15; i>=0; i--)
for (int i=0; i<16; i++)
{
if (i<12)
{
pixelsStrip1.setPixelColor(i, pixelsStrip1.Color(0,0,0));
}
pixelsStrip2.setPixelColor(i, pixelsStrip2.Color(0,0,0));
pixelsStrip3.setPixelColor(i, pixelsStrip3.Color(0,0,0));
pixelsStrip4.setPixelColor(i, pixelsStrip4.Color(0,0,0));
pixelsStrip1.show();
pixelsStrip2.show();
pixelsStrip3.show();
pixelsStrip4.show();
delay(100);
}
delay (3000);
}
void setup_ISRbttns()
{
//pinMode(LED, OUTPUT);
pinMode(bttnUP.PIN, INPUT_PULLUP); // PULLUP --> Switch Pin to GND // PULLDOWN --> Switch Pin to 5V or 3V3
pinMode(bttnDW.PIN, INPUT_PULLUP); // PULLUP --> Switch Pin to GND // PULLDOWN --> Switch Pin to 5V or 3V3
pinMode(bttnOK.PIN, INPUT_PULLUP); // PULLUP --> Switch Pin to GND // PULLDOWN --> Switch Pin to 5V or 3V3
pinMode(bttnLF.PIN, INPUT_PULLUP); // PULLUP --> Switch Pin to GND // PULLDOWN --> Switch Pin to 5V or 3V3
pinMode(bttnRI.PIN, INPUT_PULLUP); // PULLUP --> Switch Pin to GND // PULLDOWN --> Switch Pin to 5V or 3V3
f_attachInterrupt_ISRbttns();
}
void f_attachInterrupt_ISRbttns() // atach all ISRs
{
attachInterrupt(digitalPinToInterrupt(bttnUP.PIN), ISR_UPbttn, HIGH); //LOW, HIGH, CHANGE, FALLING, RISING
attachInterrupt(digitalPinToInterrupt(bttnDW.PIN), ISR_DWbttn, HIGH); //LOW, HIGH, CHANGE, FALLING, RISING
attachInterrupt(digitalPinToInterrupt(bttnOK.PIN), ISR_OKbttn, HIGH); //LOW, HIGH, CHANGE, FALLING, RISING
attachInterrupt(digitalPinToInterrupt(bttnLF.PIN), ISR_LFbttn, HIGH); //LOW, HIGH, CHANGE, FALLING, RISING
attachInterrupt(digitalPinToInterrupt(bttnRI.PIN), ISR_RIbttn, HIGH); //LOW, HIGH, CHANGE, FALLING, RISING
}
void f_detachInterrupt_ISRbttns() // detach all ISRs
{
detachInterrupt(digitalPinToInterrupt(bttnUP.PIN));
detachInterrupt(digitalPinToInterrupt(bttnDW.PIN));
detachInterrupt(digitalPinToInterrupt(bttnOK.PIN));
detachInterrupt(digitalPinToInterrupt(bttnLF.PIN));
detachInterrupt(digitalPinToInterrupt(bttnRI.PIN));
}
// @@@--- MAIN PROGRAM ---@@@ //
void loop()
{
if(flaganybttnpressed == true)
{
f_evaluateISRbttn();
f_updatebttnstatus();
}
//f_pixelStrips();
}
void f_evaluateISRbttn()
{
if(millis()-oldtime_ISRbttn > timePressingButton)
{
if(digitalRead(bttnUP.PIN)==LOW)
{
bttnUP.pressed = true;
bttnNumberPressed = 1;
flaganybttnpressed = false;
}
if(digitalRead(bttnDW.PIN)==LOW)
{
bttnDW.pressed = true;
bttnNumberPressed = 2;
flaganybttnpressed = false;
}
if(digitalRead(bttnOK.PIN)==LOW)
{
bttnOK.pressed = true;
bttnNumberPressed = 5;
flaganybttnpressed = false;
}
if(digitalRead(bttnLF.PIN)==LOW)
{
bttnLF.pressed = true;
bttnNumberPressed = 3;
flaganybttnpressed = false;
}
if(digitalRead(bttnRI.PIN)==LOW)
{
bttnRI.pressed = true;
bttnNumberPressed = 4;
flaganybttnpressed = false;
}
// Restrablecemos los flags de los pulsadores en la función "void f_updatebttnstatus()"
//bttnUP.pressed = false;
//bttnDW.pressed = false;
//bttnOK.pressed = false;
//bttnLF.pressed = false;
//bttnRI.pressed = false;
// Restrablecemos las interrupciones en la función "void f_updatebttnstatus()"
//f_attachInterrupt_ISRbttns();
}
}
void f_updatebttnstatus()
{
if (bttnUP.pressed || bttnDW.pressed || bttnOK.pressed || bttnLF.pressed || bttnRI.pressed)
{
/*
Serial.printf("UP button pressed: %d", bttnUP.pressed); Serial.println();
Serial.printf("DOWN button pressed: %d", bttnDW.pressed); Serial.println();
Serial.printf("OK button pressed: %d", bttnOK.pressed); Serial.println();
Serial.printf("LEFT button pressed: %d", bttnLF.pressed); Serial.println();
Serial.printf("RIGHT button pressed: %d", bttnRI.pressed); Serial.println();
Serial.println();
*/
//ff_setLEDcolor();
ff_ScreenRefresh();
// restablecemos los flags de las interrupciones
bttnUP.pressed = false;
bttnDW.pressed = false;
bttnOK.pressed = false;
bttnLF.pressed = false;
bttnRI.pressed = false;
f_attachInterrupt_ISRbttns();
}
}
/*
void ff_setLEDcolor()
{
if (bttnUP.pressed)
{
pixelsStrip1.setPixelColor(0, pixelsStrip1.Color(255,0,0));
}
if (bttnDW.pressed)
{
pixelsStrip2.setPixelColor(0, pixelsStrip2.Color(0,0,255));
}
if (bttnOK.pressed)
{
pixelsStrip1.setPixelColor(0, pixelsStrip1.Color(0,0,0));
pixelsStrip2.setPixelColor(0, pixelsStrip2.Color(0,0,0));
pixelsStrip3.setPixelColor(0, pixelsStrip3.Color(0,0,0));
pixelsStrip4.setPixelColor(0, pixelsStrip4.Color(0,0,0));
}
if (bttnLF.pressed)
{
pixelsStrip3.setPixelColor(0, pixelsStrip3.Color(255,0,255));
}
if (bttnRI.pressed)
{
pixelsStrip4.setPixelColor(0, pixelsStrip4.Color(0,255,0));
}
pixelsStrip1.show();
pixelsStrip2.show();
pixelsStrip3.show();
pixelsStrip4.show();
}
*/
void ff_ScreenRefresh()
{
fff_ScreenNavi();
fff_ScreenLayout();
fff_ScreenValues();
}
void fff_ScreenNavi()
{
switch (bttnNumberPressed)
{
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
}
}
void fff_ScreenLayout()
{
u8g2.firstPage();
do {
//u8g2.setFont(u8g2_font_scrum_tr);
//u8g2.setFont(u8g2_font_6x10_tf);
u8g2.setFont(u8g2_font_t0_18_tr);
u8g2.userInterfaceSelectionList("LIGHTING MENU", 3, "Brightness\nColor\nAbout\n");
//u8g2.setFont(u8g2_font_6x10_tf);
//u8g2.setFontRefHeightAll(); /* this will add some extra space for the text inside the buttons */
//u8g2.userInterfaceMessage("Title1", "Title2", "Title3", " Ok \n Cancel ");
} while ( u8g2.nextPage() );
//u8g2.clear();
}
void fff_ScreenValues()
{
}
void f_pixelStrips()
{
for (int i=0; i<12; i++)
{
pixelsStrip1.setPixelColor(i, pixelsStrip1.Color(0,0,255));
pixelsStrip1.show();
}
for (int i=0; i<12; i++)
{
pixelsStrip2.setPixelColor(i, pixelsStrip2.Color(0,0,255));
pixelsStrip2.show();
}
for (int i=0; i<12; i++)
{
pixelsStrip3.setPixelColor(i, pixelsStrip3.Color(0,0,255));
pixelsStrip3.show();
}
for (int i=0; i<12; i++)
{
pixelsStrip4.setPixelColor(i, pixelsStrip4.Color(0,0,255));
pixelsStrip4.show();
}
}