Skip to content
Snippets Groups Projects
Select Git revision
1 result Searching

wolpertinger.ino

Blame
  • wolpertinger.ino 8.61 KiB
    #include <math.h>
    #include <Wire.h>
    #include <hexbright.h>
    
    // Modes
    #define MODE_OFF_PREVIEW        0
    #define MODE_OFF                1
    #define MODE_STATIC_PREVIEW     2
    #define MODE_STATIC             3
    #define MODE_DYNAMIC_PREVIEW    4
    #define MODE_FADE               5
    #define MODE_BLINKING           6
    #define MODE_STROBE             7
    #define MODE_DAZZLE             8
    #define MODE_TAPS_PREVIEW       9
    #define MODE_TAPS_RECORD        10
    #define MODE_TAPS_PLAYBACK      11
    
    // State
    byte mode;
    hexbright hb;
    char fade_direction = -1;
    
    /***
     *
     * Edit these 4 parameters for your own brightness levels,
     * which level to use first and wether to increase or
     * decrease from that level to the next
     *
     ***/
    
    #define BRIGHTNESS_COUNT 5
    int brightness[BRIGHTNESS_COUNT] = {10, 250, 500, 750, 1000};
    int current_brightness = 0;
    int increase_brightness = 1;
    
    /***
     *
     * Define the time (in milliseconds) for switching between
     * static/non-static mode and until switching off
     *
     ***/
    
    int DOUBLECLICK = 100;
    int HOLD_SHORT = 500;
    int HOLD_LONG = 2000;
    
    void setup()
    {
      /// Set DEBUG to a non-zero value in hexbright.h to enable printing
      hb.init_hardware();
      mode = MODE_OFF;
    }
    
    void loop()
    {
      hb.update();
      hb.print_charge(GLED);
    
      boolean button_just_pressed = hb.button_just_pressed();
      boolean button_just_released = hb.button_just_released();
      boolean button_pressed = hb.button_pressed();
      int button_pressed_time = hb.button_pressed_time();
      int button_released_time = hb.button_released_time();
      
      byte newMode = mode;
      
      switch (mode) {
        case MODE_OFF_PREVIEW:
          if (button_just_released) {