Create a gist now

Instantly share code, notes, and snippets.

@mon /SDVX.ino
Created Jul 22, 2016

Embed
What would you like to do?
Super simple SDVX controller with fading lights
// You will need the SoftPWM and Encoder libraries, available from
// the teensy website. Google!
// Edit the fade time to your liking.
// Edit the pins and keys if you use different ones.
// ENCODER PINS MUST BE 0, 1, 2, 3 FOR BEST PERFORMANCE
// Everything else can go wherever.
#include <Keyboard.h>
#include <Mouse.h>
#include <SoftPWM.h>
#define ENCODER_OPTIMIZE_INTERRUPTS
#include <Encoder.h>
#define DELAY 1 // Delay per loop in ms
#define FADE_TIME 200
typedef struct {
Encoder enc;
char axis;
} encoder_t;
#define ENCODER_COUNT 2
encoder_t encoders[ENCODER_COUNT] = {
{Encoder(0, 1), 'x'},
{Encoder(3, 2), 'y'}
};
typedef struct {
uint8_t switchPin;
uint8_t lightPin;
char key;
} switch_t;
#define SWITCH_COUNT 7
switch_t switches[SWITCH_COUNT] = {
{4, 5, KEY_RETURN}, // START
{6, 7, 'd'}, // A
{8, 9, 'f'}, // B
{10, 16, 'j'}, // C
{14, 15, 'k'}, // D
{A0, A1, 'c'}, // FX A
{A2, A3, 'm'}, // FX B
};
void setup()
{
SoftPWMBegin(SOFTPWM_NORMAL);
for(int i = 0; i < SWITCH_COUNT; i++) {
pinMode(switches[i].switchPin, INPUT_PULLUP);
pinMode(switches[i].lightPin, OUTPUT);
SoftPWMSet(switches[i].lightPin, 0);
SoftPWMSetFadeTime(switches[i].lightPin, 0, FADE_TIME);
}
Keyboard.begin();
}
void loop() {
for(int i = 0; i < SWITCH_COUNT; i++) {
if(digitalRead(switches[i].switchPin) == LOW) {
Keyboard.press(switches[i].key);
SoftPWMSet(switches[i].lightPin, 255);
} else {
Keyboard.release(switches[i].key);
SoftPWMSet(switches[i].lightPin, 0);
}
}
for(int i=0; i < ENCODER_COUNT;i++) {
long encVal = encoders[i].enc.read();
if(encVal != 0) {
if(encoders[i].axis == 'x')
Mouse.move(encVal,0,0);
else
Mouse.move(0,encVal,0);
encoders[i].enc.write(0);
}
}
delay(DELAY);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment