forked from W4D/soundcube-firmware
leds, buttons and vibration motor working
This commit is contained in:
90
soundcube-firmware/soundcube-firmware.ino
Normal file
90
soundcube-firmware/soundcube-firmware.ino
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
#include <TCA9555.h>
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
|
||||||
|
#define HAPTIC 0
|
||||||
|
|
||||||
|
TCA9555 TCA(0x20, &Wire1);
|
||||||
|
|
||||||
|
//PWMAudio ui_snd(8);
|
||||||
|
|
||||||
|
Adafruit_NeoPixel edge_pixels(8, 4, NEO_GRB + NEO_KHZ800);
|
||||||
|
Adafruit_NeoPixel ui_pixels(72, 5, NEO_GRB + NEO_KHZ800);
|
||||||
|
|
||||||
|
volatile bool flag = false;
|
||||||
|
|
||||||
|
void tca_irq()
|
||||||
|
{
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin();
|
||||||
|
delay(2000);
|
||||||
|
|
||||||
|
Serial.println("INIT WIRE");
|
||||||
|
Wire1.setSDA(2);
|
||||||
|
Wire1.setSCL(3);
|
||||||
|
Wire1.begin();
|
||||||
|
Serial.println("SUCCESS");
|
||||||
|
|
||||||
|
Serial.println("INIT TCA");
|
||||||
|
TCA.begin();
|
||||||
|
TCA.pinMode16(0xFFFF);
|
||||||
|
TCA.setPolarity16(0x0000);
|
||||||
|
Serial.println("SUCCESS");
|
||||||
|
|
||||||
|
Serial.println("INIT INTERRUPT");
|
||||||
|
pinMode(1, INPUT_PULLUP);
|
||||||
|
attachInterrupt(digitalPinToInterrupt(1), tca_irq, FALLING);
|
||||||
|
Serial.println("SUCCESS");
|
||||||
|
|
||||||
|
pinMode(6, OUTPUT); // Vibration Motor
|
||||||
|
pinMode(7, OUTPUT); // UI Amp Enable
|
||||||
|
|
||||||
|
//ui_snd.begin(44100);
|
||||||
|
|
||||||
|
edge_pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
|
ui_pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
edge_pixels.clear(); // Set all pixel colors to 'off'
|
||||||
|
ui_pixels.clear(); // Set all pixel colors to 'off'
|
||||||
|
|
||||||
|
if(flag){
|
||||||
|
int val = TCA.read16();
|
||||||
|
Serial.println(val, BIN);
|
||||||
|
flag = false;
|
||||||
|
if(HAPTIC){
|
||||||
|
digitalWrite(6, HIGH);
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < 13; i++){
|
||||||
|
ui_pixels.setPixelColor(i+3+48+4,edge_pixels.Color(5,0,0));
|
||||||
|
}
|
||||||
|
|
||||||
|
// put your main code here, to run repeatedly:
|
||||||
|
|
||||||
|
edge_pixels.show(); // Set all pixel colors to 'off'
|
||||||
|
ui_pixels.show(); // Set all pixel colors to 'off'
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user