void setup() { //--------------------------------------------------------------------------- // configure LED pin //--------------------------------------------------------------------------- pinMode(LED_BUILTIN, OUTPUT); //--------------------------------------------------------------------------- // setup blink timer control //--------------------------------------------------------------------------- BlinkTimerAdapter* blinkTimerAdapter = new BlinkTimerAdapter(); blinkTimerControl = new BlinkTimerControl(blinkTimerAdapter, BLINK_TIME_MILLIS); //----------------------------------------------------------------------------- // Serial Command Object for Debug CLI //----------------------------------------------------------------------------- Serial.begin(115200); sCmd = new SerialCommand(); // Setup callbacks for SerialCommand commands if (0 != sCmd) { sCmd->addCommand("i", incr); sCmd->addCommand("d", decr); sCmd->setDefaultHandler(unrecognized); // Handler for command that isn't matched (says "What?") } Serial.println("Hello from Neo Matrix Test!\n"); //----------------------------------------------------------------------------- // Battery Voltage Surveillance //----------------------------------------------------------------------------- batteryAdapter = new MyBatteryAdapter(); battery = new Battery(batteryAdapter); //----------------------------------------------------------------------------- // Neo Matrix //----------------------------------------------------------------------------- new Timer(new LoopTimerAdapter(), Timer::IS_RECURRING, 1000); matrix.begin(); matrix.setTextWrap(false); matrix.setBrightness(10); matrix.setTextColor(colors[0]); matrix.setTextSize(1); }
void loop() { if ( Spark.connected() == true){ //let the web know we are alive! Spark.publish("ticker-connected"); //Make sure the function is registered Spark.function("celebrate", setSalvations); Spark.function("reset", clearSalvations); //Incase the no wifi pixel is showing matrix.setPixelColor(57,0,0,0); matrix.show(); }else{ if ( WiFi.connecting() == false){ //Light UP missing wifi LED missingWifi(); } } //Read low battery pin if(digitalRead(batteryPin) == LOW){ lowBattery(); }else{ matrix.setPixelColor(56,0,0,0); matrix.show(); } //Wait 5 minutes before checking again. // delay(300000); }
void setup() { matrix.begin(); matrix.setRemapFunction(remapXY); matrix.setTextWrap(false); // Allow scrolling off left matrix.setTextColor(0xF800); // Red by default matrix.setBrightness(31); // Batteries have limited sauce BTLEserial.begin(); pinMode(LED, OUTPUT); digitalWrite(LED, LOW); }
void setup() { //Initalize the reader FlashDevice* device = Devices::createWearLevelErase(); FlashReader reader(device); Serial.begin(9600); Serial.println("Starting setup...."); //Wifi will be disabled at this point matrix.begin(); matrix.setTextWrap(false); matrix.setBrightness(100); matrix.setTextColor(matrix.Color(80,255,0)); matrix.fillScreen(0); //We're not connected to WIFI just yet but we need a number to show int salvations = reader.readInt(); //Show salvations unless something isn't stored in memory. if(salvations >= 0){ showSalvations(salvations, 0); }else{ matrix.print(F("******")); matrix.show(); } pinMode(batteryPin, INPUT_PULLUP); //Now that everything is done and being shown, lets quietly connect to wifi. if ( Spark.connected() == false){ Spark.connect(); } }
void showSalvations(int salvations, int oldSalvations){ //Initalize Digits int digits = 1; //Loop through a counter until it reaches salvations. This loop happens very fast. for(int c = oldSalvations; c <= salvations; c = c + (rand() % 30 + 200)){ //Fill Screen with black matrix.fillScreen(0); //Count digits digits = countDigits(c); //Place cursor matrix.setCursor(41-(digits*6),0); //set the data within the matrix matrix.print(F(c)); //Show matrix.show(); //delay the next interation for 35ms delay(35); } //The following happens at the very end but because the ticker is moving so fast you wouldn't see it happen. //This is just to ensure the final number displayed is the correct total. matrix.fillScreen(0); digits = countDigits(salvations); matrix.setCursor(41-(digits*6),0); matrix.print(F(salvations)); matrix.show(); return; }
void loop() { unsigned long t = millis(); // Current elapsed time, milliseconds. // millis() comparisons are used rather than delay() so that animation // speed is consistent regardless of message length & other factors. BTLEserial.pollACI(); // Handle BTLE operations aci_evt_opcode_t state = BTLEserial.getState(); if(state != prevState) { // BTLE state change? switch(state) { // Change LED flashing to show state case ACI_EVT_DEVICE_STARTED: LEDperiod = 1000L / 10; break; case ACI_EVT_CONNECTED: LEDperiod = 1000L / 2; break; case ACI_EVT_DISCONNECTED: LEDperiod = 0L; break; } prevState = state; prevLEDtime = t; LEDstate = LOW; // Any state change resets LED digitalWrite(LED, LEDstate); } if(LEDperiod && ((t - prevLEDtime) >= LEDperiod)) { // Handle LED flash prevLEDtime = t; LEDstate = !LEDstate; digitalWrite(LED, LEDstate); } // If connected, check for input from BTLE... if((state == ACI_EVT_CONNECTED) && BTLEserial.available()) { if(BTLEserial.peek() == '#') { // Color commands start with '#' char color[7]; switch(readStr(color, sizeof(color))) { case 4: // #RGB 4/4/4 RGB matrix.setTextColor(matrix.Color( unhex(color[1]) * 17, // Expand to 8/8/8 unhex(color[2]) * 17, unhex(color[3]) * 17)); break; case 5: // #XXXX 5/6/5 RGB matrix.setTextColor( (unhex(color[1]) << 12) + (unhex(color[2]) << 8) + (unhex(color[3]) << 4) + unhex(color[4])); break; case 7: // #RRGGBB 8/8/8 RGB matrix.setTextColor(matrix.Color( (unhex(color[1]) << 4) + unhex(color[2]), (unhex(color[3]) << 4) + unhex(color[4]), (unhex(color[5]) << 4) + unhex(color[6]))); break; } } else { // Not color, must be message string msgLen = readStr(msg, sizeof(msg)-1); msg[msgLen] = 0; msgX = matrix.width(); // Reset scrolling } } if((t - prevFrameTime) >= (1000L / FPS)) { // Handle scrolling matrix.fillScreen(0); matrix.setCursor(msgX, 0); matrix.print(msg); if(--msgX < (msgLen * -6)) msgX = matrix.width(); // We must repeat! matrix.show(); prevFrameTime = t; } }
// NEOPIXEL STUFF ---------------------------------------------------------- // 4 meters of NeoPixel strip is coiled around a top hat; the result is // not a perfect grid. My large-ish 61cm circumference hat accommodates // 37 pixels around...a 240 pixel reel isn't quite enough for 7 rows all // around, so there's 7 rows at the front, 6 at the back; a smaller hat // will fare better. #define NEO_PIN 6 // Arduino pin to NeoPixel data input #define NEO_WIDTH 37 // Hat circumference in pixels #define NEO_HEIGHT 7 // Number of pixel rows (round up if not equal) #define NEO_OFFSET (((NEO_WIDTH * NEO_HEIGHT) - 240) / 2) // Pixel strip must be coiled counterclockwise, top to bottom, due to // custom remap function (not a regular grid). Adafruit_NeoMatrix matrix(NEO_WIDTH, NEO_HEIGHT, NEO_PIN, NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE, NEO_GRB + NEO_KHZ800); char msg[21] = {0}; // BLE 20 char limit + NUL uint8_t msgLen = 0; // Empty message int msgX = matrix.width(); // Start off right edge unsigned long prevFrameTime = 0L; // For animation timing #define FPS 20 // Scrolling speed // BLUEFRUIT LE STUFF------------------------------------------------------- // CLK, MISO, MOSI connect to hardware SPI. Other pins are configrable: #define ADAFRUITBLE_REQ 10 #define ADAFRUITBLE_RST 9 #define ADAFRUITBLE_RDY 2 // Must be an interrupt pin
//Show BLUE LED if low battery. void lowBattery(){ matrix.setPixelColor(56,100,0,0); matrix.show(); }
//Show YELLOW LED if no WIFI. void missingWifi(){ matrix.setPixelColor(57,0,0,255); matrix.show(); }
void timeExpired() { matrix.fillScreen(0); matrix.fillCircle(6, 6, 6, matrix.Color(190, 190, 190)); matrix.setTextColor(colors[0]); matrix.setCursor(0, 1); matrix.print(F("158")); if (counter % 2 == 0) { matrix.fillScreen(0); matrix.fillCircle(6, 5, 5, matrix.Color(20, 20, 20)); matrix.setTextColor(colors[2]); matrix.setCursor(0, 1); matrix.print(String(counter)); } matrix.show(); counter++; }
// NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns proceed // in the same order, or alternate lines reverse direction; pick one. // See example below for these values in action. // Parameter 5 = pixel type flags, add together as needed: // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) // Example for NeoPixel Shield. In this application we'd like to use it // as a 5x8 tall matrix, with the USB port positioned at the top of the // Arduino. When held that way, the first pixel is at the top right, and // lines are arranged in columns, progressive order. The shield uses // 800 KHz (v2) pixels that expect GRB color data. Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(16, 16, PIN, NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG, NEO_GRB + NEO_KHZ800); const uint16_t colors[] = { matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) }; int x = matrix.width(); int pass = 0; int counter = 1; class LoopTimerAdapter : public TimerAdapter { public: void timeExpired() { matrix.fillScreen(0);