committing this black magic for reference later
This commit is contained in:
@@ -2,9 +2,7 @@
|
||||
#include <Arduino.h>
|
||||
#include <SPI.h>
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#include "Adafruit_BLE.h"
|
||||
#include "Adafruit_BluefruitLE_SPI.h"
|
||||
#include "Adafruit_BluefruitLE_UART.h"
|
||||
|
||||
#if SOFTWARE_SERIAL_AVAILABLE
|
||||
#include <SoftwareSerial.h>
|
||||
@@ -18,9 +16,16 @@
|
||||
#define FACTORYRESET true
|
||||
#define DIM_FACTOR 80
|
||||
|
||||
// Updated with bluetooth connection state
|
||||
volatile bool conn = false;
|
||||
volatile char* to_rx;
|
||||
|
||||
const char pattern_rainbow[] PROGMEM = "pattern rainbow";
|
||||
const char* const msg_pattern_rainbow PROGMEM = pattern_rainbow;
|
||||
|
||||
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);
|
||||
|
||||
void bluetooth_setup(){
|
||||
void bluetooth_setup(void){
|
||||
if ( !ble.begin(VERBOSE_MODE) ) {
|
||||
Serial.println(F("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?"));
|
||||
while(1); // halt
|
||||
@@ -52,10 +57,12 @@ void bluetooth_setup(){
|
||||
void on_connect(void){
|
||||
// Status light will go solid blue because of AT+HWMODELED=2
|
||||
Serial.println(F("Bluetooth Connected"));
|
||||
conn = true;
|
||||
}
|
||||
void on_disconnect(void){
|
||||
// Blue status light will shut off because of AT+HWMODELED=2
|
||||
Serial.println(F("Bluetooth Disconnected"));
|
||||
conn = false;
|
||||
}
|
||||
|
||||
void BleUartRX(char payload[], uint16_t payload_len){
|
||||
@@ -137,7 +144,6 @@ class Strip {
|
||||
}
|
||||
|
||||
void off(void){
|
||||
Serial.println(F("off()"));
|
||||
pixel.begin();
|
||||
for(uint8_t i=0; i<num_pixels; i++){
|
||||
pixel.setPixelColor(i, pack_color(0,0,0));
|
||||
@@ -199,7 +205,11 @@ class Strip {
|
||||
unsigned long now = millis();
|
||||
if (now - wait > last){
|
||||
last = now;
|
||||
rainbow();
|
||||
if (pattern == 'o'){
|
||||
off();
|
||||
} else {
|
||||
rainbow();
|
||||
}
|
||||
offset += 1;
|
||||
if (offset == num_pixels){
|
||||
offset = 0;
|
||||
@@ -218,27 +228,40 @@ void setWait(char data[], uint16_t len){
|
||||
uint16_t wait_int = wait.toInt();
|
||||
if (wait_int >= 0 && wait_int <= 200){
|
||||
strip.wait = wait_int;
|
||||
Serial.print(F("strip.wait set to "));
|
||||
Serial.println(wait_int);
|
||||
Serial.println(F("delay set"));
|
||||
} else {
|
||||
Serial.print(F("Speed delay is out of the allowed range (0-200): "));
|
||||
Serial.println(wait_int);
|
||||
Serial.println(F("out of range (0,200)"));
|
||||
}
|
||||
}
|
||||
|
||||
void setPattern(char data[], uint16_t len){
|
||||
if (len != 1){
|
||||
Serial.println(F("Invalid pattern"));
|
||||
Serial.println(F("pattern invalid"));
|
||||
} else if (data[0] == 'r'){
|
||||
Serial.println(F("pattern set to rainbow"));
|
||||
strip.pattern = 'r';
|
||||
to_rx = msg_pattern_rainbow;
|
||||
Serial.println(F("pattern rainbow"));
|
||||
} else if (data[0] == 'o') {
|
||||
strip.pattern = 'o';
|
||||
Serial.println(F("pattern off"));
|
||||
} else {
|
||||
Serial.println(F("Invalid pattern"));
|
||||
Serial.println(F("pattern invalid"));
|
||||
}
|
||||
}
|
||||
|
||||
void do_rx_send(void){
|
||||
if (to_rx == NULL){
|
||||
return;
|
||||
}
|
||||
char buffer[20];
|
||||
strcpy_P(buffer, (char *)pgm_read_word(&(msg_pattern_rainbow)));
|
||||
Serial.println("attempt");
|
||||
Serial.print(buffer);
|
||||
Serial.println();
|
||||
to_rx = NULL;
|
||||
}
|
||||
|
||||
void setup(void) {
|
||||
strip.off();
|
||||
if (REQUIRE_SERIAL){
|
||||
while (!Serial);
|
||||
Serial.begin(115200);
|
||||
@@ -249,5 +272,6 @@ void setup(void) {
|
||||
|
||||
void loop(void) {
|
||||
ble.update(BT_SCAN_MS);
|
||||
do_rx_send();
|
||||
strip.update();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user