six key encoder with oled firmware

2020-11-25

the laptop i was using to flash this board blew up

that's fine i wanted to get https://platformio.org/ working anyway

i ended up just starting over for now encoder isn't working yet but i'm able to flash it fine with my new laptop so whenever the need arises i'll come back to this

#include <Arduino.h>
#include <ClickEncoder.h>
#include <TimerOne.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_GFX.h>
#include <HID-Project.h>
#include <Adafruit_SSD1306.h>

// setup 6 switches

#define RowOneOne 4
#define RowOneTwo 5
#define RowOneThree 6
#define RowTwoOne 7
#define RowTwoTwo 8
#define RowTwoThree 9
#define RightSwitch 13

Adafruit_NeoPixel strip(6, 12, NEO_GRB + NEO_KHZ800);

const uint32_t RED   = strip.Color(155, 155,   0);
const uint32_t GREEN = strip.Color(  0, 155, 155);
const uint32_t BLUE  = strip.Color(155,   0, 155);
const uint32_t OFF = strip.Color(20,  0, 20);

// setup encoder with timers

ClickEncoder encoder(10, 11, A0);

// template<typename T>

// struct TimeStampedValue {
//   explicit TimeStampedValue(T value) : _value(value), _timeStamp(0) {}
//   void set(const T& value) { _value = value; touch(); }
//   operator const T&() const { return _value; }
//   void touch() { _timeStamp = millis(); }
//   unsigned long getTimeStamp() const { return _timeStamp; }

// private:
//   T _value;
//   unsigned long _timeStamp;
// };

// TimeStampedValue<int16_t> value(0);
// int16_t current = 0;
// int16_t intensity = 0;

// void timerIsr() {
//   encoder.service();
// }

// setup screen
Adafruit_SSD1306 display;
boolean OledClear = true;
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

void setup()  {
  pinMode (RowOneOne, INPUT_PULLUP);
  pinMode (RowOneTwo, INPUT_PULLUP);
  pinMode (RowOneThree, INPUT_PULLUP);
  pinMode (RowTwoOne, INPUT_PULLUP);
  pinMode (RowTwoTwo, INPUT_PULLUP);
  pinMode (RowTwoThree, INPUT_PULLUP);
  pinMode (RightSwitch, INPUT_PULLUP);

  strip.begin();
  strip.show();

  // Timer1.initialize(1000);
  // Timer1.attachInterrupt(timerIsr);

  Keyboard.begin();
  Consumer.begin();

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.display();
 // delay(2000);
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.println("shane0 keebs");
  display.startscrollright(0x00, 0x0F);

}

void loop()  {
  // Top Layer Programming
  if (digitalRead(RightSwitch) == HIGH)
  {
    strip.setPixelColor(0, 128, 0, 64);   // 1  clockwise counting wtf
    strip.setPixelColor(1, 0, 128, 128);  // 2
    strip.setPixelColor(2, 128, 0, 64);   // 3
    strip.setPixelColor(3, 0, 128, 128);  // 4
    strip.setPixelColor(4, 0, 128, 128);  // 5
    strip.setPixelColor(5, 0, 128, 128);  // 6
    strip.show();
    // keys
    if (digitalRead(RowOneOne) == LOW)
    {
      Keyboard.press("s");
    }
    if (digitalRead(RowOneOne) == HIGH)
    {
      Keyboard.release("s");
    }
  }
  else if (digitalRead(RightSwitch) == LOW)
  // Bottom Layer Programming
  {
    strip.setPixelColor(0, 128, 128, 0);
    strip.setPixelColor(1, 128, 128, 0);
    strip.setPixelColor(2, 128, 128, 0);
    strip.setPixelColor(3, 128, 0, 128);
    strip.setPixelColor(4, 128, 0, 128);
    strip.setPixelColor(5, 128, 0, 128);
    strip.show();
  }

}

original

#include <Adafruit_NeoPixel.h>
#include <ClickEncoder.h>
#include <TimerOne.h>
#include <HID-Project.h>

#include <SPI.h>
#include <Wire.h>

#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>

template<typename T>
struct TimeStampedValue {
  explicit TimeStampedValue(T value) : _value(value), _timeStamp(0) {}
  void set(const T& value) { _value = value; touch(); }
  operator const T&() const { return _value; }
  void touch() { _timeStamp = millis(); }
  unsigned long getTimeStamp() const { return _timeStamp; }

private:
  T _value;
  unsigned long _timeStamp;
};

#define TIMEOUT_VIBRA_MS   30
#define TIMEOUT_LIGHTS_MS 600

#define LUp 4
#define Up 5
#define RUp 6
#define Left 7
#define Down 8
#define Right 9
#define Switch 13

Adafruit_NeoPixel strip(6, 12, NEO_GRB + NEO_KHZ800);

Adafruit_NeoPixel strip_a(15, A1, NEO_GRB + NEO_KHZ800);
const uint32_t RED   = strip_a.Color(155, 155,   0);
const uint32_t GREEN = strip_a.Color(  0, 155, 155);
const uint32_t BLUE  = strip_a.Color(155,   0, 155);
const uint32_t OFF = strip_a.Color(20,  0, 20);

ClickEncoder encoder(10, 11, A0);
TimeStampedValue<int16_t> value(0);
int16_t current = 0;
int16_t intensity = 0;

void timerIsr() {
  encoder.service();
}

boolean OledClear = true;

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

static const unsigned char PROGMEM level1[] =
{ 
0x1F, 0xE0, 0xFF, 0x8C, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x09, 0xFE, 0x3F, 0xEF, 0xFB, 0x03,
0x1F, 0xE0, 0xFF, 0x8C, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x09, 0xFE, 0x3F, 0xEF, 0xFB, 0x03,
0x1F, 0xF0, 0xFF, 0x8C, 0x00, 0x40, 0x00, 0x07, 0x80, 0x00, 0x09, 0xFF, 0x3F, 0xEF, 0xFB, 0x07,
0x1F, 0xF0, 0xFF, 0x8C, 0x00, 0x40, 0x00, 0x07, 0x80, 0x00, 0x09, 0xFF, 0x3F, 0xEF, 0xFB, 0x07,
0x18, 0x38, 0xC0, 0x0C, 0x00, 0x40, 0x00, 0x0F, 0xC0, 0x00, 0x09, 0x83, 0xB0, 0x6C, 0x03, 0x06,
0x18, 0x38, 0xC0, 0x0C, 0x00, 0x40, 0x00, 0x0F, 0xC0, 0x00, 0x09, 0x83, 0xB0, 0x6C, 0x03, 0x0E,
0x18, 0x18, 0xC0, 0x0C, 0x00, 0x40, 0x00, 0x1B, 0x60, 0x00, 0x09, 0x81, 0xB0, 0x6C, 0x03, 0x0C,
0x18, 0x18, 0xC0, 0x0C, 0x00, 0x40, 0x00, 0x1B, 0x60, 0x00, 0x09, 0x81, 0xB0, 0x6C, 0x03, 0x0C,
0x18, 0x18, 0xC0, 0x0C, 0x00, 0x40, 0x00, 0x33, 0x30, 0x00, 0x09, 0x83, 0xB0, 0x6C, 0x03, 0x1C,
0x18, 0x18, 0xC0, 0x0C, 0x00, 0x40, 0x00, 0x33, 0x30, 0x00, 0x09, 0x83, 0xB0, 0x6C, 0x03, 0x1C,
0x18, 0x18, 0xFE, 0x0C, 0x00, 0x40, 0x00, 0x63, 0x18, 0x00, 0x09, 0xFF, 0x3F, 0xEC, 0x03, 0xF8,
0x18, 0x18, 0xFE, 0x0C, 0x00, 0x40, 0x00, 0x63, 0x18, 0x00, 0x09, 0xFF, 0x3F, 0xEC, 0x03, 0xF8,
0x18, 0x18, 0xFE, 0x0C, 0x00, 0x40, 0x00, 0xC3, 0x0C, 0x00, 0x09, 0xFE, 0x3F, 0xEC, 0x03, 0xF8,
0x18, 0x18, 0xFE, 0x0C, 0x00, 0x40, 0x00, 0xC3, 0x0C, 0x00, 0x09, 0xFF, 0x3F, 0xEC, 0x03, 0xF8,
0x18, 0x18, 0xC0, 0x0C, 0x00, 0x40, 0x00, 0x83, 0x04, 0x00, 0x09, 0xFF, 0x30, 0x6C, 0x03, 0x1C,
0x18, 0x18, 0xC0, 0x0C, 0x00, 0x40, 0x00, 0x83, 0x04, 0x00, 0x09, 0x83, 0xB0, 0x6C, 0x03, 0x1C,
0x18, 0x18, 0xC0, 0x0C, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x09, 0x83, 0xB0, 0x6C, 0x03, 0x0C,
0x18, 0x18, 0xC0, 0x0C, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x09, 0x81, 0xB0, 0x6C, 0x03, 0x0C,
0x18, 0x18, 0xC0, 0x0C, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x09, 0x81, 0xB0, 0x6C, 0x03, 0x0E,
0x18, 0x18, 0xC0, 0x0C, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x09, 0x81, 0xB0, 0x6C, 0x03, 0x06,
0x18, 0x38, 0xC0, 0x0C, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x09, 0x83, 0xB0, 0x6C, 0x03, 0x06,
0x18, 0x38, 0xC0, 0x0C, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x09, 0x83, 0xB0, 0x6C, 0x03, 0x07,
0x1F, 0xF0, 0xFF, 0x8F, 0xF8, 0x40, 0x00, 0x03, 0x00, 0x00, 0x09, 0xFF, 0x30, 0x6F, 0xFB, 0x07,
0x1F, 0xF0, 0xFF, 0x8F, 0xF8, 0x40, 0x00, 0x03, 0x00, 0x00, 0x09, 0xFF, 0x30, 0x6F, 0xFB, 0x03,
0x1F, 0xE0, 0xFF, 0x8F, 0xF8, 0x40, 0x00, 0x03, 0x00, 0x00, 0x09, 0xFE, 0x30, 0x6F, 0xFB, 0x03,
0x1F, 0xE0, 0xFF, 0x8F, 0xF8, 0x40, 0x00, 0x03, 0x00, 0x00, 0x09, 0xFE, 0x30, 0x6F, 0xFB, 0x03,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x60, 0x00, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x18, 0x00, 0x00,
0x00, 0x00, 0x60, 0x00, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x18, 0x00, 0x00,
0x00, 0x00, 0xC0, 0x00, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x0C, 0x00, 0x00,
0x00, 0x00, 0xC0, 0x00, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x0C, 0x00, 0x00,
0x00, 0x01, 0x80, 0x00, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x06, 0x00, 0x00,
0x00, 0x01, 0x80, 0x00, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x06, 0x00, 0x00,
0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x03, 0x00, 0x00,
0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x03, 0x00, 0x00,
0x00, 0x06, 0x00, 0x00, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x01, 0x80, 0x00,
0x00, 0x06, 0x00, 0x00, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x01, 0x80, 0x00,
0x00, 0x0C, 0x00, 0x00, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xC0, 0x00,
0x00, 0x0C, 0x00, 0x00, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xC0, 0x00,
0x00, 0x1F, 0xFF, 0xF0, 0x00, 0x40, 0x00, 0x83, 0x04, 0x00, 0x08, 0x00, 0x3F, 0xFF, 0xE0, 0x00,
0x00, 0x1F, 0xFF, 0xF0, 0x00, 0x40, 0x00, 0x83, 0x04, 0x00, 0x08, 0x00, 0x3F, 0xFF, 0xE0, 0x00,
0x00, 0x1F, 0xFF, 0xF0, 0x00, 0x40, 0x00, 0xC3, 0x0C, 0x00, 0x08, 0x00, 0x3F, 0xFF, 0xE0, 0x00,
0x00, 0x1F, 0xFF, 0xF0, 0x00, 0x40, 0x00, 0xC3, 0x0C, 0x00, 0x08, 0x00, 0x3F, 0xFF, 0xE0, 0x00,
0x00, 0x0C, 0x00, 0x00, 0x00, 0x40, 0x00, 0x63, 0x18, 0x00, 0x08, 0x00, 0x00, 0x00, 0xC0, 0x00,
0x00, 0x0C, 0x00, 0x00, 0x00, 0x40, 0x00, 0x63, 0x18, 0x00, 0x08, 0x00, 0x00, 0x00, 0xC0, 0x00,
0x00, 0x06, 0x00, 0x00, 0x00, 0x40, 0x00, 0x33, 0x30, 0x00, 0x08, 0x00, 0x00, 0x01, 0x80, 0x00,
0x00, 0x06, 0x00, 0x00, 0x00, 0x40, 0x00, 0x33, 0x30, 0x00, 0x08, 0x00, 0x00, 0x01, 0x80, 0x00,
0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0x00, 0x1B, 0x60, 0x00, 0x08, 0x00, 0x00, 0x03, 0x00, 0x00,
0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0x00, 0x1B, 0x60, 0x00, 0x08, 0x00, 0x00, 0x03, 0x00, 0x00,
0x00, 0x01, 0x80, 0x00, 0x00, 0x40, 0x00, 0x0F, 0xC0, 0x00, 0x08, 0x00, 0x00, 0x06, 0x00, 0x00,
0x00, 0x01, 0x80, 0x00, 0x00, 0x40, 0x00, 0x0F, 0xC0, 0x00, 0x08, 0x00, 0x00, 0x06, 0x00, 0x00,
0x00, 0x00, 0xC0, 0x00, 0x00, 0x40, 0x00, 0x07, 0x80, 0x00, 0x08, 0x00, 0x00, 0x0C, 0x00, 0x00,
0x00, 0x00, 0xC0, 0x00, 0x00, 0x40, 0x00, 0x07, 0x80, 0x00, 0x08, 0x00, 0x00, 0x0C, 0x00, 0x00,
0x00, 0x00, 0x60, 0x00, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x18, 0x00, 0x00,
0x00, 0x00, 0x60, 0x00, 0x00, 0x40, 0x00, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x18, 0x00, 0x00
};

static const unsigned char PROGMEM level2[] =
{ 
0x0F, 0xF8, 0x3F, 0x0F, 0xF0, 0x58, 0x37, 0xFD, 0xFF, 0xBF, 0xE9, 0xFE, 0x3F, 0xC0, 0xFC, 0xFF,
0x0F, 0xF8, 0x3F, 0x0F, 0xF0, 0x58, 0x37, 0xFD, 0xFF, 0xBF, 0xE9, 0xFE, 0x3F, 0xC0, 0xFC, 0xFF,
0x0F, 0xF8, 0x7F, 0x0F, 0xF0, 0x58, 0x37, 0xFD, 0xFF, 0xBF, 0xE9, 0xFF, 0x3F, 0xE1, 0xFC, 0xFF,
0x0F, 0xF8, 0x7F, 0x0F, 0xF0, 0x58, 0x37, 0xFD, 0xFF, 0xBF, 0xE9, 0xFF, 0x3F, 0xE1, 0xFC, 0xFF,
0x0C, 0x00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, 0x09, 0x80, 0x30, 0xC0, 0x0E, 0xC0,
0x0C, 0x00, 0x01, 0x8C, 0x00, 0x58, 0x36, 0x0D, 0x81, 0xB0, 0x09, 0x80, 0x30, 0x60, 0x06, 0xC0,
0x0C, 0x00, 0x01, 0x8C, 0x00, 0x58, 0x36, 0x0D, 0x81, 0xB0, 0x09, 0x80, 0x30, 0x60, 0x06, 0xC0,
0x0C, 0x00, 0x01, 0x8C, 0x00, 0x58, 0x36, 0x0D, 0x81, 0xB0, 0x09, 0x80, 0x30, 0x60, 0x06, 0xC0,
0x0C, 0x00, 0x01, 0x8C, 0x00, 0x58, 0x36, 0x0D, 0x81, 0xB0, 0x09, 0x80, 0x30, 0x60, 0x06, 0xC0,
0x0C, 0x00, 0x03, 0x8C, 0x00, 0x58, 0x36, 0x0D, 0x81, 0xB0, 0x09, 0x80, 0x30, 0x30, 0x0E, 0xC0,
0x0C, 0x00, 0x03, 0x8C, 0x00, 0x58, 0x36, 0x0D, 0x81, 0xB0, 0x09, 0x80, 0x30, 0x30, 0x0E, 0xC0,
0x0F, 0xF8, 0xFF, 0x0F, 0xF0, 0x58, 0x36, 0x0D, 0x81, 0xBF, 0xE9, 0x80, 0x30, 0x3B, 0xFC, 0xFF,
0x0F, 0xF8, 0xFF, 0x0F, 0xF0, 0x58, 0x37, 0xFD, 0x81, 0xBF, 0xE9, 0x80, 0x30, 0x3B, 0xFC, 0xFF,
0x0F, 0xF8, 0xFE, 0x0F, 0xF0, 0x58, 0x37, 0xFD, 0x81, 0xBF, 0xE9, 0x80, 0x30, 0x1B, 0xF8, 0xFF,
0x0F, 0xF8, 0xFE, 0x0F, 0xF0, 0x58, 0x37, 0xFD, 0x81, 0xBF, 0xE9, 0x80, 0x30, 0x1B, 0xF8, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0x07, 0xE6, 0x03, 0xFE, 0x43, 0xFE, 0x30, 0x31, 0xFE, 0x08, 0x7E, 0x7F, 0xD8, 0x0D, 0xFF,
0xFF, 0x07, 0xE6, 0x03, 0xFE, 0x43, 0xFE, 0x30, 0x31, 0xFE, 0x08, 0x7E, 0x7F,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, 0x3F, 0xF1, 0x81, 0x88, 0x7E, 0x7F, 0xCF, 0x79, 0xFC,
0xC0, 0xC0, 0x76, 0x03, 0x06, 0x43, 0x00, 0x37, 0xF1, 0x81, 0x88, 0x07, 0x60, 0xC7, 0x71, 0x80,
0xC0, 0xC0, 0x76, 0x03, 0x06, 0x43, 0x00, 0x37, 0xF1, 0x81, 0x88, 0x07, 0x60, 0xC7, 0x71, 0x80,
0xC0, 0xC0, 0x36, 0x03, 0x06, 0x43, 0x00, 0x33, 0xF1, 0x81, 0x88, 0x03, 0x60, 0xC7, 0x71, 0x80,
0xC0, 0xC0, 0x36, 0x03, 0x06, 0x43, 0x00, 0x33, 0xF1, 0x81, 0x88, 0x03, 0x60, 0xC7, 0x71, 0x80,
0xC0, 0xC0, 0x36, 0x03, 0x06, 0x43, 0x00, 0x31, 0xF1, 0x81, 0x88, 0x03, 0x60, 0xC3, 0xE1, 0x80,
0xC0, 0xC0, 0x36, 0x03, 0x06, 0x43, 0x00, 0x31, 0xF1, 0x81, 0x88, 0x03, 0x60, 0xC3, 0xE1, 0x80,
0xC1, 0xC0, 0x76, 0x03, 0x06, 0x43, 0x00, 0x30, 0xF1, 0x83, 0x88, 0x07, 0x60, 0xC3, 0xE1, 0x80,
0xC1, 0xC0, 0x76, 0x03, 0x06, 0x43, 0x00, 0x30, 0xF1, 0x83, 0x88, 0x07, 0x60, 0xC3, 0xE1, 0x80,
0xFF, 0x9F, 0xE7, 0xFB, 0x06, 0x43, 0xFE, 0x30, 0x71, 0xFF, 0x09, 0xFE, 0x60, 0xC1, 0xC1, 0xFF,
0xFF, 0x9F, 0xE7, 0xFB, 0x06, 0x43, 0xFE, 0x30, 0x71, 0xFF, 0x09, 0xFE, 0x60, 0xC1, 0xC1, 0xFF,
0xFF, 0x1F, 0xC7, 0xFB, 0x06, 0x43, 0xFE, 0x30, 0x31, 0xFE, 0x09, 0xFC, 0x60, 0xC1, 0xC1, 0xFF,
0xFF, 0x1F, 0xC7, 0xFB, 0x06, 0x43, 0xFE, 0x30, 0x31, 0xFE, 0x09, 0xFC, 0x60, 0xC1, 0xC1, 0xFF
};

Adafruit_SSD1306 display;

void setup() {

  pinMode (LUp, INPUT_PULLUP);
  pinMode (Up, INPUT_PULLUP);
  pinMode (RUp, INPUT_PULLUP);
  pinMode (Left, INPUT_PULLUP);
  pinMode (Down, INPUT_PULLUP);
  pinMode (Right, INPUT_PULLUP);
  pinMode (Switch, INPUT_PULLUP);

  strip.begin();
  strip.show();

  strip_a.begin();
  strip_a.show();

  Timer1.initialize(1000);
  Timer1.attachInterrupt(timerIsr);

  Keyboard.begin();
  Consumer.begin();

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.display();
 // delay(2000);
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);

}

void loop() {

  current += encoder.getValue();
  auto diff = current - value;
  if (diff != 0) {

    if (diff < 0) {
      intensity = max(1, min(intensity + 1, 10));
      volumeChange(MEDIA_VOL_UP, GREEN);      
    } 
    else {
      intensity = min(-1, max(intensity - 1, -10));
      volumeChange(MEDIA_VOL_DOWN, RED);              
    }
    Serial.println(intensity);
    value.set(current);
  }

  ClickEncoder::Button b = encoder.getButton();
  if (b != ClickEncoder::Open) {
    Serial.println("Button");
    switch (b) {
      case ClickEncoder::Clicked:
        intensity = 9;
        volumeChange(MEDIA_VOL_MUTE, BLUE);              
        value.touch();
        break;
    }
  }
  else {

    if (millis() - value.getTimeStamp() > TIMEOUT_VIBRA_MS) {

    }
    if (millis() - value.getTimeStamp() > TIMEOUT_LIGHTS_MS) {
      setColor(OFF);
      intensity = 1;
    }
  }
}

void volumeChange(uint16_t key, uint32_t color) {
  setColor(color);
  Consumer.write(key);
}


void setColor(uint32_t c) {
  strip_a.setBrightness(abs(intensity) * 255 / 10);
  for (uint16_t i = 0; i < strip_a.numPixels(); i++) {
      strip_a.setPixelColor(i, c);
  }
  strip_a.show();
//}


 if (digitalRead(Switch) == HIGH)
  {
    //Setting the colours (Led number, Red, Green, Blue) max amount that each RGB value can have is 255, min is 0
    strip.setPixelColor(0, 128, 0, 64);   // 1  clockwise counting !!!
    strip.setPixelColor(1, 0, 128, 128);  // 2
    strip.setPixelColor(2, 128, 0, 64);   // 3
    strip.setPixelColor(3, 0, 128, 128);  // 4
    strip.setPixelColor(4, 0, 128, 128);  // 5
    strip.setPixelColor(5, 0, 128, 128);  // 6

    strip.show();
    // Boolean Checks to make sure that we haven't done this before
    if (OledClear == true) {

    display.clearDisplay();
    display.drawBitmap(0, 0,  level1, 128, 64, 1);
    display.display();

      OledClear = false;
    }
   //Up Arrow//
    if (digitalRead(Up) == LOW)
    {
      Keyboard.press(KEY_UP_ARROW);
    }
    if (digitalRead(Up) == HIGH)
    {
      Keyboard.release(KEY_UP_ARROW);
    }

    //Down Arrow//
    if (digitalRead(Down) == LOW)
    {
      Keyboard.press(KEY_DOWN_ARROW);
    }
    if (digitalRead(Down) == HIGH)
    {
      Keyboard.release(KEY_DOWN_ARROW);
    }

    //Right Arrow//
    if (digitalRead(Right) == LOW)
    {
      Keyboard.press(KEY_RIGHT_ARROW);
    }
    if (digitalRead(Right) == HIGH)
    {
      Keyboard.release(KEY_RIGHT_ARROW);
    }

    //Left Arrow//
    if (digitalRead(Left) == LOW)
    {
      Keyboard.press(KEY_LEFT_ARROW);
    }
    if (digitalRead(Left) == HIGH)
    {
      Keyboard.release(KEY_LEFT_ARROW);
    }

    //Top Right Button//
    if (digitalRead(RUp) == LOW)
    {
      Keyboard.press(KEY_BACKSPACE);
    }
    if (digitalRead(RUp)==HIGH)
    {
      Keyboard.release(KEY_BACKSPACE);
    }

    //Top Left Button//
    if (digitalRead(LUp) == LOW)
    {
      Keyboard.press(KEY_DELETE);
    }
    if (digitalRead(LUp) == HIGH)
    {
      Keyboard.release(KEY_DELETE);
    }
  }

  // Second Layer Programming

  else if (digitalRead(Switch) == LOW)
  {
    // Setting the colours (Led number, Red, Green, Blue) max amount that each RGB value can have is 255, min is 0
    strip.setPixelColor(0, 128, 128, 0);
    strip.setPixelColor(1, 128, 128, 0);
    strip.setPixelColor(2, 128, 128, 0);
    strip.setPixelColor(3, 128, 0, 128);
    strip.setPixelColor(4, 128, 0, 128);
    strip.setPixelColor(5, 128, 0, 128);

    strip.show();

    // Make sure that we aren't constantly clearing the display
    if (OledClear == false)
    {

      display.clearDisplay();
      display.drawBitmap(0, 0,  level2, 128, 64, 1);
      display.display();

      OledClear = true;
    }

    //Up Arrow//
    if (digitalRead(Up) == LOW)
    {
        Keyboard.press(KEY_HOME);
    }
    if (digitalRead(Up) == HIGH)
    {
        Keyboard.release(KEY_HOME);
    }

    //Down Arrow//
    if (digitalRead(Down) == LOW)
    {
        Keyboard.press(KEY_END);
    }
    if (digitalRead(Down) == HIGH)
    {
        Keyboard.release(KEY_END);
    }

    //Right Arrow//
    if (digitalRead(Right) == LOW)
    {
      Keyboard.press(KEY_RIGHT_CTRL);
      Keyboard.press('s');     
    }
    if (digitalRead(Right) == HIGH)
    {
    Keyboard.releaseAll();     
    }

    //Left Arrow//
    if (digitalRead(Left) == LOW)
    {
      Keyboard.print("display last");
      delay(1000);
    }
    if (digitalRead(Left) == HIGH)
    {
    Keyboard.releaseAll();
    }

    //Top Right Button//
    if (digitalRead(RUp) == LOW)
    {
        Keyboard.press(KEY_PRINTSCREEN);  // print screen, finally working AGAIN :-))))) 
    }
    if (digitalRead(RUp)==HIGH)
    {
        Keyboard.release(KEY_PRINTSCREEN); 
    }

    //Top Left Button//
    if (digitalRead(LUp) == LOW)
    {
      Keyboard.press(KEY_ESC);
    }
    if (digitalRead(LUp) == HIGH)
    {
      Keyboard.release(KEY_ESC);

    }
  }
}

Comments