forked from W4D/soundcube-firmware
encoder working
This commit is contained in:
@ -1,18 +1,22 @@
|
||||
#include <TCA9555.h>
|
||||
#include <AS5600.h>
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#include <PWMAudio.h>
|
||||
#include <I2S.h>
|
||||
|
||||
#define HAPTIC 1
|
||||
#define AURAL 1
|
||||
#define HAPTIC 0
|
||||
#define AURAL 0
|
||||
#define UI_SAMPLERATE 22050
|
||||
|
||||
I2S i2s(INPUT_PULLUP);
|
||||
|
||||
TCA9555 TCA(0x20, &Wire1);
|
||||
AS5600 ENC(&Wire1);
|
||||
|
||||
PWMAudio ui_snd(8);
|
||||
|
||||
enum BUTTON {CVINL, CVINR, INL, INR, OUTR, OUTL, CVOUTR, CVOUTL, RIGHT, LEFT, SELECT, DEBUG1, DEBUG2, DEBUG3};
|
||||
|
||||
Adafruit_NeoPixel edge_pixels(8, 4, NEO_GRB + NEO_KHZ800);
|
||||
Adafruit_NeoPixel ui_pixels(72, 5, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
@ -22,6 +26,8 @@ volatile bool amp = false;
|
||||
|
||||
int counter = 0;
|
||||
|
||||
bool buttons[16] = {false};
|
||||
|
||||
int16_t beep[UI_SAMPLERATE];
|
||||
|
||||
void pwm_audio_callback() {
|
||||
@ -67,6 +73,9 @@ void setup() {
|
||||
attachInterrupt(digitalPinToInterrupt(1), tca_irq, FALLING);
|
||||
Serial.println("SUCCESS");
|
||||
|
||||
// Rotary Encoder
|
||||
ENC.begin(4); // set direction pin.
|
||||
|
||||
pinMode(6, OUTPUT); // Vibration Motor
|
||||
pinMode(7, OUTPUT); // UI Amp Enable
|
||||
|
||||
@ -78,30 +87,55 @@ void setup() {
|
||||
edge_pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||
ui_pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||
|
||||
i2s.setDOUT(14);
|
||||
i2s.setDIN(15);
|
||||
i2s.setBCLK(16); //
|
||||
i2s.swapClocks();
|
||||
i2s.setMCLK(18);
|
||||
i2s.setBitsPerSample(16);
|
||||
i2s.setFrequency(48000);
|
||||
i2s.setSysClk(48000)
|
||||
i2s.begin();
|
||||
// i2s.setDOUT(14);
|
||||
// i2s.setDIN(15);
|
||||
// i2s.setBCLK(16); //
|
||||
// i2s.swapClocks();
|
||||
// i2s.setMCLK(18);
|
||||
// i2s.setBitsPerSample(16);
|
||||
// i2s.setFrequency(48000);
|
||||
// i2s.setSysClk(48000);
|
||||
// i2s.begin();
|
||||
|
||||
while (1) {
|
||||
int16_t l, r;
|
||||
i2s.read16(&l, &r);
|
||||
i2s.write16(l, r);
|
||||
}
|
||||
// while (1) {
|
||||
// int16_t l, r;
|
||||
// i2s.read16(&l, &r);
|
||||
// i2s.write16(l, r);
|
||||
// }
|
||||
}
|
||||
int active = 0;
|
||||
uint32_t lastTime = 0;
|
||||
int32_t position = 0;
|
||||
|
||||
void loop() {
|
||||
edge_pixels.clear(); // Set all pixel colors to 'off'
|
||||
ui_pixels.clear(); // Set all pixel colors to 'off'
|
||||
|
||||
position = ENC.getCumulativePosition();
|
||||
|
||||
// if (millis() - lastTime >= 100)
|
||||
// {
|
||||
// lastTime = millis();
|
||||
// Serial.print(ENC.getCumulativePosition());
|
||||
// Serial.print("\t");
|
||||
// Serial.println(ENC.getRevolutions());
|
||||
// }
|
||||
|
||||
for (int i = 0; i < 48; i++) {
|
||||
ui_pixels.setPixelColor(i + 3, edge_pixels.Color(0, 0, 0));
|
||||
}
|
||||
|
||||
if (flag) {
|
||||
int val = TCA.read16();
|
||||
Serial.println(val, BIN);
|
||||
|
||||
for(int i = 0; i < 16; i++){
|
||||
buttons[i] = ~(val >> i) & 0x01;
|
||||
Serial.print(buttons[i]);
|
||||
Serial.print(" ");
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
flag = false;
|
||||
if (HAPTIC) {
|
||||
digitalWrite(6, HIGH);
|
||||
@ -117,28 +151,32 @@ void loop() {
|
||||
if(!AURAL) delay(50);
|
||||
digitalWrite(6, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
edge_pixels.setPixelColor(i, edge_pixels.Color(5, 5, 5));
|
||||
}
|
||||
|
||||
ui_pixels.setPixelColor(0, edge_pixels.Color(0, 0, 5));
|
||||
ui_pixels.setPixelColor(1, edge_pixels.Color(0, 0, 5));
|
||||
ui_pixels.setPixelColor(2, edge_pixels.Color(0, 0, 5));
|
||||
|
||||
for (int i = 0; i < 48; i++) {
|
||||
if (flag) {
|
||||
ui_pixels.setPixelColor(i + 3, edge_pixels.Color(0, 5, 0));
|
||||
} else {
|
||||
ui_pixels.setPixelColor(i + 3, edge_pixels.Color(0, 0, 0));
|
||||
ui_pixels.setPixelColor(i + 3, edge_pixels.Color(0, 15, 0));
|
||||
}
|
||||
if(buttons[RIGHT]) active++;
|
||||
if(buttons[LEFT]) active--;
|
||||
if(active == 13) active = 0;
|
||||
if(active == -1) active = 12;
|
||||
}
|
||||
// 11111110 11111111 button right
|
||||
|
||||
// EDGE LEDs
|
||||
for (int i = 0; i < 8; i++) {
|
||||
edge_pixels.setPixelColor(i, edge_pixels.Color(15, 15, 15));
|
||||
}
|
||||
|
||||
// Rotary button LEDs
|
||||
ui_pixels.setPixelColor(0, edge_pixels.Color(0, 0, 15));
|
||||
ui_pixels.setPixelColor(1, edge_pixels.Color(0, 0, 15));
|
||||
ui_pixels.setPixelColor(2, edge_pixels.Color(0, 0, 15));
|
||||
|
||||
for (int i = 0; i < 13; i++) {
|
||||
ui_pixels.setPixelColor(i + 3 + 48 + 4, edge_pixels.Color(5, 0, 0));
|
||||
ui_pixels.setPixelColor(i + 3 + 48 + 4, edge_pixels.Color(0, 0, 0));
|
||||
}
|
||||
|
||||
ui_pixels.setPixelColor(active + 3 + 48 + 4, edge_pixels.Color(255, 255, 255));
|
||||
|
||||
// put your main code here, to run repeatedly:
|
||||
|
||||
edge_pixels.show(); // Set all pixel colors to 'off'
|
||||
|
||||
Reference in New Issue
Block a user