whatever work I had before & left on this machine
This commit is contained in:
parent
19b37ba30a
commit
c97424ade8
|
@ -4,7 +4,7 @@
|
||||||
// ----------------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------------
|
||||||
#define BUFSIZE 128 // Size of the read buffer for incoming data
|
#define BUFSIZE 128 // Size of the read buffer for incoming data
|
||||||
#define VERBOSE_MODE true // If set to 'true' enables debug output
|
#define VERBOSE_MODE true // If set to 'true' enables debug output
|
||||||
#define BLE_READPACKET_TIMEOUT 500 // Timeout in ms waiting to read a response
|
#define BLE_READPACKET_TIMEOUT 5 // Timeout in ms waiting to read a response
|
||||||
|
|
||||||
|
|
||||||
// SOFTWARE UART SETTINGS
|
// SOFTWARE UART SETTINGS
|
||||||
|
@ -12,10 +12,10 @@
|
||||||
// The following macros declare the pins that will be used for 'SW' serial.
|
// The following macros declare the pins that will be used for 'SW' serial.
|
||||||
// You should use this option if you are connecting the UART Friend to an UNO
|
// You should use this option if you are connecting the UART Friend to an UNO
|
||||||
// ----------------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------------
|
||||||
#define BLUEFRUIT_SWUART_RXD_PIN 9 // Required for software serial!
|
//#define BLUEFRUIT_SWUART_RXD_PIN 9 // Required for software serial!
|
||||||
#define BLUEFRUIT_SWUART_TXD_PIN 10 // Required for software serial!
|
//#define BLUEFRUIT_SWUART_TXD_PIN 10 // Required for software serial!
|
||||||
#define BLUEFRUIT_UART_CTS_PIN -1//11 // Required for software serial!
|
//#define BLUEFRUIT_UART_CTS_PIN -1//11 // Required for software serial!
|
||||||
#define BLUEFRUIT_UART_RTS_PIN -1 // Optional, set to -1 if unused
|
//#define BLUEFRUIT_UART_RTS_PIN -1 // Optional, set to -1 if unused
|
||||||
|
|
||||||
|
|
||||||
// HARDWARE UART SETTINGS
|
// HARDWARE UART SETTINGS
|
||||||
|
|
|
@ -1,3 +1,31 @@
|
||||||
|
#include <noise.h>
|
||||||
|
#include <bitswap.h>
|
||||||
|
#include <fastspi_types.h>
|
||||||
|
#include <pixelset.h>
|
||||||
|
#include <fastled_progmem.h>
|
||||||
|
#include <led_sysdefs.h>
|
||||||
|
#include <hsv2rgb.h>
|
||||||
|
#include <fastled_delay.h>
|
||||||
|
#include <colorpalettes.h>
|
||||||
|
#include <color.h>
|
||||||
|
#include <fastspi_ref.h>
|
||||||
|
#include <fastspi_bitbang.h>
|
||||||
|
#include <controller.h>
|
||||||
|
#include <fastled_config.h>
|
||||||
|
#include <colorutils.h>
|
||||||
|
#include <chipsets.h>
|
||||||
|
#include <pixeltypes.h>
|
||||||
|
#include <fastspi_dma.h>
|
||||||
|
#include <fastpin.h>
|
||||||
|
#include <fastspi_nop.h>
|
||||||
|
#include <platforms.h>
|
||||||
|
#include <lib8tion.h>
|
||||||
|
#include <cpp_compat.h>
|
||||||
|
#include <fastspi.h>
|
||||||
|
#include <FastLED.h>
|
||||||
|
#include <dmx.h>
|
||||||
|
#include <power_mgt.h>
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
This is an example for our nRF51822 based Bluefruit LE modules
|
This is an example for our nRF51822 based Bluefruit LE modules
|
||||||
|
|
||||||
|
@ -15,7 +43,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <Adafruit_NeoPixel.h>
|
|
||||||
#include "Adafruit_BLE.h"
|
#include "Adafruit_BLE.h"
|
||||||
#include "Adafruit_BluefruitLE_SPI.h"
|
#include "Adafruit_BluefruitLE_SPI.h"
|
||||||
#include "Adafruit_BluefruitLE_UART.h"
|
#include "Adafruit_BluefruitLE_UART.h"
|
||||||
|
@ -55,36 +82,50 @@
|
||||||
-----------------------------------------------------------------------*/
|
-----------------------------------------------------------------------*/
|
||||||
#define FACTORYRESET_ENABLE 1
|
#define FACTORYRESET_ENABLE 1
|
||||||
|
|
||||||
#define PIN 9
|
/*-----------------------------------------------------------------------*/
|
||||||
#define NUMPIXELS 10
|
#define STRING_PIN 9
|
||||||
|
#define ONBOARD_PIN 8
|
||||||
|
#define NUM_LED_STRING 9
|
||||||
|
#define NUM_LED_ONBOARD 1
|
||||||
|
#define NUM_LED NUM_LED_STRING + NUM_LED_ONBOARD
|
||||||
|
|
||||||
|
#define MIN_BRIGHTNESS 10
|
||||||
|
#define MAX_BRIGHTNESS 200
|
||||||
|
#define HUE_SPREAD 15
|
||||||
|
#define HUE_RATE_MODULO 10 //96 // increasing this value makes the hue change slower
|
||||||
|
#define BT_CHECK_CONN_MODULO 20
|
||||||
|
#define MIN_SATURATION 192
|
||||||
|
#define MAX_SATURATION 255
|
||||||
|
#define MIN_RATE 1
|
||||||
|
#define MAX_RATE 3
|
||||||
|
#define SPEED 20
|
||||||
|
|
||||||
|
CRGB leds[NUM_LED];
|
||||||
|
|
||||||
|
byte clock = 0;
|
||||||
|
byte globalHue = 0;
|
||||||
|
byte hues[NUM_LED + 1];
|
||||||
|
int brightnesses[NUM_LED + 1];
|
||||||
|
int saturations[NUM_LED + 1];
|
||||||
|
int rates[NUM_LED + 1];
|
||||||
|
bool isInDataMode = false;
|
||||||
|
bool fixedHue = false;
|
||||||
/*=========================================================================*/
|
/*=========================================================================*/
|
||||||
|
|
||||||
Adafruit_NeoPixel pixel = Adafruit_NeoPixel(NUMPIXELS, PIN);
|
// Create the bluefruit object
|
||||||
|
|
||||||
// Create the bluefruit object, either software serial...uncomment these lines
|
|
||||||
/*
|
|
||||||
SoftwareSerial bluefruitSS = SoftwareSerial(BLUEFRUIT_SWUART_TXD_PIN, BLUEFRUIT_SWUART_RXD_PIN);
|
|
||||||
|
|
||||||
Adafruit_BluefruitLE_UART ble(bluefruitSS, BLUEFRUIT_UART_MODE_PIN,
|
|
||||||
BLUEFRUIT_UART_CTS_PIN, BLUEFRUIT_UART_RTS_PIN);
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* ...or hardware serial, which does not need the RTS/CTS pins. Uncomment this line */
|
|
||||||
Adafruit_BluefruitLE_UART ble(BLUEFRUIT_HWSERIAL_NAME, BLUEFRUIT_UART_MODE_PIN);
|
Adafruit_BluefruitLE_UART ble(BLUEFRUIT_HWSERIAL_NAME, BLUEFRUIT_UART_MODE_PIN);
|
||||||
|
|
||||||
/* ...hardware SPI, using SCK/MOSI/MISO hardware SPI pins and then user selected CS/IRQ/RST */
|
|
||||||
//Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);
|
|
||||||
|
|
||||||
/* ...software SPI, using SCK/MOSI/MISO user-defined SPI pins and then user selected CS/IRQ/RST */
|
|
||||||
//Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_SCK, BLUEFRUIT_SPI_MISO,
|
|
||||||
// BLUEFRUIT_SPI_MOSI, BLUEFRUIT_SPI_CS,
|
|
||||||
// BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);
|
|
||||||
|
|
||||||
|
|
||||||
// A small helper
|
// A small helper
|
||||||
void error(const __FlashStringHelper*err) {
|
void error(const __FlashStringHelper*err) {
|
||||||
Serial.println(err);
|
Serial.println(err);
|
||||||
while (1);
|
|
||||||
|
while (1) {
|
||||||
|
// flash red led
|
||||||
|
digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level)
|
||||||
|
delay(1000); // wait 1 second
|
||||||
|
digitalWrite(7, LOW); // turn the LED off by making the voltage LOW
|
||||||
|
delay(1000); // wait 1 second
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// function prototypes over in packetparser.cpp
|
// function prototypes over in packetparser.cpp
|
||||||
|
@ -107,13 +148,15 @@ void setup(void)
|
||||||
//while (!Serial); // required for Flora & Micro
|
//while (!Serial); // required for Flora & Micro
|
||||||
delay(500);
|
delay(500);
|
||||||
|
|
||||||
// turn off neopixel
|
FastLED.addLeds<NEOPIXEL, STRING_PIN>(leds, NUM_LED_STRING);
|
||||||
pixel.begin(); // This initializes the NeoPixel library.
|
FastLED.addLeds<NEOPIXEL, ONBOARD_PIN>(leds, NUM_LED_STRING, NUM_LED_ONBOARD);
|
||||||
for(uint8_t i=0; i<NUMPIXELS; i++) {
|
for (int i=0; i<NUM_LED; i++)
|
||||||
//pixel.setPixelColor(i, pixel.Color(0,0,0)); // off
|
{
|
||||||
pixel.setPixelColor(i, pixel.Color(8,8,8)); // default
|
hues[i] = globalHue + random(0,HUE_SPREAD);
|
||||||
}
|
saturations[i] = random(MIN_SATURATION,MAX_SATURATION);
|
||||||
pixel.show();
|
rates[i] = random(MIN_RATE,MAX_RATE);
|
||||||
|
brightnesses[i] = random(MIN_BRIGHTNESS,MAX_BRIGHTNESS);
|
||||||
|
}
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println(F("Adafruit Bluefruit Neopixel Color Picker Example"));
|
Serial.println(F("Adafruit Bluefruit Neopixel Color Picker Example"));
|
||||||
|
@ -143,26 +186,11 @@ void setup(void)
|
||||||
Serial.println("Requesting Bluefruit info:");
|
Serial.println("Requesting Bluefruit info:");
|
||||||
/* Print Bluefruit information */
|
/* Print Bluefruit information */
|
||||||
ble.info();
|
ble.info();
|
||||||
|
//ble.setMode(BLUEFRUIT_MODE_DATA);
|
||||||
|
|
||||||
Serial.println(F("Please use Adafruit Bluefruit LE app to connect in Controller mode"));
|
Serial.println(F("Please use Adafruit Bluefruit LE app to connect in Controller mode"));
|
||||||
Serial.println(F("Then activate/use the sensors, color picker, game controller, etc!"));
|
Serial.println(F("Then activate/use the sensors, color picker, game controller, etc!"));
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
|
||||||
ble.verbose(false); // debug info is a little annoying after this point!
|
|
||||||
|
|
||||||
/* Wait for connection */
|
|
||||||
while (! ble.isConnected()) {
|
|
||||||
delay(500);
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.println(F("***********************"));
|
|
||||||
|
|
||||||
// Set Bluefruit to DATA mode
|
|
||||||
Serial.println( F("Switching to DATA mode!") );
|
|
||||||
ble.setMode(BLUEFRUIT_MODE_DATA);
|
|
||||||
|
|
||||||
Serial.println(F("***********************"));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
@ -172,6 +200,56 @@ void setup(void)
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
void loop(void)
|
void loop(void)
|
||||||
{
|
{
|
||||||
|
// Twinkle
|
||||||
|
for (int i=0; i<NUM_LED; i++)
|
||||||
|
{
|
||||||
|
brightnesses[i] += rates[i];
|
||||||
|
// Rate is positive but the new brightness is lower, so we overflowed.
|
||||||
|
if (brightnesses[i] >= MAX_BRIGHTNESS)
|
||||||
|
{
|
||||||
|
// Flip the sign of the rate & start decaying light.
|
||||||
|
rates[i] *= -1;
|
||||||
|
brightnesses[i] += rates[i];
|
||||||
|
}
|
||||||
|
// Rate is negative but the new brightness is bigger, so we underflowed.
|
||||||
|
else if (brightnesses[i] <= MIN_BRIGHTNESS)
|
||||||
|
{
|
||||||
|
// reset this pixel to a different color and start anew.
|
||||||
|
hues[i] = globalHue + random(0,HUE_SPREAD);
|
||||||
|
saturations[i] = random(MIN_SATURATION,MAX_SATURATION);
|
||||||
|
rates[i] = random(MIN_RATE,MAX_RATE);
|
||||||
|
brightnesses[i] = MIN_BRIGHTNESS;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
brightnesses[i] += rates[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
leds[i] = CHSV(hues[i], saturations[i], brightnesses[i]);
|
||||||
|
}
|
||||||
|
FastLED.show();
|
||||||
|
|
||||||
|
clock++;
|
||||||
|
if (clock % HUE_RATE_MODULO == 0 && !fixedHue)
|
||||||
|
{
|
||||||
|
globalHue++;
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(SPEED);
|
||||||
|
|
||||||
|
if (!isInDataMode) {
|
||||||
|
if (clock % BT_CHECK_CONN_MODULO == 0 && ble.isConnected()) { // ble.isConnected() takes time, so don't do it every loop
|
||||||
|
isInDataMode = true;
|
||||||
|
Serial.println(F("***********************"));
|
||||||
|
// Set Bluefruit to DATA mode
|
||||||
|
Serial.println( F("Switching to DATA mode!") );
|
||||||
|
ble.setMode(BLUEFRUIT_MODE_DATA);
|
||||||
|
Serial.println(F("***********************"));
|
||||||
|
ble.verbose(false); // debug info is a little annoying after this point!
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Wait for new data to arrive */
|
/* Wait for new data to arrive */
|
||||||
uint8_t len = readPacket(&ble, BLE_READPACKET_TIMEOUT);
|
uint8_t len = readPacket(&ble, BLE_READPACKET_TIMEOUT);
|
||||||
if (len == 0) return;
|
if (len == 0) return;
|
||||||
|
@ -192,10 +270,34 @@ void loop(void)
|
||||||
if (blue < 0x10) Serial.print("0");
|
if (blue < 0x10) Serial.print("0");
|
||||||
Serial.println(blue, HEX);
|
Serial.println(blue, HEX);
|
||||||
|
|
||||||
|
if (red == 0 && blue == 0 && green == 0) {
|
||||||
|
// receiving #000000 is a special control color that enables the hue cycle.
|
||||||
|
fixedHue = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
CRGB color(red, green, blue);
|
||||||
|
CHSV hsv = rgb2hsv_approximate(color);
|
||||||
|
globalHue = hsv.hue;
|
||||||
|
fixedHue = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset them all
|
||||||
|
for (int i=0; i<NUM_LED; i++) {
|
||||||
|
hues[i] = globalHue + random(0,HUE_SPREAD);
|
||||||
|
saturations[i] = random(MIN_SATURATION,MAX_SATURATION);
|
||||||
|
rates[i] = random(MIN_RATE,MAX_RATE);
|
||||||
|
brightnesses[i] = MIN_BRIGHTNESS;
|
||||||
|
|
||||||
|
if (rates[i] < 0) {
|
||||||
|
rates[i] = rates[i] * -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
for(uint8_t i=0; i<NUMPIXELS; i++) {
|
for(uint8_t i=0; i<NUMPIXELS; i++) {
|
||||||
pixel.setPixelColor(i, pixel.Color(red,green,blue));
|
pixel.setPixelColor(i, pixel.Color(red,green,blue));
|
||||||
}
|
}
|
||||||
pixel.show(); // This sends the updated pixel color to the hardware.
|
pixel.show(); // This sends the updated pixel color to the hardware.
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ int saturations[NUM_LED];
|
||||||
int rates[NUM_LED];
|
int rates[NUM_LED];
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
FastLED.addLeds<NEOPIXEL, 0>(leds, NUM_LED);
|
FastLED.addLeds<NEOPIXEL, PIN>(leds, NUM_LED);
|
||||||
for (int i=0; i<NUM_LED; i++)
|
for (int i=0; i<NUM_LED; i++)
|
||||||
{
|
{
|
||||||
hues[i] = globalHue + random(0,HUE_SPREAD);
|
hues[i] = globalHue + random(0,HUE_SPREAD);
|
||||||
|
|
Loading…
Reference in New Issue