#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSerifBold9pt7b.h>
#include <Fonts/FreeSerif9pt7b.h>
#include <USBHIDKeyboard.h>
// Declare the keyboard object globally
USBHIDKeyboard keyboard;
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define unPressed HIGH
#define pressed LOW
#define LED 35
boolean activationMode;
boolean last_activationMode;
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO: A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO: 2(SDA), 3(SCL), ...
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
// in diagram.json, can edit oled2 address to 0x3d
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
static const unsigned char PROGMEM global_icon[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1c,0x00,0x00,0x00,0x00,0x1f,0x00,0x00,0x00,0xc0,0x1f,0x80,0x00,0x01,0xc0,0x07,0xc0,0x00,0x03,0xe0,0x03,0xe0,0x00,0x07,0xe0,0x00,0xf0,0x00,0x0f,0xe0,0xf0,0x78,0x00,0x1f,0xe0,0xf8,0x38,0x00,0x3f,0xe0,0x7e,0x3c,0x00,0x7f,0xe0,0x1e,0x1c,0x00,0xff,0xe0,0x0f,0x1e,0xff,0xff,0xe3,0x07,0x8e,0xff,0xff,0xe3,0xc3,0x8f,0xff,0xff,0xe3,0xe3,0x8f,0xff,0xff,0xe1,0xe3,0xc7,0xff,0xff,0xe0,0xf1,0xc7,0xff,0xff,0xe0,0x71,0xc7,0xff,0xff,0xe0,0x71,0xc7,0xff,0xff,0xe0,0xf1,0xc7,0xff,0xff,0xe1,0xe3,0xc7,0xff,0xff,0xe3,0xe3,0x8f,0xff,0xff,0xe3,0xc3,0x8f,0xff,0xff,0xe3,0x07,0x8e,0x00,0xff,0xe0,0x0f,0x1e,0x00,0x7f,0xe0,0x1e,0x1c,0x00,0x3f,0xe0,0x7e,0x3c,0x00,0x1f,0xe0,0xf8,0x38,0x00,0x0f,0xe0,0xf0,0x78,0x00,0x07,0xe0,0x00,0xf0,0x00,0x03,0xe0,0x03,0xe0,0x00,0x01,0xc0,0x07,0xc0,0x00,0x00,0xc0,0x1f,0x80,0x00,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x1c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
static const unsigned char PROGMEM chrome_icon[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x00,0x00,0x03,0xff,0xc0,0x00,0x00,0x0f,0xff,0xf0,0x00,0x00,0x1f,0xff,0xf8,0x00,0x00,0x3f,0xff,0xfc,0x00,0x00,0x7f,0xff,0xfe,0x00,0x00,0x3f,0xff,0xff,0x00,0x00,0x9f,0xe0,0x00,0x00,0x01,0x9f,0x00,0x00,0x00,0x01,0xce,0x00,0x7f,0x80,0x01,0xec,0x7e,0x3f,0x80,0x03,0xe4,0xff,0x3f,0xc0,0x03,0xf4,0xff,0x3f,0xc0,0x03,0xf0,0xff,0x1f,0xc0,0x03,0xf8,0xff,0x1f,0xc0,0x03,0xf8,0xff,0x3f,0xc0,0x03,0xfc,0xff,0x3f,0xc0,0x01,0xfc,0x7e,0x3f,0x80,0x01,0xfe,0x00,0x7f,0x80,0x01,0xff,0x00,0xff,0x80,0x00,0xff,0xe4,0xff,0x00,0x00,0xff,0xf9,0xff,0x00,0x00,0x7f,0xf9,0xfe,0x00,0x00,0x3f,0xf3,0xfc,0x00,0x00,0x1f,0xf7,0xf8,0x00,0x00,0x0f,0xe7,0xf0,0x00,0x00,0x03,0xef,0xc0,0x00,0x00,0x00,0x4e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
static const unsigned char PROGMEM discord_icon[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1e,0x00,0x78,0x00,0x00,0xfe,0x00,0x7f,0x00,0x03,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x07,0xff,0xff,0xff,0xe0,0x0f,0xff,0xff,0xff,0xf0,0x0f,0xff,0xff,0xff,0xf0,0x1f,0xff,0xff,0xff,0xf8,0x1f,0xff,0xff,0xff,0xf8,0x3f,0xff,0xff,0xff,0xfc,0x3f,0xff,0xff,0xff,0xfc,0x7f,0xff,0xff,0xff,0xfe,0x7f,0xff,0xff,0xff,0xfe,0x7f,0xe0,0xff,0x07,0xfe,0x7f,0xc0,0xff,0x03,0xfe,0x7f,0xc0,0x7e,0x03,0xff,0xff,0xc0,0x7e,0x03,0xff,0xff,0xc0,0x7e,0x03,0xff,0xff,0xc0,0xff,0x03,0xff,0xff,0xe0,0xff,0x07,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,0xcf,0xff,0xf3,0xfe,0x3f,0xf0,0x7e,0x0f,0xfc,0x0f,0xf0,0x00,0x0f,0xf0,0x03,0xf0,0x00,0x0f,0xc0,0x00,0xe0,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
static const unsigned char PROGMEM game_icon[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xf8,0x00,0x1f,0xc0,0x07,0xfe,0x00,0x7f,0xe0,0x0f,0xff,0x00,0xff,0xf0,0x1f,0x9f,0xff,0xf9,0xf8,0x1f,0x1f,0xff,0xf8,0xf8,0x1f,0x1f,0xff,0xff,0xf8,0x3c,0x07,0xff,0xe7,0x3c,0x3c,0x07,0xff,0xe7,0x3c,0x3f,0x1f,0xff,0xf9,0xfc,0x3f,0x1f,0xff,0xf8,0xfc,0x3f,0xff,0xff,0xff,0xfc,0x7f,0xfb,0xff,0x9f,0xfe,0x7f,0xe0,0xff,0x07,0xfe,0x7f,0xe0,0xfe,0x07,0xfe,0x7f,0xe0,0x7e,0x07,0xfe,0x7f,0xe0,0xff,0x07,0xfe,0x7f,0xf0,0xff,0x0f,0xfe,0x7f,0xff,0xff,0xff,0xfe,0x7f,0xff,0x81,0xff,0xfe,0x7f,0xfe,0x00,0x7f,0xfe,0x7f,0xf8,0x00,0x1f,0xfe,0x7f,0xf8,0x00,0x1f,0xfe,0x7f,0xf0,0x00,0x0f,0xfe,0x3f,0xe0,0x00,0x07,0xfc,0x1f,0xe0,0x00,0x07,0xf8,0x0f,0x80,0x00,0x01,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
static const unsigned char PROGMEM cross_out[] = {0x0f,0x80,0x00,0x01,0xf0,0x3f,0xe0,0x00,0x07,0xfc,0x7f,0xf0,0x00,0x0f,0xfe,0x78,0xf8,0x00,0x1f,0x1e,0xf0,0x7c,0x00,0x3e,0x0f,0xe0,0x3e,0x00,0x7c,0x07,0xe0,0x1f,0x00,0xf8,0x07,0xe0,0x0f,0x81,0xf0,0x07,0xf0,0x07,0xc3,0xe0,0x0f,0x78,0x03,0xe7,0xc0,0x1e,0x7c,0x01,0xff,0x80,0x3e,0x3e,0x00,0xff,0x00,0x7c,0x1f,0x00,0x7e,0x00,0xf8,0x0f,0x80,0x3c,0x01,0xf0,0x07,0xc0,0x18,0x03,0xe0,0x03,0xe0,0x00,0x07,0xc0,0x01,0xf0,0x00,0x0f,0x80,0x00,0xf8,0x00,0x1f,0x00,0x00,0x7c,0x00,0x3e,0x00,0x00,0x3e,0x00,0x7c,0x00,0x00,0x3e,0x00,0x7c,0x00,0x00,0x7c,0x00,0x3e,0x00,0x00,0xf8,0x00,0x1f,0x00,0x01,0xf0,0x00,0x0f,0x80,0x03,0xe0,0x00,0x07,0xc0,0x07,0xc0,0x18,0x03,0xe0,0x0f,0x80,0x3c,0x01,0xf0,0x1f,0x00,0x7e,0x00,0xf8,0x3e,0x00,0xff,0x00,0x7c,0x7c,0x01,0xff,0x80,0x3e,0x78,0x03,0xe7,0xc0,0x1e,0xf0,0x07,0xc3,0xe0,0x0f,0xe0,0x0f,0x81,0xf0,0x07,0xe0,0x1f,0x00,0xf8,0x07,0xe0,0x3e,0x00,0x7c,0x07,0xf0,0x7c,0x00,0x3e,0x0f,0x78,0xf8,0x00,0x1f,0x1e,0x7f,0xf0,0x00,0x0f,0xfe,0x3f,0xe0,0x00,0x07,0xfc,0x0f,0x80,0x00,0x01,0xf0};
static const unsigned char PROGMEM cross_in[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0xe0,0x0f,0x80,0x00,0x01,0xf0,0x1f,0xc0,0x00,0x03,0xf8,0x1f,0xe0,0x00,0x07,0xf8,0x1f,0xf0,0x00,0x0f,0xf8,0x0f,0xf8,0x00,0x1f,0xf0,0x07,0xfc,0x00,0x3f,0xe0,0x03,0xfe,0x00,0x7f,0xc0,0x01,0xff,0x00,0xff,0x80,0x00,0xff,0x81,0xff,0x00,0x00,0x7f,0xc3,0xfe,0x00,0x00,0x3f,0xe7,0xfc,0x00,0x00,0x1f,0xff,0xf8,0x00,0x00,0x0f,0xff,0xf0,0x00,0x00,0x07,0xff,0xe0,0x00,0x00,0x03,0xff,0xc0,0x00,0x00,0x01,0xff,0x80,0x00,0x00,0x01,0xff,0x80,0x00,0x00,0x03,0xff,0xc0,0x00,0x00,0x07,0xff,0xe0,0x00,0x00,0x0f,0xff,0xf0,0x00,0x00,0x1f,0xff,0xf8,0x00,0x00,0x3f,0xe7,0xfc,0x00,0x00,0x7f,0xc3,0xfe,0x00,0x00,0xff,0x81,0xff,0x00,0x01,0xff,0x00,0xff,0x80,0x03,0xfe,0x00,0x7f,0xc0,0x07,0xfc,0x00,0x3f,0xe0,0x0f,0xf8,0x00,0x1f,0xf0,0x1f,0xf0,0x00,0x0f,0xf8,0x1f,0xe0,0x00,0x07,0xf8,0x1f,0xc0,0x00,0x03,0xf8,0x0f,0x80,0x00,0x01,0xf0,0x07,0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
static const unsigned char PROGMEM headphones_icon[] = {0x00,0x00,0xff,0xff,0x80,0x01,0xbf,0xfd,0xa0,0x05,0xa0,0x05,0xa0,0x05,0xa0,0x05,0xa0,0x05,0xbf,0xfd,0x80,0x01,0xff,0xff,0x03,0xc0,0x03,0xc0,0x0f,0xf0,0x00,0x00};
static const unsigned char PROGMEM monitor_icon[] = {0x07,0xc0,0x1e,0xf0,0x38,0x38,0x60,0x0c,0x40,0x04,0x80,0x02,0x80,0x02,0x80,0x02,0x60,0x0c,0x90,0x12,0x98,0x32,0xc8,0x26,0x44,0x44,0x64,0x4c,0x38,0x38,0x00,0x00};
static const unsigned char PROGMEM mute_icon[] = {0x00,0x00,0xff,0x00,0x00,0x00,0x0f,0xff,0xf0,0x00,0x00,0x3f,0xff,0xfc,0x00,0x00,0x7f,0xff,0xfe,0x00,0x01,0xff,0xff,0xff,0x80,0x03,0xff,0xff,0xff,0xc0,0x07,0xfe,0x00,0x7f,0xe0,0x0f,0xf8,0x00,0x1f,0xf0,0x0f,0xf0,0x00,0x0f,0xf0,0x1f,0xf0,0x00,0x03,0xf8,0x3f,0xf8,0x00,0x01,0xfc,0x3f,0xfc,0x00,0x01,0xfc,0x7f,0x7e,0x00,0x00,0xfe,0x7e,0x3f,0x00,0x00,0x7e,0x7e,0x1f,0x80,0x00,0x7e,0xfc,0x0f,0xc0,0x00,0x3e,0xfc,0x07,0xe0,0x00,0x3f,0xfc,0x03,0xf0,0x00,0x3f,0xfc,0x01,0xf8,0x00,0x3f,0xfc,0x00,0xfc,0x00,0x3f,0xfc,0x00,0x7e,0x00,0x3f,0xfc,0x00,0x3f,0x00,0x3f,0xfc,0x00,0x1f,0x80,0x3f,0xfc,0x00,0x0f,0xc0,0x3f,0xfc,0x00,0x07,0xe0,0x3e,0x7e,0x00,0x03,0xf0,0x7e,0x7e,0x00,0x01,0xf8,0x7e,0x7f,0x00,0x00,0xfc,0xfe,0x3f,0x00,0x00,0x7f,0xfc,0x3f,0x80,0x00,0x3f,0xfc,0x1f,0xc0,0x00,0x1f,0xf8,0x0f,0xe0,0x00,0x0f,0xf0,0x0f,0xf8,0x00,0x1f,0xf0,0x07,0xfe,0x00,0x7f,0xe0,0x03,0xff,0xff,0xff,0xc0,0x01,0xff,0xff,0xff,0x80,0x00,0x7f,0xff,0xfe,0x00,0x00,0x3f,0xff,0xfc,0x00,0x00,0x0f,0xff,0xf0,0x00,0x00,0x01,0xff,0x80,0x00};
const int NUM_SLIDERS = 5, NUM_AUDIO = 4;
const byte PotOne = 4, PotTwo = 5, PotThree = 6, PotFour = 7, PotFive = 15;
const byte MuteBTN = 40, ConfBTN = 48;
const int analogInputs[NUM_SLIDERS] = {PotOne, PotTwo, PotThree, PotFour, PotFive};
const int potMax = 4095.0; // NEED to make this a float else division will be integer
int p, w, c, m, a=10;
int curpot=0, curaud=0, timer=0;
const int max_timer=100, colour=1, transparent=0;
bool boot = true, mute = false;
int analogSliderValues[NUM_SLIDERS];
static const unsigned char* volImages[NUM_SLIDERS-1] = {global_icon,chrome_icon,discord_icon,game_icon};
static const unsigned char* audImages[2] = {headphones_icon,monitor_icon};
const String audSources[] = {"Innoview","Acer Nitro","Headphones","Headset"};
const String audTypes[] = {"Speakers","Bluetooth"};
int HotKeys[4] = {KEY_F9,KEY_F10,KEY_F11,KEY_F12};
void Display(uint8_t bus){
Wire.beginTransmission(0x70); // TCA9548A address is 0x70
Wire.write(1 << bus); // send byte to select bus
Wire.endTransmission();
}
void gauge(void) {
Display(1);
// show digital value and align its position
display.clearDisplay();
display.setTextColor(colour);
display.setTextWrap(false);
display.setFont(&FreeSerifBold9pt7b);
if (curpot != NUM_SLIDERS-1) {
display.setCursor(85,57);
if (mute != true) {
if (w<10){
display.print("0");
}
if (w>99) {
display.setCursor(80,57);
}
display.print(w);
display.print("%");
display.drawBitmap(82, 4, volImages[curpot], 40, 40, colour);
}
else {
display.setCursor(81,57);
display.print("Mute");
display.drawBitmap(82, 4, mute_icon, 40, 40, colour);
}
int frameX[] = {2, 24, 42, 60}; // x values for all borders
for (int i = 0; i < NUM_SLIDERS-1; i++) {
display.drawRect(frameX[i],4,15,54, colour);
float boxProg = 48*((float)analogSliderValues[i]/potMax);
if (boxProg >= 1) { // draw an empty box when volume = 0
display.fillRect(frameX[i]+3, 7+(48-boxProg), 9, boxProg, colour);
}
else if (i == curpot and mute == false) { // draw an x over the image when volume = 0 and that image is displayed
display.drawBitmap(82, 4, cross_out, 40, 40, colour);
display.drawBitmap(82, 4, cross_in, 40, 40, transparent);
}
}
}
else {
display.setFont(&FreeSerif9pt7b);
int chanNum = analogRead(PotFive);
for (int i = 0; i < NUM_AUDIO; i++) {
if (curaud!= i and chanNum< (i+1)*(potMax/NUM_AUDIO) and chanNum >= i*(potMax/NUM_AUDIO)) {
curaud = i;
keyboard.press(KEY_RIGHT_ALT);
keyboard.press(KEY_RIGHT_CTRL);
keyboard.press(HotKeys[curaud]);
break;
}
}
display.drawRect(4, 17, 120, 23, colour);
display.drawLine(4, 14, 123, 14, colour);
display.setCursor(9, 34);
display.print(audSources[curaud]);
int closeBox[] = {15,44,73,103};
int openBox[] = {10,39,69,98};
int numBox[] = {15,44,74,103};
for (int i = 0; i < NUM_AUDIO; i++) {
if (curaud == i) {
display.drawRect(openBox[i],44,19,19, colour);
display.setCursor(numBox[i],59);
display.print(i+1);
}
else {
display.fillRect(closeBox[i],49,9,9, colour);
}
}
int source = 0;
if (curaud/(float)NUM_AUDIO >= 0.5) {
source = 1;
}
display.setCursor(4,13);
display.print(audTypes[source]);
display.drawBitmap(104, 21, audImages[source], 16, 16, colour);
}
display.display();
}
void setup(void) {
// put your setup code here, to run once:
Wire.begin();
Serial.begin(9600);
keyboard.begin();
pinMode(MuteBTN, INPUT_PULLUP);
pinMode(LED, OUTPUT);
Display(1);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
// display.display();
// Clear the buffer
display.clearDisplay();
}
void loop(void) {
String builtString = String("");
activationMode = GetToggleSwitchState(MuteBTN); // must be executed all the time
if (activationMode != last_activationMode) {
mute = !mute;
last_activationMode = activationMode;
curpot = 0;
}
for (int i = 0; i < NUM_SLIDERS; i++) {
c = analogRead(analogInputs[i]);
if ( analogSliderValues[i] != c and boot == false) {
curpot = i;
timer = max_timer;
}
analogSliderValues[i] = c;
builtString += String((int)analogSliderValues[i]);
if (i < NUM_SLIDERS - 1) {
builtString += String("|");
}
}
p = analogSliderValues[curpot];
w = map(p,0,(int)potMax,0,100);
gauge();
if (timer > 0) {
timer -= 1;
}
else {
timer = 0;
if (curpot != 0) {
curpot = 0;
}
}
Serial.println(builtString);
if (mute == false) {
digitalWrite(LED, HIGH);
} else {
digitalWrite(LED, LOW);
}
// printSliderValues(); // is only for debug, remove in actual
boot = false; // set the boot value (true when it turns on only) to false
}
void printSliderValues() {
for (int i = 0; i < NUM_SLIDERS; i++) {
int curValue = analogSliderValues[i];
if (mute == true) {
curValue = 0;
}
String printedString = String("Slider #") + String(i + 1) + String(": ") + String(curValue) + String(" mV");
Serial.write(printedString.c_str());
if (i < NUM_SLIDERS - 1) {
Serial.write(" | ");
} else {
Serial.write("\n");
}
}
}
bool GetToggleSwitchState(const byte BTN) {
// "static" makes variables persistant over function calls
static bool toggleState = false;
static bool lastToggleState = false;
static byte buttonStateOld = unPressed;
static unsigned long buttonScanStarted = 0;
unsigned long buttonDebounceTime = 50;
static unsigned long buttonDebounceTimer;
byte buttonStateNew;
if ( TimePeriodIsOver(buttonDebounceTimer, buttonDebounceTime) ) {
// if more time than buttonDebounceTime has passed by
// this means let pass by some time until
// bouncing of the button is over
buttonStateNew = digitalRead(BTN);
if (buttonStateNew != buttonStateOld) {
// if button-state has changed
buttonStateOld = buttonStateNew;
if (buttonStateNew == unPressed) {
// if button is released
toggleState = !toggleState; // toggle state-variable
} // the attention-mark is the NOT operator
} // which simply inverts the boolean state
} // !true = false NOT true is false
// !false = true NOT false is true
return toggleState;
}
// easy to use helper-function for non-blocking timing
boolean TimePeriodIsOver (unsigned long &startOfPeriod, unsigned long TimePeriod) {
unsigned long currentMillis = millis();
if ( currentMillis - startOfPeriod >= TimePeriod ) {
// more time than TimePeriod has elapsed since last time if-condition was true
startOfPeriod = currentMillis; // a new period starts right here so set new starttime
return true;
}
else return false; // actual TimePeriod is NOT yet over
}